Changeset 73874 in vbox for trunk/src/VBox/Runtime
- Timestamp:
- Aug 24, 2018 3:36:01 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/misc/json.cpp
r73616 r73874 1298 1298 1299 1299 1300 #define AssertJsonTypeReturn(pJson, enmExpectedType, ret) do { \ 1301 AssertPtrReturn((pJson), (ret)); \ 1302 AssertReturn((pJson) != NIL_RTJSONVAL, (ret)); \ 1303 AssertReturn((pJson)->enmType == (enmExpectedType), (ret)); \ 1300 RTDECL(const char *) RTJsonValueTypeName(RTJSONVALTYPE enmType) 1301 { 1302 switch (enmType) 1303 { 1304 case RTJSONVALTYPE_INVALID: return "invalid"; 1305 case RTJSONVALTYPE_OBJECT: return "object"; 1306 case RTJSONVALTYPE_ARRAY: return "array"; 1307 case RTJSONVALTYPE_STRING: return "string"; 1308 case RTJSONVALTYPE_NUMBER: return "number"; 1309 case RTJSONVALTYPE_NULL: return "null"; 1310 case RTJSONVALTYPE_TRUE: return "true"; 1311 case RTJSONVALTYPE_FALSE: return "false"; 1312 default: return "???"; 1313 } 1314 } 1315 1316 1317 #define RTJSON_ASSERT_TYPE_RETURN(pJson, enmExpectedType, ret) do { \ 1318 AssertPtrReturn((pJson), (ret)); \ 1319 AssertReturn((pJson) != NIL_RTJSONVAL, (ret)); \ 1320 AssertReturn((pJson)->enmType == (enmExpectedType), (ret)); \ 1304 1321 } while (0) 1305 1322 1306 #define RTJSON_TYPECHECK (pJson, enmExpectedType) do {\1307 if (RT_ UNLIKELY((pJson) == NIL_RTJSONVAL))\1308 return VERR_INVALID_HANDLE;\1309 if ((pJson)->enmType != (enmExpectedType))\1310 return VERR_JSON_VALUE_INVALID_TYPE;\1323 #define RTJSON_TYPECHECK_RETURN(pJson, enmExpectedType) do {\ 1324 if (RT_LIKELY((pJson) != NIL_RTJSONVAL)) { /*likely*/ } \ 1325 else return VERR_INVALID_HANDLE; \ 1326 if ((pJson)->enmType == (enmExpectedType)) { /*likely*/ } \ 1327 else return VERR_JSON_VALUE_INVALID_TYPE; \ 1311 1328 } while (0) 1312 1329 1313 1330 1314 #define RTJSON_TYPECHECK_CONTAINER(pJson) do { \ 1315 if (RT_UNLIKELY((pJson) == NIL_RTJSONVAL)) \ 1316 return VERR_INVALID_HANDLE; \ 1317 if ( (pJson)->enmType != RTJSONVALTYPE_ARRAY \ 1318 && (pJson)->enmType != RTJSONVALTYPE_OBJECT) \ 1319 return VERR_JSON_VALUE_INVALID_TYPE; \ 1331 #define RTJSON_TYPECHECK_CONTAINER_RETURN(pJson) do { \ 1332 if (RT_LIKELY((pJson) != NIL_RTJSONVAL)) { /* likely */ } \ 1333 else return VERR_INVALID_HANDLE; \ 1334 if ( (pJson)->enmType == RTJSONVALTYPE_ARRAY \ 1335 || (pJson)->enmType == RTJSONVALTYPE_OBJECT) \ 1336 { /* likely */ } \ 1337 else return VERR_JSON_VALUE_INVALID_TYPE; \ 1320 1338 } while (0) 1321 1339 … … 1324 1342 { 1325 1343 PRTJSONVALINT pThis = hJsonVal; 1326 AssertJsonTypeReturn(pThis, RTJSONVALTYPE_STRING, NULL);1344 RTJSON_ASSERT_TYPE_RETURN(pThis, RTJSONVALTYPE_STRING, NULL); 1327 1345 1328 1346 return pThis->Type.String.pszStr; … … 1336 1354 AssertPtrReturn(ppszStr, VERR_INVALID_POINTER); 1337 1355 1338 RTJSON_TYPECHECK (pThis, RTJSONVALTYPE_STRING);1356 RTJSON_TYPECHECK_RETURN(pThis, RTJSONVALTYPE_STRING); 1339 1357 *ppszStr = pThis->Type.String.pszStr; 1340 1358 return VINF_SUCCESS; … … 1347 1365 AssertPtrReturn(pi64Num, VERR_INVALID_POINTER); 1348 1366 1349 RTJSON_TYPECHECK (pThis, RTJSONVALTYPE_NUMBER);1367 RTJSON_TYPECHECK_RETURN(pThis, RTJSONVALTYPE_NUMBER); 1350 1368 *pi64Num = pThis->Type.Number.i64Num; 1351 1369 return VINF_SUCCESS; … … 1359 1377 AssertPtrReturn(phJsonVal, VERR_INVALID_POINTER); 1360 1378 1361 RTJSON_TYPECHECK (pThis, RTJSONVALTYPE_OBJECT);1379 RTJSON_TYPECHECK_RETURN(pThis, RTJSONVALTYPE_OBJECT); 1362 1380 1363 1381 int rc = VERR_NOT_FOUND; … … 1433 1451 { 1434 1452 PRTJSONVALINT pThis = hJsonVal; 1435 AssertJsonTypeReturn(pThis, RTJSONVALTYPE_ARRAY, 0);1453 RTJSON_ASSERT_TYPE_RETURN(pThis, RTJSONVALTYPE_ARRAY, 0); 1436 1454 1437 1455 return pThis->Type.Array.cItems; … … 1444 1462 AssertPtrReturn(pcItems, VERR_INVALID_POINTER); 1445 1463 1446 RTJSON_TYPECHECK (pThis, RTJSONVALTYPE_ARRAY);1464 RTJSON_TYPECHECK_RETURN(pThis, RTJSONVALTYPE_ARRAY); 1447 1465 *pcItems = pThis->Type.Array.cItems; 1448 1466 return VINF_SUCCESS; … … 1455 1473 AssertPtrReturn(phJsonVal, VERR_INVALID_POINTER); 1456 1474 1457 RTJSON_TYPECHECK (pThis, RTJSONVALTYPE_ARRAY);1475 RTJSON_TYPECHECK_RETURN(pThis, RTJSONVALTYPE_ARRAY); 1458 1476 if (RT_UNLIKELY(idx >= pThis->Type.Array.cItems)) 1459 1477 return VERR_OUT_OF_RANGE; … … 1470 1488 AssertPtrReturn(phJsonIt, VERR_INVALID_POINTER); 1471 1489 1472 RTJSON_TYPECHECK_CONTAINER (pThis);1490 RTJSON_TYPECHECK_CONTAINER_RETURN(pThis); 1473 1491 1474 1492 PRTJSONITINT pIt = (PRTJSONITINT)RTMemTmpAllocZ(sizeof(RTJSONITINT));
Note:
See TracChangeset
for help on using the changeset viewer.