VirtualBox

Changeset 61737 in vbox


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

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

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/json.h

    r61694 r61737  
    174174 * @returns IPRT status code.
    175175 * @retval VERR_JSON_VALUE_INVALID_TYPE if the JSON value is not an object.
     176 * @retval VERR_NOT_FOUND if the name is not known for this JSON object.
    176177 * @param   hJsonVal        The JSON value handle.
    177178 * @param   pszName         The member name of the object.
     
    179180 */
    180181RTDECL(int) RTJsonValueGetByName(RTJSONVAL hJsonVal, const char *pszName, PRTJSONVAL phJsonVal);
     182
     183/**
     184 * Returns the number of a number value associated with a given name for the given JSON object value.
     185 *
     186 * @returns IPRT status code.
     187 * @retval VERR_JSON_VALUE_INVALID_TYPE if the JSON value is not an object or the name does not point to
     188 *         a number value.
     189 * @retval VERR_NOT_FOUND if the name is not known for this JSON object.
     190 * @param   hJsonVal        The JSON value handle.
     191 * @param   pszName         The member name of the object.
     192 * @param   pi64Num         Where to store the number on success.
     193 */
     194RTDECL(int) RTJsonValueGetNumberByName(RTJSONVAL hJsonVal, const char *pszName, int64_t *pi64Num);
     195
     196/**
     197 * Returns the string of a string value associated with a given name for the given JSON object value.
     198 *
     199 * @returns IPRT status code.
     200 * @retval VERR_JSON_VALUE_INVALID_TYPE if the JSON value is not an object or the name does not point to
     201 *         a string value.
     202 * @retval VERR_NOT_FOUND if the name is not known for this JSON object.
     203 * @param   hJsonVal        The JSON value handle.
     204 * @param   pszName         The member name of the object.
     205 * @param   ppszStr         Where to store the pointer to the string on success. Must be freed with
     206 *                          RTStrFree().
     207 */
     208RTDECL(int) RTJsonValueGetStringByName(RTJSONVAL hJsonVal, const char *pszName, char **ppszStr);
     209
     210/**
     211 * Returns the boolean of a true/false value associated with a given name for the given JSON object value.
     212 *
     213 * @returns IPRT status code.
     214 * @retval VERR_JSON_VALUE_INVALID_TYPE if the JSON value is not an object or the name does not point to
     215 *         a true/false value.
     216 * @retval VERR_NOT_FOUND if the name is not known for this JSON object.
     217 * @param   hJsonVal        The JSON value handle.
     218 * @param   pszName         The member name of the object.
     219 * @param   pfBoolean       Where to store the boolean value on success.
     220 */
     221RTDECL(int) RTJsonValueGetBooleanByName(RTJSONVAL hJsonVal, const char *pszName, bool *pfBoolean);
    181222
    182223/**
  • trunk/include/iprt/mangling.h

    r61693 r61737  
    953953# define RTIsoFsGetFileInfo                             RT_MANGLER(RTIsoFsGetFileInfo)
    954954# define RTIsoFsOpen                                    RT_MANGLER(RTIsoFsOpen)
     955# define RTJsonIteratorBegin                            RT_MANGLER(RTJsonIteratorBegin)
     956# define RTJsonIteratorFree                             RT_MANGLER(RTJsonIteratorFree)
     957# define RTJsonIteratorGetValue                         RT_MANGLER(RTJsonIteratorGetValue)
     958# define RTJsonIteratorNext                             RT_MANGLER(RTJsonIteratorNext)
    955959# define RTJsonParseFromBuf                             RT_MANGLER(RTJsonParseFromBuf)
     960# define RTJsonParseFromFile                            RT_MANGLER(RTJsonParseFromFile)
    956961# define RTJsonParseFromString                          RT_MANGLER(RTJsonParseFromString)
    957 # define RTJsonParseFromFile                            RT_MANGLER(RTJsonParseFromFile)
    958 # define RTJsonValueRetain                              RT_MANGLER(RTJsonValueRetain)
    959 # define RTJsonValueRelease                             RT_MANGLER(RTJsonValueRelease)
    960 # define RTJsonValueGetType                             RT_MANGLER(RTJsonValueGetType)
    961 # define RTJsonValueGetString                           RT_MANGLER(RTJsonValueGetString)
    962 # define RTJsonValueGetStringEx                         RT_MANGLER(RTJsonValueGetStringEx)
    963 # define RTJsonValueGetNumber                           RT_MANGLER(RTJsonValueGetNumber)
    964 # define RTJsonValueGetByName                           RT_MANGLER(RTJsonValueGetByName)
    965962# define RTJsonValueGetArraySize                        RT_MANGLER(RTJsonValueGetArraySize)
    966963# define RTJsonValueGetArraySizeEx                      RT_MANGLER(RTJsonValueGetArraySizeEx)
     964# define RTJsonValueGetBooleanByName                    RT_MANGLER(RTJsonValueGetBooleanByName)
    967965# define RTJsonValueGetByIndex                          RT_MANGLER(RTJsonValueGetByIndex)
    968 # define RTJsonIteratorBegin                            RT_MANGLER(RTJsonIteratorBegin)
    969 # define RTJsonIteratorGetValue                         RT_MANGLER(RTJsonIteratorGetValue)
    970 # define RTJsonIteratorNext                             RT_MANGLER(RTJsonIteratorNext)
    971 # define RTJsonIteratorFree                             RT_MANGLER(RTJsonIteratorFree)
     966# define RTJsonValueGetByName                           RT_MANGLER(RTJsonValueGetByName)
     967# define RTJsonValueGetNumber                           RT_MANGLER(RTJsonValueGetNumber)
     968# define RTJsonValueGetNumberByName                     RT_MANGLER(RTJsonValueGetNumberByName)
     969# define RTJsonValueGetString                           RT_MANGLER(RTJsonValueGetString)
     970# define RTJsonValueGetStringByName                     RT_MANGLER(RTJsonValueGetStringByName)
     971# define RTJsonValueGetStringEx                         RT_MANGLER(RTJsonValueGetStringEx)
     972# define RTJsonValueGetType                             RT_MANGLER(RTJsonValueGetType)
     973# define RTJsonValueRelease                             RT_MANGLER(RTJsonValueRelease)
     974# define RTJsonValueRetain                              RT_MANGLER(RTJsonValueRetain)
    972975# define RTLatin1CalcUtf16Len                           RT_MANGLER(RTLatin1CalcUtf16Len)
    973976# define RTLatin1CalcUtf16LenEx                         RT_MANGLER(RTLatin1CalcUtf16LenEx)
  • 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