Changeset 74149 in vbox for trunk/include/iprt
- Timestamp:
- Sep 7, 2018 6:51:37 PM (6 years ago)
- Location:
- trunk/include/iprt
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/cpp/restbase.h
r74142 r74149 31 31 #include <iprt/json.h> 32 32 #include <iprt/stdarg.h> 33 #include <iprt/time.h> 33 34 #include <iprt/cpp/ministring.h> 34 35 … … 362 363 kTypeClass_Invalid = 0, 363 364 kTypeClass_Bool, /**< Primitive: bool. */ 364 kTypeClass_Int64, /**< Primitive: bool. */ 365 kTypeClass_Int32, /**< Primitive: bool. */ 366 kTypeClass_Int16, /**< Primitive: bool. */ 367 kTypeClass_Double, /**< Primitive: bool. */ 368 kTypeClass_String, /**< Primitive: bool. */ 365 kTypeClass_Int64, /**< Primitive: int64_t. */ 366 kTypeClass_Int32, /**< Primitive: int32_t. */ 367 kTypeClass_Int16, /**< Primitive: int16_t. */ 368 kTypeClass_Double, /**< Primitive: double. */ 369 kTypeClass_String, /**< Primitive: string. */ 370 kTypeClass_Date, /**< Date. */ 371 kTypeClass_Uuid, /**< UUID. */ 372 kTypeClass_Binary, /**< Binary blob. */ 369 373 kTypeClass_Object, /**< Object (any kind of data model object). */ 370 374 kTypeClass_Array, /**< Array (containing any kind of object). */ 371 375 kTypeClass_StringMap, /**< String map (containing any kind of object). */ 372 kTypeClass_StringEnum, /**< String enum. */ 373 kTypeClass_BinaryString /**< Binary string. */ 376 kTypeClass_StringEnum /**< String enum. */ 374 377 } kTypeClass; 375 378 … … 642 645 static DECLCALLBACK(RTCRestObjectBase *) createInstance(void); 643 646 }; 647 648 649 /** 650 * Date class. 651 * 652 * There are numerous ways of formatting a timestamp and the specifications 653 * we're currently working with doesn't have a way of telling it seems. 654 * Thus, decoding need to have fail safes built in so the user can give hints. 655 * The formatting likewise needs to be told which format to use by the user. 656 * 657 * Two side-effects of the format stuff is that the default constructor creates 658 * an object that is null, and resetToDefault will do the same bug leave the 659 * format as a hint. 660 */ 661 class RT_DECL_CLASS RTCRestDate : public RTCRestObjectBase 662 { 663 public: 664 /** Default constructor. 665 * @note The result is a null-object. */ 666 RTCRestDate(); 667 /** Copy constructor. */ 668 RTCRestDate(RTCRestDate const &a_rThat); 669 /** Destructor. */ 670 virtual ~RTCRestDate(); 671 /** Copy assignment operator. */ 672 RTCRestDate &operator=(RTCRestDate const &a_rThat); 673 /** Safe copy assignment method. */ 674 int assignCopy(RTCRestDate const &a_rThat); 675 676 /* Overridden methods: */ 677 virtual int resetToDefault() RT_OVERRIDE; 678 virtual RTCRestOutputBase &serializeAsJson(RTCRestOutputBase &a_rDst) const RT_OVERRIDE; 679 virtual int deserializeFromJson(RTCRestJsonCursor const &a_rCursor) RT_OVERRIDE; 680 virtual int toString(RTCString *a_pDst, uint32_t a_fFlags = 0) const RT_OVERRIDE; 681 virtual int fromString(RTCString const &a_rValue, const char *a_pszName, PRTERRINFO a_pErrInfo = NULL, 682 uint32_t a_fFlags = kCollectionFormat_Unspecified) RT_OVERRIDE; 683 virtual kTypeClass typeClass(void) const RT_OVERRIDE; 684 virtual const char *typeName(void) const RT_OVERRIDE; 685 686 /** Factory method. */ 687 static DECLCALLBACK(RTCRestObjectBase *) createInstance(void); 688 689 /** Date formats. */ 690 typedef enum 691 { 692 kFormat_Invalid = 0, 693 kFormat_Rfc2822, /**< Format it according to RFC-2822. */ 694 kFormat_Rfc7131, /**< Format it according to RFC-7131 (HTTP). */ 695 kFormat_Rfc3339, /**< Format it according to RFC-3339 (ISO-8601) (no fraction). */ 696 kFormat_Rfc3339_Fraction_2, /**< Format it according to RFC-3339 (ISO-8601) with two digit fraction (hundreths). */ 697 kFormat_Rfc3339_Fraction_3, /**< Format it according to RFC-3339 (ISO-8601) with three digit fraction (milliseconds). */ 698 kFormat_Rfc3339_Fraction_6, /**< Format it according to RFC-3339 (ISO-8601) with six digit fraction (microseconds). */ 699 kFormat_Rfc3339_Fraction_9, /**< Format it according to RFC-3339 (ISO-8601) with nine digit fraction (nanoseconds). */ 700 kFormat_End 701 } kFormat; 702 703 /** 704 * Assigns the value, formats it as a string and clears the null indicator. 705 * 706 * @returns VINF_SUCCESS, VERR_NO_STR_MEMORY or VERR_INVALID_PARAMETER. 707 * @param a_pTimeSpec The time spec to set. 708 * @param a_enmFormat The date format to use when formatting it. 709 */ 710 int assignValue(PCRTTIMESPEC a_pTimeSpec, kFormat a_enmFormat); 711 int assignValueRfc2822(PCRTTIMESPEC a_pTimeSpec); /**< Convenience method. */ 712 int assignValueRfc7131(PCRTTIMESPEC a_pTimeSpec); /**< Convenience method. */ 713 int assignValueRfc3339(PCRTTIMESPEC a_pTimeSpec); /**< Convenience method. */ 714 715 /** 716 * Assigns the current UTC time and clears the null indicator . 717 * 718 * @returns VINF_SUCCESS, VERR_NO_STR_MEMORY or VERR_INVALID_PARAMETER. 719 * @returns VINF_SUCCESS or VERR_NO_STR_MEMORY. 720 * @param a_enmFormat The date format to use when formatting it. 721 */ 722 int assignNow(kFormat a_enmFormat); 723 int assignNowRfc2822(); /**< Convenience method. */ 724 int assignNowRfc7131(); /**< Convenience method. */ 725 int assignNowRfc3339(); /**< Convenience method. */ 726 727 /** 728 * Sets the format to help deal with decoding issues. 729 * 730 * This can also be used to change the date format for an okay timespec. 731 * @returns IPRT status code. 732 * @param a_enmFormat The date format to try/set. 733 */ 734 int setFormat(kFormat a_enmFormat); 735 736 /** Check if the value is okay (m_TimeSpec & m_Exploded). */ 737 bool isOkay() const { return m_fTimeSpecOkay; } 738 /** Get the timespec value. */ 739 RTTIMESPEC const &getTimeSpec() const { return m_TimeSpec; } 740 /** Get the exploded time. */ 741 RTTIME const &getExploded() const { return m_Exploded; } 742 /** Get the formatted/raw string value. */ 743 RTCString const &getString() const { return m_strFormatted; } 744 745 protected: 746 /** The value. */ 747 RTTIMESPEC m_TimeSpec; 748 /** The exploded time value. */ 749 RTTIME m_Exploded; 750 /** Set if m_TimeSpec is okay, consult m_strFormatted if not. */ 751 bool m_fTimeSpecOkay; 752 /** The format / format hint. */ 753 kFormat m_enmFormat; 754 /** The formatted date string. 755 * This will be the raw input string for a deserialized value, where as for 756 * a value set by the user it will be the formatted value. */ 757 RTCString m_strFormatted; 758 759 /** 760 * Explodes and formats the m_TimeSpec value. 761 * 762 * Sets m_Exploded, m_strFormatted, m_fTimeSpecOkay, and m_enmFormat, clears m_fNullIndicator. 763 * 764 * @returns VINF_SUCCESS or VERR_NO_STR_MEMORY. 765 * @param a_enmFormat The format to use. 766 */ 767 int explodeAndFormat(kFormat a_enmFormat); 768 769 /** 770 * Formats the m_Exploded value. 771 * 772 * Sets m_strFormatted, m_fTimeSpecOkay, and m_enmFormat, clears m_fNullIndicator. 773 * 774 * @returns VINF_SUCCESS or VERR_NO_STR_MEMORY. 775 * @param a_enmFormat The format to use. 776 */ 777 int format(kFormat a_enmFormat); 778 779 /** 780 * Internal worker that attempts to decode m_strFormatted. 781 * 782 * Sets m_fTimeSpecOkay. 783 * 784 * @returns IPRT status code. 785 * @param enmFormat Specific format to try, kFormat_Invalid (default) to try guess it. 786 */ 787 int decodeFormattedString(kFormat enmFormat = kFormat_Invalid); 788 }; 789 790 791 /** We should provide a proper UUID class eventually. Currently it is not used. */ 792 typedef RTCRestString RTCRestUuid; 644 793 645 794 -
trunk/include/iprt/err.h
r74093 r74149 3218 3218 /** Server response contains unexpected repetitive header field. */ 3219 3219 #define VERR_REST_RESPONSE_REPEAT_HEADER_FIELD (-25703) 3220 /** Unable to decode date value. */ 3221 #define VWRN_REST_UNABLE_TO_DECODE_DATE (25704) 3222 /** Unable to decode date value. */ 3223 #define VERR_REST_UNABLE_TO_DECODE_DATE (-25704) 3220 3224 3221 3225 /** Internal error \#1. */
Note:
See TracChangeset
for help on using the changeset viewer.