Changeset 74402 in vbox
- Timestamp:
- Sep 21, 2018 9:25:55 AM (6 years ago)
- Location:
- trunk
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/cpp/restanyobject.h
r74387 r74402 113 113 /** Factory method. */ 114 114 static DECLCALLBACK(RTCRestObjectBase *) createInstance(void); 115 /** Deserialization w/ instantiation. */ 116 static FNDESERIALIZEINSTANCEFROMJSON deserializeInstanceFromJson; 115 117 116 118 protected: -
trunk/include/iprt/cpp/restarray.h
r74387 r74402 147 147 148 148 /** 149 * For accessing the static deserializeInstanceFromJson() method of the value. 150 */ 151 virtual int deserializeValueInstanceFromJson(RTCRestJsonCursor const &a_rCursor, RTCRestObjectBase **a_ppInstance) = 0; 152 153 /** 149 154 * Worker for the copy constructor and the assignment operator. 150 155 * … … 244 249 } 245 250 251 /** @copydoc RTCRestObjectBase::FNDESERIALIZEINSTANCEFROMJSON */ 252 static DECLCALLBACK(int) deserializeInstanceFromJson(RTCRestJsonCursor const &a_rCursor, RTCRestObjectBase **a_ppInstance) 253 { 254 *a_ppInstance = new (std::nothrow) RTCRestArray<ElementType>(); 255 if (*a_ppInstance) 256 return (*a_ppInstance)->deserializeFromJson(a_rCursor); 257 return a_rCursor.m_pPrimary->addError(a_rCursor, VERR_NO_MEMORY, "Out of memory"); 258 } 259 246 260 247 261 /** … … 418 432 return new (std::nothrow) ElementType(); 419 433 } 434 435 virtual int deserializeValueInstanceFromJson(RTCRestJsonCursor const &a_rCursor, RTCRestObjectBase **a_ppInstance) RT_OVERRIDE 436 { 437 return ElementType::deserializeInstanceFromJson(a_rCursor, a_ppInstance); 438 } 420 439 }; 421 440 -
trunk/include/iprt/cpp/restbase.h
r74390 r74402 312 312 313 313 /** 314 * Polymorphic JSON deserialization helper that instantiate the matching class using 315 * the discriminator field. 316 * 317 * @returns IPRT status code. 318 * @param a_rCursor The JSON cursor. 319 * @param a_ppInstance Where to return the deserialized instance. 320 * May return an object on failure. 321 */ 322 typedef DECLCALLBACK(int) FNDESERIALIZEINSTANCEFROMJSON(RTCRestJsonCursor const &a_rCursor, RTCRestObjectBase **a_ppInstance); 323 /** Pointer to a FNDESERIALIZEINSTANCEFROMJSON function. */ 324 typedef FNDESERIALIZEINSTANCEFROMJSON *PFNDESERIALIZEINSTANCEFROMJSON; 325 326 /** 314 327 * Flags for toString(). 315 328 * … … 444 457 /** Factory method. */ 445 458 static DECLCALLBACK(RTCRestObjectBase *) createInstance(void); 459 /** Deserialization w/ instantiation. */ 460 static FNDESERIALIZEINSTANCEFROMJSON deserializeInstanceFromJson; 446 461 447 462 public: … … 487 502 /** Factory method. */ 488 503 static DECLCALLBACK(RTCRestObjectBase *) createInstance(void); 504 /** Deserialization w/ instantiation. */ 505 static FNDESERIALIZEINSTANCEFROMJSON deserializeInstanceFromJson; 489 506 490 507 public: … … 530 547 /** Factory method. */ 531 548 static DECLCALLBACK(RTCRestObjectBase *) createInstance(void); 549 /** Deserialization w/ instantiation. */ 550 static FNDESERIALIZEINSTANCEFROMJSON deserializeInstanceFromJson; 532 551 533 552 public: … … 573 592 /** Factory method. */ 574 593 static DECLCALLBACK(RTCRestObjectBase *) createInstance(void); 594 /** Deserialization w/ instantiation. */ 595 static FNDESERIALIZEINSTANCEFROMJSON deserializeInstanceFromJson; 575 596 576 597 public: … … 616 637 /** Factory method. */ 617 638 static DECLCALLBACK(RTCRestObjectBase *) createInstance(void); 639 /** Deserialization w/ instantiation. */ 640 static FNDESERIALIZEINSTANCEFROMJSON deserializeInstanceFromJson; 618 641 619 642 public: … … 663 686 /** Factory method. */ 664 687 static DECLCALLBACK(RTCRestObjectBase *) createInstance(void); 688 /** Deserialization w/ instantiation. */ 689 static FNDESERIALIZEINSTANCEFROMJSON deserializeInstanceFromJson; 665 690 666 691 /** @name RTCString assignment methods we need to replace to manage the null indicator … … 729 754 /** Factory method. */ 730 755 static DECLCALLBACK(RTCRestObjectBase *) createInstance(void); 756 /** Deserialization w/ instantiation. */ 757 static FNDESERIALIZEINSTANCEFROMJSON deserializeInstanceFromJson; 731 758 732 759 /** Date formats. */ … … 992 1019 993 1020 /** Factory method. */ 994 static DECLCALLBACK(RTCRestObjectBase *) createInstance(void) { return new (std::nothrow) RTCRestStringEnum(); } 1021 static DECLCALLBACK(RTCRestObjectBase *) createInstance(void) 1022 { 1023 return new (std::nothrow) RTCRestStringEnum(); 1024 } 1025 1026 /** @copydoc RTCRestObjectBase::FNDESERIALIZEINSTANCEFROMJSON */ 1027 static DECLCALLBACK(int) deserializeInstanceFromJson(RTCRestJsonCursor const &a_rCursor, RTCRestObjectBase **a_ppInstance) 1028 { 1029 *a_ppInstance = new (std::nothrow) RTCRestStringEnum(); 1030 if (*a_ppInstance) 1031 return (*a_ppInstance)->deserializeFromJson(a_rCursor); 1032 return a_rCursor.m_pPrimary->addError(a_rCursor, VERR_NO_MEMORY, "Out of memory"); 1033 } 995 1034 996 1035 protected: … … 1056 1095 /** Factory method. */ 1057 1096 static DECLCALLBACK(RTCRestObjectBase *) createInstance(void); 1097 /** Deserialization w/ instantiation. */ 1098 static FNDESERIALIZEINSTANCEFROMJSON deserializeInstanceFromJson; 1058 1099 1059 1100 protected: -
trunk/include/iprt/cpp/reststringmap.h
r74387 r74402 231 231 232 232 /** 233 * For accessing the static deserializeInstanceFromJson() method of the value. 234 */ 235 virtual int deserializeValueInstanceFromJson(RTCRestJsonCursor const &a_rCursor, RTCRestObjectBase **a_ppInstance) = 0; 236 237 /** 233 238 * Worker for the copy constructor and the assignment operator. 234 239 * … … 342 347 } 343 348 349 /** @copydoc RTCRestObjectBase::FNDESERIALIZEINSTANCEFROMJSON */ 350 static DECLCALLBACK(int) deserializeInstanceFromJson(RTCRestJsonCursor const &a_rCursor, RTCRestObjectBase **a_ppInstance) 351 { 352 *a_ppInstance = new (std::nothrow) RTCRestStringMap<ValueType>(); 353 if (*a_ppInstance) 354 return (*a_ppInstance)->deserializeFromJson(a_rCursor); 355 return a_rCursor.m_pPrimary->addError(a_rCursor, VERR_NO_MEMORY, "Out of memory"); 356 } 357 344 358 /** 345 359 * Inserts the given object into the map. … … 454 468 return new (std::nothrow) ValueType(); 455 469 } 470 471 virtual int deserializeValueInstanceFromJson(RTCRestJsonCursor const &a_rCursor, RTCRestObjectBase **a_ppInstance) RT_OVERRIDE 472 { 473 return ValueType::deserializeInstanceFromJson(a_rCursor, a_ppInstance); 474 } 456 475 }; 457 476 -
trunk/src/VBox/Runtime/common/rest/RTCRestAnyObject.cpp
r74386 r74402 580 580 } 581 581 582 583 /** 584 * @copydoc RTCRestObjectBase::FNDESERIALIZEINSTANCEFROMJSON 585 */ 586 /*static*/ DECLCALLBACK(int) 587 RTCRestAnyObject::deserializeInstanceFromJson(RTCRestJsonCursor const &a_rCursor, RTCRestObjectBase **a_ppInstance) 588 { 589 RTCRestObjectBase *pObj = createInstance(); 590 *a_ppInstance = pObj; 591 if (pObj) 592 return pObj->deserializeFromJson(a_rCursor); 593 return a_rCursor.m_pPrimary->addError(a_rCursor, VERR_NO_MEMORY, "Out of memory"); 594 } 595 -
trunk/src/VBox/Runtime/common/rest/RTCRestArrayBase.cpp
r74386 r74402 156 156 for (size_t idxName = 0;; idxName++) 157 157 { 158 /* Setup sub-cursor. */ 158 159 RTCRestJsonCursor SubCursor(a_rCursor); 159 160 int rc = RTJsonIteratorQueryValue(hIterator, &SubCursor.m_hValue, &SubCursor.m_pszName); 160 161 if (RT_SUCCESS(rc)) 161 162 { 162 RTCRestObjectBase *pObj = createValue(); 163 char szName[32]; 164 RTStrPrintf(szName, sizeof(szName), "[%u]", idxName); 165 SubCursor.m_pszName = szName; 166 167 /* Call the static deserializeInstanceFromJson method of the value class. */ 168 RTCRestObjectBase *pObj = NULL; 169 rc = deserializeValueInstanceFromJson(SubCursor, &pObj); 170 if (RT_SUCCESS(rc)) 171 Assert(pObj); 172 else if (RT_SUCCESS(rcRet)) 173 rcRet = rc; 163 174 if (pObj) 164 175 { 165 char szName[32];166 RTStrPrintf(szName, sizeof(szName), "[%u]", idxName);167 SubCursor.m_pszName = szName;168 169 rc = pObj->deserializeFromJson(SubCursor);170 if (RT_SUCCESS(rc))171 { /* likely */ }172 else if (RT_SUCCESS(rcRet))173 rcRet = rc;174 175 176 rc = insertWorker(~(size_t)0, pObj, false /*a_fReplace*/); 176 177 if (RT_SUCCESS(rc)) … … 183 184 } 184 185 } 185 else186 rcRet = a_rCursor.m_pPrimary->addError(a_rCursor, rc, "Failed to create new value object");187 186 } 188 187 else -
trunk/src/VBox/Runtime/common/rest/RTCRestStringMapBase.cpp
r74386 r74402 144 144 for (;;) 145 145 { 146 /* Set up the sub-cursor. */ 146 147 RTCRestJsonCursor SubCursor(a_rCursor); 147 148 int rc = RTJsonIteratorQueryValue(hIterator, &SubCursor.m_hValue, &SubCursor.m_pszName); 148 149 if (RT_SUCCESS(rc)) 149 150 { 150 RTCRestObjectBase *pObj = createValue(); 151 /* Call the static deserializeInstanceFromJson method of the value class. */ 152 RTCRestObjectBase *pObj = NULL; 153 rc = deserializeValueInstanceFromJson(a_rCursor, &pObj); 154 if (RT_SUCCESS(rc)) 155 Assert(pObj); 156 else if (RT_SUCCESS(rcRet)) 157 rcRet = rc; 151 158 if (pObj) 152 159 { 153 rc = pObj->deserializeFromJson(SubCursor); 154 if (RT_SUCCESS(rc)) 155 { /* likely */ } 156 else if (RT_SUCCESS(rcRet)) 157 rcRet = rc; 158 160 /* Insert the value. */ 159 161 rc = putWorker(SubCursor.m_pszName, pObj, true /*a_fReplace*/); 160 162 if (rc == VINF_SUCCESS) … … 174 176 } 175 177 } 176 else177 rcRet = a_rCursor.m_pPrimary->addError(a_rCursor, rc, "Failed to create new value object");178 178 } 179 179 else -
trunk/src/VBox/Runtime/common/rest/rest-binary.cpp
r74386 r74402 251 251 { 252 252 return new (std::nothrow) RTCRestBinary(); 253 } 254 255 256 /** 257 * @copydoc RTCRestObjectBase::FNDESERIALIZEINSTANCEFROMJSON 258 */ 259 /*static*/ DECLCALLBACK(int) 260 RTCRestBinary::deserializeInstanceFromJson(RTCRestJsonCursor const &a_rCursor, RTCRestObjectBase **a_ppInstance) 261 { 262 RTCRestObjectBase *pObj; 263 *a_ppInstance = pObj = createInstance(); 264 if (pObj) 265 return pObj->deserializeFromJson(a_rCursor); 266 return a_rCursor.m_pPrimary->addError(a_rCursor, VERR_NO_MEMORY, "Out of memory"); 253 267 } 254 268 -
trunk/src/VBox/Runtime/common/rest/rest-primary-object-types.cpp
r74386 r74402 131 131 132 132 133 /** 134 * @copydoc RTCRestObjectBase::FNDESERIALIZEINSTANCEFROMJSON 135 */ 136 /*static*/ DECLCALLBACK(int) 137 RTCRestBool::deserializeInstanceFromJson(RTCRestJsonCursor const &a_rCursor, RTCRestObjectBase **a_ppInstance) 138 { 139 RTCRestObjectBase *pObj = createInstance(); 140 *a_ppInstance = pObj; 141 if (pObj) 142 return pObj->deserializeFromJson(a_rCursor); 143 return a_rCursor.m_pPrimary->addError(a_rCursor, VERR_NO_MEMORY, "Out of memory"); 144 } 145 146 133 147 /** Default constructor. */ 134 148 RTCRestBool::RTCRestBool() … … 307 321 308 322 323 /** 324 * @copydoc RTCRestObjectBase::FNDESERIALIZEINSTANCEFROMJSON 325 */ 326 /*static*/ DECLCALLBACK(int) 327 RTCRestInt64::deserializeInstanceFromJson(RTCRestJsonCursor const &a_rCursor, RTCRestObjectBase **a_ppInstance) 328 { 329 RTCRestObjectBase *pObj = createInstance(); 330 *a_ppInstance = pObj; 331 if (pObj) 332 return pObj->deserializeFromJson(a_rCursor); 333 return a_rCursor.m_pPrimary->addError(a_rCursor, VERR_NO_MEMORY, "Out of memory"); 334 } 335 336 309 337 /** Default constructor. */ 310 338 RTCRestInt64::RTCRestInt64() … … 474 502 { 475 503 return new (std::nothrow) RTCRestInt32(); 504 } 505 506 507 /** 508 * @copydoc RTCRestObjectBase::FNDESERIALIZEINSTANCEFROMJSON 509 */ 510 /*static*/ DECLCALLBACK(int) 511 RTCRestInt32::deserializeInstanceFromJson(RTCRestJsonCursor const &a_rCursor, RTCRestObjectBase **a_ppInstance) 512 { 513 RTCRestObjectBase *pObj = createInstance(); 514 *a_ppInstance = pObj; 515 if (pObj) 516 return pObj->deserializeFromJson(a_rCursor); 517 return a_rCursor.m_pPrimary->addError(a_rCursor, VERR_NO_MEMORY, "Out of memory"); 476 518 } 477 519 … … 653 695 654 696 697 /** 698 * @copydoc RTCRestObjectBase::FNDESERIALIZEINSTANCEFROMJSON 699 */ 700 /*static*/ DECLCALLBACK(int) 701 RTCRestInt16::deserializeInstanceFromJson(RTCRestJsonCursor const &a_rCursor, RTCRestObjectBase **a_ppInstance) 702 { 703 RTCRestObjectBase *pObj = createInstance(); 704 *a_ppInstance = pObj; 705 if (pObj) 706 return pObj->deserializeFromJson(a_rCursor); 707 return a_rCursor.m_pPrimary->addError(a_rCursor, VERR_NO_MEMORY, "Out of memory"); 708 } 709 710 655 711 /** Default constructor. */ 656 712 RTCRestInt16::RTCRestInt16() … … 827 883 return new (std::nothrow) RTCRestDouble(); 828 884 } 885 886 887 /** 888 * @copydoc RTCRestObjectBase::FNDESERIALIZEINSTANCEFROMJSON 889 */ 890 /*static*/ DECLCALLBACK(int) 891 RTCRestDouble::deserializeInstanceFromJson(RTCRestJsonCursor const &a_rCursor, RTCRestObjectBase **a_ppInstance) 892 { 893 RTCRestObjectBase *pObj = createInstance(); 894 *a_ppInstance = pObj; 895 if (pObj) 896 return pObj->deserializeFromJson(a_rCursor); 897 return a_rCursor.m_pPrimary->addError(a_rCursor, VERR_NO_MEMORY, "Out of memory"); 898 } 899 829 900 830 901 /** Default constructor. */ … … 1058 1129 1059 1130 1131 /** 1132 * @copydoc RTCRestObjectBase::FNDESERIALIZEINSTANCEFROMJSON 1133 */ 1134 /*static*/ DECLCALLBACK(int) 1135 RTCRestString::deserializeInstanceFromJson(RTCRestJsonCursor const &a_rCursor, RTCRestObjectBase **a_ppInstance) 1136 { 1137 RTCRestObjectBase *pObj = createInstance(); 1138 *a_ppInstance = pObj; 1139 if (pObj) 1140 return pObj->deserializeFromJson(a_rCursor); 1141 return a_rCursor.m_pPrimary->addError(a_rCursor, VERR_NO_MEMORY, "Out of memory"); 1142 } 1143 1144 1060 1145 /** Default constructor. */ 1061 1146 RTCRestString::RTCRestString() … … 1358 1443 * RTCRestDate implementation * 1359 1444 *********************************************************************************************************************************/ 1445 /*static*/ DECLCALLBACK(RTCRestObjectBase *) RTCRestDate::createInstance(void) 1446 { 1447 return new (std::nothrow) RTCRestDate(); 1448 } 1449 1450 1451 /** 1452 * @copydoc RTCRestObjectBase::FNDESERIALIZEINSTANCEFROMJSON 1453 */ 1454 /*static*/ DECLCALLBACK(int) 1455 RTCRestDate::deserializeInstanceFromJson(RTCRestJsonCursor const &a_rCursor, RTCRestObjectBase **a_ppInstance) 1456 { 1457 RTCRestObjectBase *pObj = createInstance(); 1458 *a_ppInstance = pObj; 1459 if (pObj) 1460 return pObj->deserializeFromJson(a_rCursor); 1461 return a_rCursor.m_pPrimary->addError(a_rCursor, VERR_NO_MEMORY, "Out of memory"); 1462 } 1463 1360 1464 1361 1465 RTCRestDate::RTCRestDate() … … 1532 1636 } 1533 1637 1534 1535 /*static*/ DECLCALLBACK(RTCRestObjectBase *) RTCRestDate::createInstance(void)1536 {1537 return new (std::nothrow) RTCRestDate();1538 }1539 1638 1540 1639 int RTCRestDate::assignValue(PCRTTIMESPEC a_pTimeSpec, kFormat a_enmFormat)
Note:
See TracChangeset
for help on using the changeset viewer.