Changeset 74023 in vbox for trunk/include/iprt
- Timestamp:
- Sep 2, 2018 1:43:59 PM (6 years ago)
- Location:
- trunk/include/iprt
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/cpp/restbase.h
r74020 r74023 33 33 #include <iprt/json.h> 34 34 #include <iprt/list.h> 35 #include <iprt/string.h> 35 36 #include <iprt/stdarg.h> 36 37 #include <iprt/cpp/ministring.h> … … 314 315 * @note When adding collection format types, make sure to also 315 316 * update RTCRestArrayBase::toString(). 317 * @note Bit 24 is reserved (for kHdrField_MapCollection). 316 318 */ 317 319 enum … … 360 362 uint32_t a_fFlags = kCollectionFormat_Unspecified); 361 363 364 /** Type classification */ 365 typedef enum kTypeClass 366 { 367 kTypeClass_Invalid = 0, 368 kTypeClass_Bool, /**< Primitive: bool. */ 369 kTypeClass_Int64, /**< Primitive: bool. */ 370 kTypeClass_Int32, /**< Primitive: bool. */ 371 kTypeClass_Int16, /**< Primitive: bool. */ 372 kTypeClass_Double, /**< Primitive: bool. */ 373 kTypeClass_String, /**< Primitive: bool. */ 374 kTypeClass_Object, /**< Object (any kind of data model object). */ 375 kTypeClass_Array, /**< Array (containing any kind of object). */ 376 kTypeClass_StringMap /**< String map (containing any kind of object). */ 377 } kTypeClass; 378 379 /** 380 * Returns the object type class. 381 */ 382 virtual kTypeClass typeClass(void) const; 383 362 384 /** 363 385 * Returns the object type name. 364 386 */ 365 virtual const char * getType(void)= 0;387 virtual const char *typeName(void) const = 0; 366 388 367 389 /** … … 414 436 virtual int fromString(RTCString const &a_rValue, const char *a_pszName, PRTERRINFO a_pErrInfo = NULL, 415 437 uint32_t a_fFlags = kCollectionFormat_Unspecified) RT_OVERRIDE; 416 virtual const char *getType(void) RT_OVERRIDE; 438 virtual kTypeClass typeClass(void) const RT_OVERRIDE; 439 virtual const char *typeName(void) const RT_OVERRIDE; 417 440 418 441 /** Factory method. */ … … 453 476 virtual int fromString(RTCString const &a_rValue, const char *a_pszName, PRTERRINFO a_pErrInfo = NULL, 454 477 uint32_t a_fFlags = kCollectionFormat_Unspecified) RT_OVERRIDE; 455 virtual const char *getType(void) RT_OVERRIDE; 478 virtual kTypeClass typeClass(void) const RT_OVERRIDE; 479 virtual const char *typeName(void) const RT_OVERRIDE; 456 480 457 481 /** Factory method. */ … … 492 516 virtual int fromString(RTCString const &a_rValue, const char *a_pszName, PRTERRINFO a_pErrInfo = NULL, 493 517 uint32_t a_fFlags = kCollectionFormat_Unspecified) RT_OVERRIDE; 494 virtual const char *getType(void) RT_OVERRIDE; 518 virtual kTypeClass typeClass(void) const RT_OVERRIDE; 519 virtual const char *typeName(void) const RT_OVERRIDE; 495 520 496 521 /** Factory method. */ … … 531 556 virtual int fromString(RTCString const &a_rValue, const char *a_pszName, PRTERRINFO a_pErrInfo = NULL, 532 557 uint32_t a_fFlags = kCollectionFormat_Unspecified) RT_OVERRIDE; 533 virtual const char *getType(void) RT_OVERRIDE; 558 virtual kTypeClass typeClass(void) const RT_OVERRIDE; 559 virtual const char *typeName(void) const RT_OVERRIDE; 534 560 535 561 /** Factory method. */ … … 570 596 virtual int fromString(RTCString const &a_rValue, const char *a_pszName, PRTERRINFO a_pErrInfo = NULL, 571 597 uint32_t a_fFlags = kCollectionFormat_Unspecified) RT_OVERRIDE; 572 virtual const char *getType(void) RT_OVERRIDE; 598 virtual kTypeClass typeClass(void) const RT_OVERRIDE; 599 virtual const char *typeName(void) const RT_OVERRIDE; 573 600 574 601 /** Factory method. */ … … 613 640 virtual int fromString(RTCString const &a_rValue, const char *a_pszName, PRTERRINFO a_pErrInfo = NULL, 614 641 uint32_t a_fFlags = kCollectionFormat_Unspecified) RT_OVERRIDE; 615 virtual const char *getType(void) RT_OVERRIDE; 642 virtual kTypeClass typeClass(void) const RT_OVERRIDE; 643 virtual const char *typeName(void) const RT_OVERRIDE; 616 644 617 645 /** Factory method. */ … … 638 666 virtual int fromString(RTCString const &a_rValue, const char *a_pszName, PRTERRINFO a_pErrInfo = NULL, 639 667 uint32_t a_fFlags = kCollectionFormat_Unspecified) RT_OVERRIDE; 668 virtual kTypeClass typeClass(void) const RT_OVERRIDE; 669 virtual const char *typeName(void) const RT_OVERRIDE; 640 670 641 671 /** … … 660 690 { 661 691 return m_cElements; 692 } 693 694 /** 695 * Returns the base object pointer at a given index. 696 * 697 * @returns The base object at @a a_idx, NULL if out of range. 698 * @param a_idx The array index. 699 */ 700 RTCRestObjectBase *atBase(size_t a_idx) 701 { 702 if (a_idx < m_cElements) 703 return m_papElements[a_idx]; 704 return NULL; 705 } 706 707 /** 708 * Returns the const base object pointer at a given index. 709 * 710 * @returns The base object at @a a_idx, NULL if out of range. 711 * @param a_idx The array index. 712 */ 713 RTCRestObjectBase const *atBase(size_t a_idx) const 714 { 715 if (a_idx < m_cElements) 716 return m_papElements[a_idx]; 717 return NULL; 662 718 } 663 719 … … 669 725 */ 670 726 bool removeAt(size_t a_idx); 671 672 727 673 728 /** … … 782 837 { 783 838 return copyArrayWorker(a_rThat, false /*fThrow*/); 784 }785 786 virtual const char *getType(void) RT_OVERRIDE787 {788 return "RTCRestArray<ElementType>";789 839 } 790 840 … … 1009 1059 //virtual int fromString(RTCString const &a_rValue, const char *a_pszName, PRTERRINFO a_pErrInfo = NULL, 1010 1060 // uint32_t a_fFlags = kCollectionFormat_Unspecified) RT_OVERRIDE; 1061 virtual kTypeClass typeClass(void) const RT_OVERRIDE; 1062 virtual const char *typeName(void) const RT_OVERRIDE; 1011 1063 1012 1064 /** … … 1048 1100 bool remove(RTCString const &a_rStrKey); 1049 1101 1102 /** 1103 * Creates a new value and inserts it under the given key, returning the new value. 1104 * 1105 * @returns VINF_SUCCESS or VWRN_ALREADY_EXISTS on success. 1106 * VERR_ALREADY_EXISTS, VERR_NO_MEMORY or VERR_NO_STR_MEMORY on failure. 1107 * @param a_ppValue Where to return the pointer to the value. 1108 * @param a_pszKey The key to put it under. 1109 * @param a_cchKey The length of the key. Default is the entire string. 1110 * @param a_fReplace Whether to replace or fail on key collision. 1111 */ 1112 int putNewValue(RTCRestObjectBase **a_ppValue, const char *a_pszKey, size_t a_cchKey = RTSTR_MAX, bool a_fReplace = false); 1113 1114 /** 1115 * Creates a new value and inserts it under the given key, returning the new value. 1116 * 1117 * @returns VINF_SUCCESS or VWRN_ALREADY_EXISTS on success. 1118 * VERR_ALREADY_EXISTS, VERR_NO_MEMORY or VERR_NO_STR_MEMORY on failure. 1119 * @param a_ppValue Where to return the pointer to the value. 1120 * @param a_pszKey The key to put it under. 1121 * @param a_fReplace Whether to replace or fail on key collision. 1122 */ 1123 int putNewValue(RTCRestObjectBase **a_ppValue, RTCString const &a_rStrKey, bool a_fReplace = false); 1050 1124 1051 1125 protected: … … 1070 1144 size_t m_cEntries; 1071 1145 1146 public: 1147 /** @name Map Iteration 1148 * @{ */ 1149 /** Const iterator. */ 1150 class ConstIterator 1151 { 1152 private: 1153 MapEntry *m_pCur; 1154 ConstIterator(); 1155 protected: 1156 ConstIterator(MapEntry *a_pEntry) : m_pCur(a_pEntry) { } 1157 public: 1158 ConstIterator(ConstIterator const &a_rThat) : m_pCur(a_rThat.m_pCur) { } 1159 1160 /** Gets the key string. */ 1161 RTCString const &getKey() { return m_pCur->strKey; } 1162 /** Gets poitner to the value object. */ 1163 RTCRestObjectBase const *getValue() { return m_pCur->pValue; } 1164 1165 /** Advance to the next map entry. */ 1166 ConstIterator &operator++() 1167 { 1168 m_pCur = RTListNodeGetNextCpp(&m_pCur->ListEntry, MapEntry, ListEntry); 1169 return *this; 1170 } 1171 1172 /** Advance to the previous map entry. */ 1173 ConstIterator &operator--() 1174 { 1175 m_pCur = RTListNodeGetPrevCpp(&m_pCur->ListEntry, MapEntry, ListEntry); 1176 return *this; 1177 } 1178 1179 /** Compare equal. */ 1180 bool operator==(ConstIterator const &a_rThat) { return m_pCur == a_rThat.m_pCur; } 1181 /** Compare not equal. */ 1182 bool operator!=(ConstIterator const &a_rThat) { return m_pCur != a_rThat.m_pCur; } 1183 1184 /* Map class must be friend so it can use the MapEntry constructor. */ 1185 friend RTCRestStringMapBase; 1186 }; 1187 1188 /** Returns iterator for the first map entry (unless it's empty and it's also the end). */ 1189 ConstIterator begin() const { return ConstIterator(RTListGetFirstCpp(&m_ListHead, MapEntry, ListEntry)); } 1190 /** Returns iterator for the last map entry (unless it's empty and it's also the end). */ 1191 ConstIterator last() const { return ConstIterator(RTListGetLastCpp(&m_ListHead, MapEntry, ListEntry)); } 1192 /** Returns the end iterator. This does not ever refer to an actual map entry. */ 1193 ConstIterator end() const { return ConstIterator(RT_FROM_CPP_MEMBER(&m_ListHead, MapEntry, ListEntry)); } 1194 /** @} */ 1195 1196 1072 1197 protected: 1073 1198 /** … … 1106 1231 * @param a_pValue The value to insert. Ownership is transferred to the map on success. 1107 1232 * @param a_fReplace Whether to replace existing key-value pair with matching key. 1108 */ 1109 int putWorker(const char *a_pszKey, RTCRestObjectBase *a_pValue, bool a_fReplace); 1233 * @param a_cchKey The key length, the whole string by default. 1234 */ 1235 int putWorker(const char *a_pszKey, RTCRestObjectBase *a_pValue, bool a_fReplace, size_t a_cchKey = RTSTR_MAX); 1110 1236 1111 1237 /** … … 1117 1243 * @param a_rValue The value to copy into the map. 1118 1244 * @param a_fReplace Whether to replace existing key-value pair with matching key. 1119 */ 1120 int putCopyWorker(const char *a_pszKey, RTCRestObjectBase const &a_rValue, bool a_fReplace); 1245 * @param a_cchKey The key length, the whole string by default. 1246 */ 1247 int putCopyWorker(const char *a_pszKey, RTCRestObjectBase const &a_rValue, bool a_fReplace, size_t a_cchKey = RTSTR_MAX); 1121 1248 1122 1249 /** … … 1176 1303 { 1177 1304 return copyMapWorker(a_rThat, false /*a_fThrow*/); 1178 }1179 1180 virtual const char *getType(void) RT_OVERRIDE1181 {1182 return "RTCRestStringMap<ValueType>";1183 1305 } 1184 1306 … … 1220 1342 int put(RTCString const &a_rStrKey, ValueType *a_pValue, bool a_fReplace = false) 1221 1343 { 1222 return putWorker(a_rStrKey.c_str(), a_pValue, a_fReplace );1344 return putWorker(a_rStrKey.c_str(), a_pValue, a_fReplace, a_rStrKey.length()); 1223 1345 } 1224 1346 … … 1248 1370 int putCopy(RTCString const &a_rStrKey, const ValueType &a_rValue, bool a_fReplace = false) 1249 1371 { 1250 return putCopyWorker(a_rStrKey.c_str(), a_rValue, a_fReplace );1372 return putCopyWorker(a_rStrKey.c_str(), a_rValue, a_fReplace, a_rStrKey.length()); 1251 1373 } 1252 1374 … … 1347 1469 virtual int fromString(RTCString const &a_rValue, const char *a_pszName, PRTERRINFO a_pErrInfo = NULL, 1348 1470 uint32_t a_fFlags = kCollectionFormat_Unspecified) RT_OVERRIDE; 1349 virtual const char *getType(void) RT_OVERRIDE; 1471 virtual kTypeClass typeClass(void) const RT_OVERRIDE; 1472 virtual const char *typeName(void) const RT_OVERRIDE; 1350 1473 1351 1474 /** Factory method. */ … … 1452 1575 typedef struct 1453 1576 { 1454 const char *pszName;/**< The parameter name. */1455 uint32_t fFlags;/**< The toString flags. */1456 bool fRequired;/**< Required or not. */1457 uint8_t iBitNo;/**< The parameter bit number. */1577 const char *pszName; /**< The parameter name. */ 1578 uint32_t fFlags; /**< The toString flags. */ 1579 bool fRequired; /**< Required or not. */ 1580 uint8_t iBitNo; /**< The parameter bit number. */ 1458 1581 } QUERYPARAMDESC; 1459 1582 … … 1473 1596 typedef struct 1474 1597 { 1475 const char *pszName; /**< The parameter name. */ 1476 uint32_t fFlags; /**< The toString flags. */ 1477 bool fRequired; /**< Required or not. */ 1478 uint8_t iBitNo; /**< The parameter bit number. */ 1598 const char *pszName; /**< The parameter name. */ 1599 uint32_t fFlags; /**< The toString flags. */ 1600 bool fRequired; /**< Required or not. */ 1601 uint8_t iBitNo; /**< The parameter bit number. */ 1602 bool fMapCollection; /**< Collect headers starting with pszName into a map. */ 1479 1603 } HEADERPARAMDESC; 1480 1604 … … 1619 1743 /** Collection map, name is a prefix followed by '*'. */ 1620 1744 kHdrField_MapCollection = RT_BIT_32(24), 1621 /** Array collection, i.e. the heade field may appear more than once. */1622 kHdrField_ArrayCollection = RT_BIT_32(25)1623 1745 }; 1624 1746 -
trunk/include/iprt/err.h
r73978 r74023 3218 3218 /** Server response contains unexpected repetitive header field. */ 3219 3219 #define VERR_REST_RESPONSE_REPEAT_HEADER_FIELD (-25703) 3220 3221 /** Internal error \#1. */ 3222 #define VERR_REST_INTERAL_ERROR_1 (-25791) 3223 /** Internal error \#2. */ 3224 #define VERR_REST_INTERAL_ERROR_2 (-25792) 3225 /** Internal error \#3. */ 3226 #define VERR_REST_INTERAL_ERROR_3 (-25793) 3227 /** Internal error \#4. */ 3228 #define VERR_REST_INTERAL_ERROR_4 (-25794) 3229 /** Internal error \#5. */ 3230 #define VERR_REST_INTERAL_ERROR_5 (-25795) 3231 /** Internal error \#6. */ 3232 #define VERR_REST_INTERAL_ERROR_6 (-25796) 3233 /** Internal error \#7. */ 3234 #define VERR_REST_INTERAL_ERROR_7 (-25797) 3235 /** Internal error \#8. */ 3236 #define VERR_REST_INTERAL_ERROR_8 (-25798) 3237 /** Internal error \#9. */ 3238 #define VERR_REST_INTERAL_ERROR_9 (-25799) 3220 3239 /** @} */ 3221 3240
Note:
See TracChangeset
for help on using the changeset viewer.