Changeset 73920 in vbox for trunk/src/VBox/Runtime
- Timestamp:
- Aug 27, 2018 7:38:55 PM (6 years ago)
- Location:
- trunk/src/VBox/Runtime
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/Makefile.kmk
r73918 r73920 1655 1655 common/rest/RTCRestClientApiBase.cpp \ 1656 1656 common/rest/RTCRestClientRequestBase.cpp \ 1657 common/rest/RTCRestClientResponseBase.cpp \ 1657 1658 common/rest/RTCRestJsonPrimaryCursor.cpp \ 1658 1659 common/rest/RTCRestOutputToString.cpp -
trunk/src/VBox/Runtime/common/rest/rest-primary-object-types.cpp
r73914 r73920 35 35 36 36 #include <stdio.h> 37 #include <stdlib.h> 38 #include <errno.h> 37 39 38 40 … … 55 57 56 58 57 int RTCRestObjectBase::toString(RTCString *a_pDst, uint32_t a_fFlags /*= 0*/) const58 { 59 Assert(a_fFlags == 0); RT_NOREF(a_fFlags);59 int RTCRestObjectBase::toString(RTCString *a_pDst, uint32_t a_fFlags /*= kCollectionFormat_Unspecified*/) const 60 { 61 Assert(a_fFlags == kCollectionFormat_Unspecified); RT_NOREF(a_fFlags); 60 62 61 63 /* … … 76 78 77 79 80 int RTCRestObjectBase::fromString(RTCString const &a_rValue, const char *a_pszName, PRTERRINFO a_pErrInfo /*= NULL*/, 81 uint32_t a_fFlags /*= kCollectionFormat_Unspecified*/) 82 { 83 Assert(a_fFlags == kCollectionFormat_Unspecified); RT_NOREF(a_fFlags); 84 85 /* 86 * Just wrap the JSON serialization method. 87 */ 88 RTJSONVAL hValue = NIL_RTJSONVAL; 89 int rc = RTJsonParseFromString(&hValue, a_rValue.c_str(), a_pErrInfo); 90 if (RT_SUCCESS(rc)) 91 { 92 RTCRestJsonPrimaryCursor PrimaryCursor(hValue, a_pszName, a_pErrInfo); 93 rc = deserializeFromJson(PrimaryCursor.m_Cursor); 94 } 95 return rc; 96 } 97 78 98 79 99 /********************************************************************************************************************************* … … 156 176 157 177 158 int RTCRestBool::toString(RTCString *a_pDst, uint32_t a_fFlags /*= 0*/) const 159 { 160 Assert(a_fFlags == 0); RT_NOREF(a_fFlags); 161 162 /* Be a little careful here to avoid throwing anything. */ 163 int rc = a_pDst->reserveNoThrow(m_fValue ? sizeof("true") : sizeof("false")); 164 if (RT_SUCCESS(rc)) 165 { 166 if (m_fValue) 167 a_pDst->assign(RT_STR_TUPLE("true")); 168 else 169 a_pDst->assign(RT_STR_TUPLE("false")); 170 } 171 return rc; 178 int RTCRestBool::toString(RTCString *a_pDst, uint32_t a_fFlags /*= kCollectionFormat_Unspecified*/) const 179 { 180 Assert(a_fFlags == 0); RT_NOREF(a_fFlags); 181 182 if (m_fValue) 183 return a_pDst->assignNoThrow(RT_STR_TUPLE("true")); 184 return a_pDst->assignNoThrow(RT_STR_TUPLE("false")); 185 } 186 187 188 int RTCRestBool::fromString(RTCString const &a_rValue, const char *a_pszName, PRTERRINFO a_pErrInfo /*= NULL*/, 189 uint32_t a_fFlags /*= kCollectionFormat_Unspecified*/) 190 { 191 Assert(a_fFlags == 0); RT_NOREF(a_fFlags); 192 if (a_rValue.startsWithWord("true", RTCString::CaseInsensitive)) 193 m_fValue = true; 194 else if (a_rValue.startsWithWord("false", RTCString::CaseInsensitive)) 195 m_fValue = false; 196 else 197 return RTErrInfoSetF(a_pErrInfo, VERR_INVALID_PARAMETER, "%s: unable to parse '%s' as bool", a_pszName, a_rValue.c_str()); 198 return VINF_SUCCESS; 172 199 } 173 200 … … 255 282 256 283 257 int RTCRestInt64::toString(RTCString *a_pDst, uint32_t a_fFlags /*= 0*/) const 258 { 259 Assert(a_fFlags == 0); RT_NOREF(a_fFlags); 260 261 /* Be a little careful here to avoid throwing anything. */ 262 char szValue[64]; 263 size_t cchValue = RTStrPrintf(szValue, sizeof(szValue), "%RI64", m_iValue); 264 int rc = a_pDst->reserveNoThrow(cchValue + 1); 265 if (RT_SUCCESS(rc)) 266 a_pDst->assign(szValue, cchValue); 267 return rc; 284 int RTCRestInt64::toString(RTCString *a_pDst, uint32_t a_fFlags /*= kCollectionFormat_Unspecified*/) const 285 { 286 Assert(a_fFlags == 0); RT_NOREF(a_fFlags); 287 288 return a_pDst->printfNoThrow("%RI64", m_iValue); 289 } 290 291 292 int RTCRestInt64::fromString(RTCString const &a_rValue, const char *a_pszName, PRTERRINFO a_pErrInfo /*= NULL*/, 293 uint32_t a_fFlags /*= kCollectionFormat_Unspecified*/) 294 { 295 Assert(a_fFlags == 0); RT_NOREF(a_fFlags); 296 297 int rc = RTStrToInt64Full(RTStrStripL(a_rValue.c_str()), 10, &m_iValue); 298 if (rc == VINF_SUCCESS || rc == VERR_TRAILING_SPACES) 299 return VINF_SUCCESS; 300 return RTErrInfoSetF(a_pErrInfo, rc, "%s: error %Rrc parsing '%s' as int64_t", a_pszName, rc, a_rValue.c_str()); 268 301 } 269 302 … … 358 391 359 392 360 int RTCRestInt32::toString(RTCString *a_pDst, uint32_t a_fFlags /*= 0*/) const 361 { 362 Assert(a_fFlags == 0); RT_NOREF(a_fFlags); 363 364 /* Be a little careful here to avoid throwing anything. */ 365 char szValue[16]; 366 size_t cchValue = RTStrPrintf(szValue, sizeof(szValue), "%RI32", m_iValue); 367 int rc = a_pDst->reserveNoThrow(cchValue + 1); 368 if (RT_SUCCESS(rc)) 369 a_pDst->assign(szValue, cchValue); 370 return rc; 393 int RTCRestInt32::toString(RTCString *a_pDst, uint32_t a_fFlags /*= kCollectionFormat_Unspecified*/) const 394 { 395 Assert(a_fFlags == 0); RT_NOREF(a_fFlags); 396 397 return a_pDst->printfNoThrow("%RI32", m_iValue); 398 } 399 400 401 int RTCRestInt32::fromString(RTCString const &a_rValue, const char *a_pszName, PRTERRINFO a_pErrInfo /*= NULL*/, 402 uint32_t a_fFlags /*= kCollectionFormat_Unspecified*/) 403 { 404 Assert(a_fFlags == 0); RT_NOREF(a_fFlags); 405 406 int rc = RTStrToInt32Full(RTStrStripL(a_rValue.c_str()), 10, &m_iValue); 407 if (rc == VINF_SUCCESS || rc == VERR_TRAILING_SPACES) 408 return VINF_SUCCESS; 409 return RTErrInfoSetF(a_pErrInfo, rc, "%s: error %Rrc parsing '%s' as int32_t", a_pszName, rc, a_rValue.c_str()); 371 410 } 372 411 … … 461 500 462 501 463 int RTCRestInt16::toString(RTCString *a_pDst, uint32_t a_fFlags /*= 0*/) const 464 { 465 Assert(a_fFlags == 0); RT_NOREF(a_fFlags); 466 467 /* Be a little careful here to avoid throwing anything. */ 468 char szValue[8]; 469 size_t cchValue = RTStrPrintf(szValue, sizeof(szValue), "%RI16", m_iValue); 470 int rc = a_pDst->reserveNoThrow(cchValue + 1); 471 if (RT_SUCCESS(rc)) 472 a_pDst->assign(szValue, cchValue); 473 return rc; 502 int RTCRestInt16::toString(RTCString *a_pDst, uint32_t a_fFlags /*= kCollectionFormat_Unspecified*/) const 503 { 504 Assert(a_fFlags == 0); RT_NOREF(a_fFlags); 505 506 return a_pDst->printfNoThrow("%RI16", m_iValue); 507 } 508 509 510 int RTCRestInt16::fromString(RTCString const &a_rValue, const char *a_pszName, PRTERRINFO a_pErrInfo /*= NULL*/, 511 uint32_t a_fFlags /*= kCollectionFormat_Unspecified*/) 512 { 513 Assert(a_fFlags == 0); RT_NOREF(a_fFlags); 514 515 int rc = RTStrToInt16Full(RTStrStripL(a_rValue.c_str()), 10, &m_iValue); 516 if (rc == VINF_SUCCESS || rc == VERR_TRAILING_SPACES) 517 return VINF_SUCCESS; 518 return RTErrInfoSetF(a_pErrInfo, rc, "%s: error %Rrc parsing '%s' as int16_t", a_pszName, rc, a_rValue.c_str()); 474 519 } 475 520 … … 544 589 545 590 546 int RTCRestDouble::toString(RTCString *a_pDst, uint32_t a_fFlags /*= 0*/) const591 int RTCRestDouble::toString(RTCString *a_pDst, uint32_t a_fFlags /*= kCollectionFormat_Unspecified*/) const 547 592 { 548 593 Assert(a_fFlags == 0); RT_NOREF(a_fFlags); … … 558 603 size_t const cchValue = strlen(szValue); 559 604 560 int rc = a_pDst->reserveNoThrow(cchValue + 1); 561 if (RT_SUCCESS(rc)) 562 a_pDst->assign(szValue, cchValue); 563 return rc; 605 return a_pDst->assignNoThrow(szValue, cchValue); 606 } 607 608 609 int RTCRestDouble::fromString(RTCString const &a_rValue, const char *a_pszName, PRTERRINFO a_pErrInfo /*= NULL*/, 610 uint32_t a_fFlags /*= kCollectionFormat_Unspecified*/) 611 { 612 Assert(a_fFlags == 0); RT_NOREF(a_fFlags); 613 614 const char *pszValue = RTStrStripL(a_rValue.c_str()); 615 errno = 0; 616 char *pszNext = NULL; 617 m_rdValue = strtod(pszValue, &pszNext); 618 if (errno == 0) 619 return VINF_SUCCESS; 620 int rc = RTErrConvertFromErrno(errno); 621 return RTErrInfoSetF(a_pErrInfo, rc, "%s: error %Rrc parsing '%s' as double", a_pszName, rc, a_rValue.c_str()); 564 622 } 565 623 … … 632 690 const char *pszValue = RTJsonValueGetString(a_rCursor.m_hValue); 633 691 const size_t cchValue = strlen(pszValue); 634 int rc = reserveNoThrow(cchValue + 1);692 int rc = assignNoThrow(pszValue, cchValue); 635 693 if (RT_SUCCESS(rc)) 636 {637 assign(pszValue, cchValue);638 694 return VINF_SUCCESS; 639 }640 695 return a_rCursor.m_pPrimary->addError(a_rCursor, rc, "no memory for %zu char long string", cchValue); 641 696 } … … 652 707 653 708 654 int RTCRestString::toString(RTCString *a_pDst, uint32_t a_fFlags /*= 0*/) const655 { 656 Assert(a_fFlags == 0); RT_NOREF(a_fFlags); 657 658 /* Careful as always. */659 if (m_cch) 660 { 661 int rc = a_pDst->reserveNoThrow(m_cch + 1); 662 if (RT_SUCCESS(rc)) 663 { /* likely */ }664 else 665 return rc;666 }667 a_pDst->assign(*this); 668 return VINF_SUCCESS;709 int RTCRestString::toString(RTCString *a_pDst, uint32_t a_fFlags /*= kCollectionFormat_Unspecified*/) const 710 { 711 Assert(a_fFlags == 0); RT_NOREF(a_fFlags); 712 713 return a_pDst->assignNoThrow(*this); 714 } 715 716 717 int RTCRestString::fromString(RTCString const &a_rValue, const char *a_pszName, PRTERRINFO a_pErrInfo /*= NULL*/, 718 uint32_t a_fFlags /*= kCollectionFormat_Unspecified*/) 719 { 720 Assert(a_fFlags == 0); RT_NOREF(a_fFlags); 721 RT_NOREF(a_pszName); RT_NOREF(a_pErrInfo); 722 723 return assignNoThrow(a_rValue); 669 724 } 670 725
Note:
See TracChangeset
for help on using the changeset viewer.