Changeset 74008 in vbox for trunk/src/VBox/Runtime
- Timestamp:
- Aug 31, 2018 7:08:02 PM (6 years ago)
- Location:
- trunk/src/VBox/Runtime/common/rest
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/rest/RTCRestArrayBase.cpp
r73995 r74008 88 88 /* The default state of an array is empty. At least for now. */ 89 89 clear(); 90 m_fNullIndicator = false; 90 91 return VINF_SUCCESS; 91 92 } … … 94 95 RTCRestOutputBase &RTCRestArrayBase::serializeAsJson(RTCRestOutputBase &a_rDst) const 95 96 { 96 a_rDst.printf("[\n"); 97 unsigned const uOldIndent = a_rDst.incrementIndent(); 98 99 for (size_t i = 0; i < m_cElements; i++) 100 { 101 m_papElements[i]->serializeAsJson(a_rDst); 102 if (i < m_cElements) 103 a_rDst.printf(",\n"); 104 else 105 a_rDst.printf("\n"); 106 } 107 108 a_rDst.setIndent(uOldIndent); 109 a_rDst.printf("]"); 97 if (!m_fNullIndicator) 98 { 99 a_rDst.printf("[\n"); 100 unsigned const uOldIndent = a_rDst.incrementIndent(); 101 102 for (size_t i = 0; i < m_cElements; i++) 103 { 104 m_papElements[i]->serializeAsJson(a_rDst); 105 if (i < m_cElements) 106 a_rDst.printf(",\n"); 107 else 108 a_rDst.printf("\n"); 109 } 110 111 a_rDst.setIndent(uOldIndent); 112 a_rDst.printf("]"); 113 } 114 else 115 a_rDst.printf("null"); 110 116 return a_rDst; 111 117 } … … 119 125 if (m_cElements > 0) 120 126 clear(); 127 m_fNullIndicator = false; 121 128 122 129 /* … … 179 186 RTJsonIteratorFree(hIterator); 180 187 } 181 else if ( rcRet == VERR_JSON_IS_EMPTY 182 || ( rcRet == VERR_JSON_VALUE_INVALID_TYPE 183 && RTJsonValueGetType(a_rCursor.m_hValue) == RTJSONVALTYPE_NULL) ) 188 else if (rcRet == VERR_JSON_IS_EMPTY) 184 189 rcRet = VINF_SUCCESS; 190 else if ( rcRet == VERR_JSON_VALUE_INVALID_TYPE 191 && RTJsonValueGetType(a_rCursor.m_hValue) == RTJSONVALTYPE_NULL) 192 { 193 m_fNullIndicator = true; 194 rcRet = VINF_SUCCESS; 195 } 185 196 else 186 197 rcRet = a_rCursor.m_pPrimary->addError(a_rCursor, rcRet, … … 195 206 { 196 207 int rc; 197 if (m_cElements) 198 { 199 static char const s_szSep[kCollectionFormat_Mask + 1] = ",, \t|,,"; 200 char const chSep = s_szSep[a_fFlags & kCollectionFormat_Mask]; 201 202 rc = m_papElements[0]->toString(a_pDst, a_fFlags); 203 for (size_t i = 1; RT_SUCCESS(rc) && i < m_cElements; i++) 204 { 205 rc = a_pDst->appendNoThrow(chSep); 206 if (RT_SUCCESS(rc)) 207 rc = m_papElements[i]->toString(a_pDst, a_fFlags | kToString_Append); 208 } 209 } 208 if (!m_fNullIndicator) 209 { 210 if (m_cElements) 211 { 212 static char const s_szSep[kCollectionFormat_Mask + 1] = ",, \t|,,"; 213 char const chSep = s_szSep[a_fFlags & kCollectionFormat_Mask]; 214 215 rc = m_papElements[0]->toString(a_pDst, a_fFlags); 216 for (size_t i = 1; RT_SUCCESS(rc) && i < m_cElements; i++) 217 { 218 rc = a_pDst->appendNoThrow(chSep); 219 if (RT_SUCCESS(rc)) 220 rc = m_papElements[i]->toString(a_pDst, a_fFlags | kToString_Append); 221 } 222 } 223 else 224 { 225 if (!(a_fFlags & kToString_Append)) 226 a_pDst->setNull(); 227 rc = VINF_SUCCESS; 228 } 229 } 230 else if (a_fFlags & kToString_Append) 231 rc = a_pDst->appendNoThrow(RT_STR_TUPLE("null")); 210 232 else 211 { 212 a_pDst->setNull(); 213 rc = VINF_SUCCESS; 214 } 233 rc = a_pDst->appendNoThrow(RT_STR_TUPLE("null")); 234 215 235 return rc; 216 236 } … … 239 259 } 240 260 m_cElements = 0; 261 m_fNullIndicator = false; 241 262 } 242 263 … … 291 312 clear(); 292 313 if (a_rThat.m_cElements == 0) 314 { 315 m_fNullIndicator = a_rThat.m_fNullIndicator; 293 316 rc = VINF_SUCCESS; 317 } 294 318 else 295 319 { 320 Assert(!a_rThat.m_fNullIndicator); 296 321 rc = ensureCapacity(a_rThat.m_cElements); 297 322 if (RT_SUCCESS(rc)) … … 346 371 AssertPtr(m_papElements[i]); 347 372 #endif 373 m_fNullIndicator = false; 348 374 return VINF_SUCCESS; 349 375 } … … 352 378 delete m_papElements[a_idx]; 353 379 m_papElements[a_idx] = a_pValue; 380 m_fNullIndicator = false; 354 381 return VWRN_ALREADY_EXISTS; 355 382 } -
trunk/src/VBox/Runtime/common/rest/RTCRestStringMapBase.cpp
r73995 r74008 40 40 */ 41 41 RTCRestStringMapBase::RTCRestStringMapBase() 42 : m_Map(NULL) 42 : RTCRestObjectBase() 43 , m_Map(NULL) 43 44 , m_cEntries(0) 44 45 { … … 77 78 /* Default is an empty map. */ 78 79 clear(); 80 m_fNullIndicator = false; 79 81 return VINF_SUCCESS; 80 82 } … … 83 85 RTCRestOutputBase &RTCRestStringMapBase::serializeAsJson(RTCRestOutputBase &a_rDst) const 84 86 { 85 a_rDst.printf("{\n"); 86 unsigned const uOldIndent = a_rDst.incrementIndent(); 87 88 MapEntry const * const pLast = RTListGetLastCpp(&m_ListHead, MapEntry, ListEntry); 89 MapEntry const * pCur; 90 RTListForEachCpp(&m_ListHead, pCur, MapEntry, ListEntry) 91 { 92 a_rDst.printf("%RJs: ", pCur->strKey.c_str()); 93 pCur->pValue->serializeAsJson(a_rDst); 94 95 if (pCur != pLast) 96 a_rDst.printf(",\n"); 97 else 98 a_rDst.printf("\n"); 99 } 100 101 a_rDst.setIndent(uOldIndent); 102 a_rDst.printf("}"); 87 if (!m_fNullIndicator) 88 { 89 a_rDst.printf("{\n"); 90 unsigned const uOldIndent = a_rDst.incrementIndent(); 91 92 MapEntry const * const pLast = RTListGetLastCpp(&m_ListHead, MapEntry, ListEntry); 93 MapEntry const * pCur; 94 RTListForEachCpp(&m_ListHead, pCur, MapEntry, ListEntry) 95 { 96 a_rDst.printf("%RJs: ", pCur->strKey.c_str()); 97 pCur->pValue->serializeAsJson(a_rDst); 98 99 if (pCur != pLast) 100 a_rDst.printf(",\n"); 101 else 102 a_rDst.printf("\n"); 103 } 104 105 a_rDst.setIndent(uOldIndent); 106 a_rDst.printf("}"); 107 } 108 else 109 a_rDst.printf("null"); 103 110 return a_rDst; 104 111 } … … 112 119 if (m_cEntries > 0) 113 120 clear(); 121 m_fNullIndicator = false; 114 122 115 123 /* … … 175 183 RTJsonIteratorFree(hIterator); 176 184 } 177 else if ( rcRet == VERR_JSON_IS_EMPTY 178 || ( rcRet == VERR_JSON_VALUE_INVALID_TYPE 179 && RTJsonValueGetType(a_rCursor.m_hValue) == RTJSONVALTYPE_NULL) ) 185 else if (rcRet == VERR_JSON_IS_EMPTY) 180 186 rcRet = VINF_SUCCESS; 187 else if ( rcRet == VERR_JSON_VALUE_INVALID_TYPE 188 && RTJsonValueGetType(a_rCursor.m_hValue) == RTJSONVALTYPE_NULL) 189 { 190 m_fNullIndicator = true; 191 rcRet = VINF_SUCCESS; 192 } 181 193 else 182 194 rcRet = a_rCursor.m_pPrimary->addError(a_rCursor, rcRet, "RTJsonIteratorBegin failed: %Rrc (type %s)", … … 220 232 RTListInit(&m_ListHead); 221 233 m_cEntries = 0; 234 m_fNullIndicator = false; 222 235 } 223 236 … … 267 280 Assert(this != &a_rThat); 268 281 clear(); 269 270 MapEntry const *pCur; 271 RTListForEachCpp(&a_rThat.m_ListHead, pCur, MapEntry, ListEntry) 272 { 273 int rc = putCopyWorker(pCur->strKey.c_str(), *pCur->pValue, true /*a_fReplace*/); 274 if (RT_SUCCESS(rc)) 275 { /* likely */ } 276 else if (a_fThrow) 277 throw std::bad_alloc(); 278 else 279 return rc; 282 m_fNullIndicator = a_rThat.m_fNullIndicator; 283 284 if (!a_rThat.m_fNullIndicator) 285 { 286 MapEntry const *pCur; 287 RTListForEachCpp(&a_rThat.m_ListHead, pCur, MapEntry, ListEntry) 288 { 289 int rc = putCopyWorker(pCur->strKey.c_str(), *pCur->pValue, true /*a_fReplace*/); 290 if (RT_SUCCESS(rc)) 291 { /* likely */ } 292 else if (a_fThrow) 293 throw std::bad_alloc(); 294 else 295 return rc; 296 } 280 297 } 281 298 … … 299 316 { 300 317 m_cEntries++; 318 m_fNullIndicator = false; 301 319 return VINF_SUCCESS; 302 320 } 303 321 322 Assert(!m_fNullIndicator); 304 323 if (!a_fReplace) 305 324 rc = VERR_ALREADY_EXISTS; -
trunk/src/VBox/Runtime/common/rest/rest-primary-object-types.cpp
r73977 r74008 47 47 /** Default constructor. */ 48 48 RTCRestObjectBase::RTCRestObjectBase() 49 : m_fNullIndicator(false) 50 { 51 } 52 53 54 /** Copy constructor. */ 55 RTCRestObjectBase::RTCRestObjectBase(RTCRestObjectBase const &a_rThat) 56 : m_fNullIndicator(a_rThat.m_fNullIndicator) 49 57 { 50 58 } … … 55 63 { 56 64 /* nothing to do */ 65 } 66 67 68 int RTCRestObjectBase::setNull() 69 { 70 int rc = resetToDefault(); 71 m_fNullIndicator = true; 72 return rc; 73 } 74 75 76 void RTCRestObjectBase::setNotNull() 77 { 78 m_fNullIndicator = false; 57 79 } 58 80 … … 107 129 108 130 109 /** Default destructor. */131 /** Default constructor. */ 110 132 RTCRestBool::RTCRestBool() 111 : m_fValue(false) 133 : RTCRestObjectBase() 134 , m_fValue(false) 112 135 { 113 136 } … … 139 162 RTCRestBool &RTCRestBool::operator=(RTCRestBool const &a_rThat) 140 163 { 164 m_fNullIndicator = a_rThat.m_fNullIndicator; 141 165 m_fValue = a_rThat.m_fValue; 142 166 return *this; … … 146 170 int RTCRestBool::assignCopy(RTCRestBool const &a_rThat) 147 171 { 172 m_fNullIndicator = a_rThat.m_fNullIndicator; 148 173 m_fValue = a_rThat.m_fValue; 149 174 return VINF_SUCCESS; … … 154 179 { 155 180 m_fValue = false; 181 m_fNullIndicator = false; 156 182 return VINF_SUCCESS; 157 183 } … … 160 186 RTCRestOutputBase &RTCRestBool::serializeAsJson(RTCRestOutputBase &a_rDst) const 161 187 { 162 a_rDst.printf( m_fValue ? "true" : "false");188 a_rDst.printf(!m_fNullIndicator ? m_fValue ? "true" : "false" : "null"); 163 189 return a_rDst; 164 190 } … … 172 198 { 173 199 m_fValue = true; 200 m_fNullIndicator = false; 174 201 return VINF_SUCCESS; 175 202 } … … 178 205 { 179 206 m_fValue = false; 180 return VINF_SUCCESS;181 }182 183 /* This is probably non-sense... */ 207 m_fNullIndicator = false; 208 return VINF_SUCCESS; 209 } 210 184 211 if (enmType == RTJSONVALTYPE_NULL) 212 { 185 213 m_fValue = false; 214 m_fNullIndicator = true; 215 return VINF_SUCCESS; 216 } 186 217 187 218 return a_rCursor.m_pPrimary->addError(a_rCursor, VERR_WRONG_TYPE, "wrong JSON type %s for boolean", … … 194 225 if (!(a_fFlags & kToString_Append)) 195 226 { 227 if (!m_fNullIndicator) 228 { 229 if (m_fValue) 230 return a_pDst->assignNoThrow(RT_STR_TUPLE("true")); 231 return a_pDst->assignNoThrow(RT_STR_TUPLE("false")); 232 } 233 return a_pDst->assignNoThrow(RT_STR_TUPLE("null")); 234 } 235 236 if (!m_fNullIndicator) 237 { 196 238 if (m_fValue) 197 return a_pDst->assignNoThrow(RT_STR_TUPLE("true")); 198 return a_pDst->assignNoThrow(RT_STR_TUPLE("false")); 199 } 200 if (m_fValue) 201 return a_pDst->appendNoThrow(RT_STR_TUPLE("true")); 202 return a_pDst->appendNoThrow(RT_STR_TUPLE("false")); 239 return a_pDst->appendNoThrow(RT_STR_TUPLE("true")); 240 return a_pDst->appendNoThrow(RT_STR_TUPLE("false")); 241 } 242 return a_pDst->appendNoThrow(RT_STR_TUPLE("null")); 203 243 } 204 244 … … 210 250 211 251 if (a_rValue.startsWithWord("true", RTCString::CaseInsensitive)) 252 { 212 253 m_fValue = true; 254 m_fNullIndicator = false; 255 } 213 256 else if (a_rValue.startsWithWord("false", RTCString::CaseInsensitive)) 257 { 214 258 m_fValue = false; 259 m_fNullIndicator = false; 260 } 261 else if (a_rValue.startsWithWord("null", RTCString::CaseInsensitive)) 262 { 263 m_fValue = false; 264 m_fNullIndicator = true; 265 } 215 266 else 216 267 return RTErrInfoSetF(a_pErrInfo, VERR_INVALID_PARAMETER, "%s: unable to parse '%s' as bool", a_pszName, a_rValue.c_str()); … … 239 290 /** Default destructor. */ 240 291 RTCRestInt64::RTCRestInt64() 241 : m_iValue(0) 292 : RTCRestObjectBase() 293 , m_iValue(0) 242 294 { 243 295 } … … 254 306 /** From value constructor. */ 255 307 RTCRestInt64::RTCRestInt64(int64_t iValue) 256 : m_iValue(iValue) 308 : RTCRestObjectBase() 309 , m_iValue(iValue) 257 310 { 258 311 } … … 269 322 RTCRestInt64 &RTCRestInt64::operator=(RTCRestInt64 const &a_rThat) 270 323 { 324 m_fNullIndicator = a_rThat.m_fNullIndicator; 271 325 m_iValue = a_rThat.m_iValue; 272 326 return *this; … … 276 330 int RTCRestInt64::assignCopy(RTCRestInt64 const &a_rThat) 277 331 { 332 m_fNullIndicator = a_rThat.m_fNullIndicator; 278 333 m_iValue = a_rThat.m_iValue; 279 334 return VINF_SUCCESS; … … 284 339 { 285 340 m_iValue = 0; 341 m_fNullIndicator = false; 286 342 return VINF_SUCCESS; 287 343 } … … 290 346 RTCRestOutputBase &RTCRestInt64::serializeAsJson(RTCRestOutputBase &a_rDst) const 291 347 { 292 a_rDst.printf("%RI64", m_iValue); 348 if (!m_fNullIndicator) 349 a_rDst.printf("%RI64", m_iValue); 350 else 351 a_rDst.printf("null"); 293 352 return a_rDst; 294 353 } … … 297 356 int RTCRestInt64::deserializeFromJson(RTCRestJsonCursor const &a_rCursor) 298 357 { 358 m_iValue = 0; 359 m_fNullIndicator = false; 360 299 361 RTJSONVALTYPE enmType = RTJsonValueGetType(a_rCursor.m_hValue); 300 362 if (enmType == RTJSONVALTYPE_NUMBER) … … 306 368 } 307 369 370 if (enmType == RTJSONVALTYPE_NULL) 371 { 372 m_fNullIndicator = true; 373 return VINF_SUCCESS; 374 } 375 308 376 /* This is probably non-sense... */ 309 if (enmType == RTJSONVALTYPE_NULL || enmType == RTJSONVALTYPE_FALSE) 310 m_iValue = 0; 311 else if (enmType == RTJSONVALTYPE_TRUE) 377 if (enmType == RTJSONVALTYPE_TRUE) 312 378 m_iValue = 1; 313 379 … … 320 386 { 321 387 if (!(a_fFlags & kToString_Append)) 322 return a_pDst->printfNoThrow("%RI64", m_iValue); 323 return a_pDst->appendPrintfNoThrow("%RI64", m_iValue); 388 { 389 if (!m_fNullIndicator) 390 return a_pDst->printfNoThrow("%RI64", m_iValue); 391 return a_pDst->assignNoThrow(RT_STR_TUPLE("null")); 392 } 393 if (!m_fNullIndicator) 394 return a_pDst->appendPrintfNoThrow("%RI64", m_iValue); 395 return a_pDst->appendNoThrow(RT_STR_TUPLE("null")); 324 396 } 325 397 … … 330 402 RT_NOREF(a_fFlags); 331 403 404 m_iValue = 0; 405 m_fNullIndicator = false; 406 332 407 int rc = RTStrToInt64Full(RTStrStripL(a_rValue.c_str()), 10, &m_iValue); 333 408 if (rc == VINF_SUCCESS || rc == VERR_TRAILING_SPACES) 334 409 return VINF_SUCCESS; 410 411 if (a_rValue.startsWithWord("null", RTCString::CaseInsensitive)) 412 { 413 m_iValue = 0; 414 m_fNullIndicator = true; 415 return VINF_SUCCESS; 416 } 417 335 418 return RTErrInfoSetF(a_pErrInfo, rc, "%s: error %Rrc parsing '%s' as int64_t", a_pszName, rc, a_rValue.c_str()); 336 419 } … … 357 440 /** Default destructor. */ 358 441 RTCRestInt32::RTCRestInt32() 359 : m_iValue(0) 442 : RTCRestObjectBase() 443 , m_iValue(0) 360 444 { 361 445 } … … 372 456 /** From value constructor. */ 373 457 RTCRestInt32::RTCRestInt32(int32_t iValue) 374 : m_iValue(iValue) 458 : RTCRestObjectBase() 459 , m_iValue(iValue) 375 460 { 376 461 } … … 387 472 RTCRestInt32 &RTCRestInt32::operator=(RTCRestInt32 const &a_rThat) 388 473 { 474 m_fNullIndicator = a_rThat.m_fNullIndicator; 389 475 m_iValue = a_rThat.m_iValue; 390 476 return *this; … … 394 480 int RTCRestInt32::assignCopy(RTCRestInt32 const &a_rThat) 395 481 { 482 m_fNullIndicator = a_rThat.m_fNullIndicator; 396 483 m_iValue = a_rThat.m_iValue; 397 484 return VINF_SUCCESS; … … 402 489 { 403 490 m_iValue = 0; 491 m_fNullIndicator = false; 404 492 return VINF_SUCCESS; 405 493 } … … 408 496 RTCRestOutputBase &RTCRestInt32::serializeAsJson(RTCRestOutputBase &a_rDst) const 409 497 { 410 a_rDst.printf("%RI32", m_iValue); 498 if (!m_fNullIndicator) 499 a_rDst.printf("%RI32", m_iValue); 500 else 501 a_rDst.printf("null"); 411 502 return a_rDst; 412 503 } … … 415 506 int RTCRestInt32::deserializeFromJson(RTCRestJsonCursor const &a_rCursor) 416 507 { 508 m_iValue = 0; 509 m_fNullIndicator = false; 510 417 511 RTJSONVALTYPE enmType = RTJsonValueGetType(a_rCursor.m_hValue); 418 512 if (enmType == RTJSONVALTYPE_NUMBER) … … 430 524 } 431 525 526 if (enmType == RTJSONVALTYPE_NULL) 527 { 528 m_fNullIndicator = true; 529 return VINF_SUCCESS; 530 } 531 432 532 /* This is probably non-sense... */ 433 if (enmType == RTJSONVALTYPE_NULL || enmType == RTJSONVALTYPE_FALSE) 434 m_iValue = 0; 435 else if (enmType == RTJSONVALTYPE_TRUE) 533 if (enmType == RTJSONVALTYPE_TRUE) 436 534 m_iValue = 1; 437 535 … … 444 542 { 445 543 if (!(a_fFlags & kToString_Append)) 446 return a_pDst->printfNoThrow("%RI32", m_iValue); 447 return a_pDst->appendPrintfNoThrow("%RI32", m_iValue); 544 { 545 if (!m_fNullIndicator) 546 return a_pDst->printfNoThrow("%RI32", m_iValue); 547 return a_pDst->assignNoThrow(RT_STR_TUPLE("null")); 548 } 549 if (!m_fNullIndicator) 550 return a_pDst->appendPrintfNoThrow("%RI32", m_iValue); 551 return a_pDst->appendNoThrow(RT_STR_TUPLE("null")); 448 552 } 449 553 … … 454 558 RT_NOREF(a_fFlags); 455 559 560 m_iValue = 0; 561 m_fNullIndicator = false; 562 456 563 int rc = RTStrToInt32Full(RTStrStripL(a_rValue.c_str()), 10, &m_iValue); 457 564 if (rc == VINF_SUCCESS || rc == VERR_TRAILING_SPACES) 458 565 return VINF_SUCCESS; 566 567 if (a_rValue.startsWithWord("null", RTCString::CaseInsensitive)) 568 { 569 m_iValue = 0; 570 m_fNullIndicator = true; 571 return VINF_SUCCESS; 572 } 573 459 574 return RTErrInfoSetF(a_pErrInfo, rc, "%s: error %Rrc parsing '%s' as int32_t", a_pszName, rc, a_rValue.c_str()); 460 575 } … … 481 596 /** Default destructor. */ 482 597 RTCRestInt16::RTCRestInt16() 483 : m_iValue(0) 598 : RTCRestObjectBase() 599 , m_iValue(0) 484 600 { 485 601 } … … 496 612 /** From value constructor. */ 497 613 RTCRestInt16::RTCRestInt16(int16_t iValue) 498 : m_iValue(iValue) 614 : RTCRestObjectBase() 615 , m_iValue(iValue) 499 616 { 500 617 } … … 511 628 RTCRestInt16 &RTCRestInt16::operator=(RTCRestInt16 const &a_rThat) 512 629 { 630 m_fNullIndicator = a_rThat.m_fNullIndicator; 513 631 m_iValue = a_rThat.m_iValue; 514 632 return *this; … … 518 636 int RTCRestInt16::assignCopy(RTCRestInt16 const &a_rThat) 519 637 { 638 m_fNullIndicator = a_rThat.m_fNullIndicator; 520 639 m_iValue = a_rThat.m_iValue; 521 640 return VINF_SUCCESS; … … 526 645 { 527 646 m_iValue = 0; 647 m_fNullIndicator = false; 528 648 return VINF_SUCCESS; 529 649 } … … 532 652 RTCRestOutputBase &RTCRestInt16::serializeAsJson(RTCRestOutputBase &a_rDst) const 533 653 { 534 a_rDst.printf("%RI16", m_iValue); 654 if (!m_fNullIndicator) 655 a_rDst.printf("%RI16", m_iValue); 656 else 657 a_rDst.printf("null"); 535 658 return a_rDst; 536 659 } … … 539 662 int RTCRestInt16::deserializeFromJson(RTCRestJsonCursor const &a_rCursor) 540 663 { 664 m_iValue = 0; 665 m_fNullIndicator = false; 666 541 667 RTJSONVALTYPE enmType = RTJsonValueGetType(a_rCursor.m_hValue); 542 668 if (enmType == RTJSONVALTYPE_NUMBER) … … 554 680 } 555 681 682 if (enmType == RTJSONVALTYPE_NULL) 683 { 684 m_fNullIndicator = true; 685 return VINF_SUCCESS; 686 } 687 556 688 /* This is probably non-sense... */ 557 if (enmType == RTJSONVALTYPE_NULL || enmType == RTJSONVALTYPE_FALSE) 558 m_iValue = 0; 559 else if (enmType == RTJSONVALTYPE_TRUE) 689 if (enmType == RTJSONVALTYPE_TRUE) 560 690 m_iValue = 1; 561 691 … … 568 698 { 569 699 if (!(a_fFlags & kToString_Append)) 570 return a_pDst->printfNoThrow("%RI16", m_iValue); 571 return a_pDst->appendPrintfNoThrow("%RI16", m_iValue); 700 { 701 if (!m_fNullIndicator) 702 return a_pDst->printfNoThrow("%RI16", m_iValue); 703 return a_pDst->assignNoThrow(RT_STR_TUPLE("null")); 704 } 705 if (!m_fNullIndicator) 706 return a_pDst->appendPrintfNoThrow("%RI16", m_iValue); 707 return a_pDst->appendNoThrow(RT_STR_TUPLE("null")); 572 708 } 573 709 … … 578 714 RT_NOREF(a_fFlags); 579 715 716 m_iValue = 0; 717 m_fNullIndicator = false; 718 580 719 int rc = RTStrToInt16Full(RTStrStripL(a_rValue.c_str()), 10, &m_iValue); 581 720 if (rc == VINF_SUCCESS || rc == VERR_TRAILING_SPACES) 582 721 return VINF_SUCCESS; 722 723 if (a_rValue.startsWithWord("null", RTCString::CaseInsensitive)) 724 { 725 m_iValue = 0; 726 m_fNullIndicator = true; 727 return VINF_SUCCESS; 728 } 729 583 730 return RTErrInfoSetF(a_pErrInfo, rc, "%s: error %Rrc parsing '%s' as int16_t", a_pszName, rc, a_rValue.c_str()); 584 731 } … … 604 751 /** Default destructor. */ 605 752 RTCRestDouble::RTCRestDouble() 606 : m_rdValue(0.0) 753 : RTCRestObjectBase() 754 , m_rdValue(0.0) 607 755 { 608 756 } … … 619 767 /** From value constructor. */ 620 768 RTCRestDouble::RTCRestDouble(double rdValue) 621 : m_rdValue(rdValue) 769 : RTCRestObjectBase() 770 , m_rdValue(rdValue) 622 771 { 623 772 } … … 634 783 RTCRestDouble &RTCRestDouble::operator=(RTCRestDouble const &a_rThat) 635 784 { 785 m_fNullIndicator = a_rThat.m_fNullIndicator; 636 786 m_rdValue = a_rThat.m_rdValue; 637 787 return *this; … … 641 791 int RTCRestDouble::assignCopy(RTCRestDouble const &a_rThat) 642 792 { 793 m_fNullIndicator = a_rThat.m_fNullIndicator; 643 794 m_rdValue = a_rThat.m_rdValue; 644 795 return VINF_SUCCESS; … … 649 800 { 650 801 m_rdValue = 0.0; 802 m_fNullIndicator = false; 651 803 return VINF_SUCCESS; 652 804 } … … 655 807 RTCRestOutputBase &RTCRestDouble::serializeAsJson(RTCRestOutputBase &a_rDst) const 656 808 { 657 /* Just a simple approximation here. */ 658 /** @todo implement floating point values for json. */ 659 char szValue[128]; 809 if (!m_fNullIndicator) 810 { 811 812 /* Just a simple approximation here. */ 813 /** @todo implement floating point values for json. */ 814 char szValue[128]; 660 815 #ifdef _MSC_VER 661 _snprintf(szValue, sizeof(szValue), "%g", m_rdValue);816 _snprintf(szValue, sizeof(szValue), "%g", m_rdValue); 662 817 #else 663 snprintf(szValue, sizeof(szValue), "%g", m_rdValue);818 snprintf(szValue, sizeof(szValue), "%g", m_rdValue); 664 819 #endif 665 a_rDst.printf("%s", szValue); 820 a_rDst.printf("%s", szValue); 821 } 822 else 823 a_rDst.printf("null"); 666 824 return a_rDst; 667 825 } … … 678 836 int RTCRestDouble::toString(RTCString *a_pDst, uint32_t a_fFlags /*= kCollectionFormat_Unspecified*/) const 679 837 { 680 /* Just a simple approximation here. */ 681 /** @todo implement floating point values for json. */ 682 char szValue[128]; 838 if (!m_fNullIndicator) 839 { 840 /* Just a simple approximation here. */ 841 /** @todo implement floating point values for json. */ 842 char szValue[128]; 683 843 #ifdef _MSC_VER 684 _snprintf(szValue, sizeof(szValue), "%g", m_rdValue);844 _snprintf(szValue, sizeof(szValue), "%g", m_rdValue); 685 845 #else 686 snprintf(szValue, sizeof(szValue), "%g", m_rdValue);846 snprintf(szValue, sizeof(szValue), "%g", m_rdValue); 687 847 #endif 688 size_t const cchValue = strlen(szValue); 848 size_t const cchValue = strlen(szValue); 849 850 if (!(a_fFlags & kToString_Append)) 851 return a_pDst->assignNoThrow(szValue, cchValue); 852 return a_pDst->appendNoThrow(szValue, cchValue); 853 } 689 854 690 855 if (!(a_fFlags & kToString_Append)) 691 return a_pDst->assignNoThrow( szValue, cchValue);692 return a_pDst->appendNoThrow( szValue, cchValue);856 return a_pDst->assignNoThrow(RT_STR_TUPLE("null")); 857 return a_pDst->appendNoThrow(RT_STR_TUPLE("null")); 693 858 } 694 859 … … 698 863 { 699 864 RT_NOREF(a_fFlags); 865 866 m_fNullIndicator = false; 700 867 701 868 const char *pszValue = RTStrStripL(a_rValue.c_str()); … … 705 872 if (errno == 0) 706 873 return VINF_SUCCESS; 874 875 if (a_rValue.startsWithWord("null", RTCString::CaseInsensitive)) 876 { 877 m_rdValue = 0.0; 878 m_fNullIndicator = true; 879 return VINF_SUCCESS; 880 } 881 707 882 int rc = RTErrConvertFromErrno(errno); 708 883 return RTErrInfoSetF(a_pErrInfo, rc, "%s: error %Rrc parsing '%s' as double", a_pszName, rc, a_rValue.c_str()); … … 731 906 RTCRestString::RTCRestString() 732 907 : RTCString() 908 , RTCRestObjectBase() 733 909 { 734 910 } … … 753 929 RTCRestString::RTCRestString(const char *a_pszSrc) 754 930 : RTCString(a_pszSrc) 931 , RTCRestObjectBase() 755 932 { 756 933 } … … 764 941 765 942 943 int RTCRestString::assignCopy(RTCRestString const &a_rThat) 944 { 945 m_fNullIndicator = a_rThat.m_fNullIndicator; 946 return assignNoThrow(a_rThat); 947 } 948 949 766 950 int RTCRestString::assignCopy(RTCString const &a_rThat) 767 951 { 952 m_fNullIndicator = false; 768 953 return assignNoThrow(a_rThat); 769 954 } … … 772 957 int RTCRestString::assignCopy(const char *a_pszThat) 773 958 { 959 m_fNullIndicator = false; 774 960 return assignNoThrow(a_pszThat); 775 961 } 776 962 777 963 964 int RTCRestString::setNull() 965 { 966 RTCString::setNull(); 967 m_fNullIndicator = true; 968 return VINF_SUCCESS; 969 } 970 971 778 972 int RTCRestString::resetToDefault() 779 973 { 780 setNull(); 974 RTCString::setNull(); 975 m_fNullIndicator = false; 781 976 return VINF_SUCCESS; 782 977 } … … 785 980 RTCRestOutputBase &RTCRestString::serializeAsJson(RTCRestOutputBase &a_rDst) const 786 981 { 787 a_rDst.printf("%RMjs", m_psz); 982 if (!m_fNullIndicator) 983 a_rDst.printf("%RMjs", m_psz); 984 else 985 a_rDst.printf("null"); 788 986 return a_rDst; 789 987 } … … 792 990 int RTCRestString::deserializeFromJson(RTCRestJsonCursor const &a_rCursor) 793 991 { 992 m_fNullIndicator = false; 993 794 994 RTJSONVALTYPE enmType = RTJsonValueGetType(a_rCursor.m_hValue); 795 995 if (enmType == RTJSONVALTYPE_STRING) … … 803 1003 } 804 1004 805 if (enmType == RTJSONVALTYPE_NULL) /** @todo RTJSONVALTYPE_NULL for strings??? */ 806 { 807 setNull(); 1005 RTCString::setNull(); 1006 1007 if (enmType == RTJSONVALTYPE_NULL) 1008 { 1009 m_fNullIndicator = true; 808 1010 return VINF_SUCCESS; 809 1011 } … … 816 1018 int RTCRestString::toString(RTCString *a_pDst, uint32_t a_fFlags /*= kCollectionFormat_Unspecified*/) const 817 1019 { 1020 /* Note! m_fNullIndicator == true: empty string. */ 818 1021 if (!(a_fFlags & kToString_Append)) 819 1022 return a_pDst->assignNoThrow(*this); … … 827 1030 RT_NOREF(a_fFlags); RT_NOREF(a_pszName); RT_NOREF(a_pErrInfo); 828 1031 1032 /* Note! Unable to set m_fNullIndicator = true here. */ 1033 m_fNullIndicator = false; 829 1034 return assignNoThrow(a_rValue); 830 1035 }
Note:
See TracChangeset
for help on using the changeset viewer.