VirtualBox

Changeset 61737 in vbox for trunk/src/VBox/Runtime/common


Ignore:
Timestamp:
Jun 17, 2016 8:35:23 AM (8 years ago)
Author:
vboxsync
Message:

Runtime/RTJson: Three more helpers, sort RTJson API alphabetically in mangling.h

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/misc/json.cpp

    r61730 r61737  
    13081308}
    13091309
     1310RTDECL(int) RTJsonValueGetNumberByName(RTJSONVAL hJsonVal, const char *pszName, int64_t *pi64Num)
     1311{
     1312    RTJSONVAL hJsonValNum = NIL_RTJSONVAL;
     1313    int rc = RTJsonValueGetByName(hJsonVal, pszName, &hJsonValNum);
     1314    if (RT_SUCCESS(rc))
     1315    {
     1316        rc = RTJsonValueGetNumber(hJsonValNum, pi64Num);
     1317        RTJsonValueRelease(hJsonValNum);
     1318    }
     1319
     1320    return rc;
     1321}
     1322
     1323RTDECL(int) RTJsonValueGetStringByName(RTJSONVAL hJsonVal, const char *pszName, char **ppszStr)
     1324{
     1325    RTJSONVAL hJsonValStr = NIL_RTJSONVAL;
     1326    int rc = RTJsonValueGetByName(hJsonVal, pszName, &hJsonValStr);
     1327    if (RT_SUCCESS(rc))
     1328    {
     1329        const char *pszStr = NULL;
     1330        rc = RTJsonValueGetStringEx(hJsonValStr, &pszStr);
     1331        if (RT_SUCCESS(rc))
     1332        {
     1333            *ppszStr = RTStrDup(pszStr);
     1334            if (!*ppszStr)
     1335                rc = VERR_NO_STR_MEMORY;
     1336        }
     1337        RTJsonValueRelease(hJsonValStr);
     1338    }
     1339
     1340    return rc;
     1341}
     1342
     1343RTDECL(int) RTJsonValueGetBooleanByName(RTJSONVAL hJsonVal, const char *pszName, bool *pfBoolean)
     1344{
     1345    AssertPtrReturn(pfBoolean, VERR_INVALID_POINTER);
     1346
     1347    RTJSONVAL hJsonValBool = NIL_RTJSONVAL;
     1348    int rc = RTJsonValueGetByName(hJsonVal, pszName, &hJsonValBool);
     1349    if (RT_SUCCESS(rc))
     1350    {
     1351        RTJSONVALTYPE enmType = RTJsonValueGetType(hJsonValBool);
     1352        if (enmType == RTJSONVALTYPE_TRUE)
     1353            *pfBoolean = true;
     1354        else if (enmType == RTJSONVALTYPE_FALSE)
     1355            *pfBoolean = false;
     1356        else
     1357            rc = VERR_JSON_VALUE_INVALID_TYPE;
     1358        RTJsonValueRelease(hJsonValBool);
     1359    }
     1360
     1361    return rc;
     1362}
     1363
    13101364RTDECL(uint32_t) RTJsonValueGetArraySize(RTJSONVAL hJsonVal)
    13111365{
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette