|
jaffarCommon
|
Contains common functions related to JSON manipulation. More...

Go to the source code of this file.
Typedefs | |
| typedef nlohmann::json | jaffarCommon::json::object |
Contains common functions related to JSON manipulation.
| typedef nlohmann::json jaffarCommon::json::object |
Masks the use of nlohmann namespace in favor or an implementation-agnostic naming
| __JAFFAR_COMMON_INLINE__ const void jaffarCommon::json::checkEmpty | ( | const object & | json, |
| const std::string & | context | ||
| ) |
Throws if the given json object still contains any keys. Used after a parser has consumed (via the pop*() functions) every key it recognizes: anything left is an unrecognized key, which is reported by name together with the context (e.g. the configuration section the keys came from).
| [in] | json | The (already-consumed) json object that should be empty |
| [in] | context | A human-readable description of where the keys came from, used in the error |
| __JAFFAR_COMMON_INLINE__ const void jaffarCommon::json::checkEntry | ( | const object & | json, |
| const std::string & | key | ||
| ) |
Verifies the given key exists in the given json object
| [in] | json | The json object to look into |
| [in] | key | The key to look for inside the json object |
| __JAFFAR_COMMON_INLINE__ const std::vector< T > jaffarCommon::json::getArray | ( | const object & | json, |
| const std::string & | key | ||
| ) |
Returns the array of the specified type stored in the given key of the given json object
| [in] | json | The json object to look into |
| [in] | key | The key to look for inside the json object |
| __JAFFAR_COMMON_INLINE__ const bool jaffarCommon::json::getBoolean | ( | const object & | json, |
| const std::string & | key | ||
| ) |
Returns the boolean stored the given key of the given json object
| [in] | json | The json object to look into |
| [in] | key | The key to look for inside the json object |
| __JAFFAR_COMMON_INLINE__ const T jaffarCommon::json::getNumber | ( | const object & | json, |
| const std::string & | key | ||
| ) |
Returns the number of the specified type stored the given key of the given json object
| [in] | json | The json object to look into |
| [in] | key | The key to look for inside the json object |
| __JAFFAR_COMMON_INLINE__ const object & jaffarCommon::json::getObject | ( | const object & | json, |
| const std::string & | key | ||
| ) |
Returns the object stored in the given key of the given json object
| [in] | json | The json object to look into |
| [in] | key | The key to look for inside the json object |
| __JAFFAR_COMMON_INLINE__ const std::string jaffarCommon::json::getString | ( | const object & | json, |
| const std::string & | key | ||
| ) |
Returns the string stored in the given key of the given json object
| [in] | json | The json object to look into |
| [in] | key | The key to look for inside the json object |
| __JAFFAR_COMMON_INLINE__ const std::vector< T > jaffarCommon::json::popArray | ( | object & | json, |
| const std::string & | key | ||
| ) |
Like getArray(), but erases the key from the json object. See popString().
| [in,out] | json | The json object to read from and erase the key from |
| [in] | key | The key to read and erase |
| __JAFFAR_COMMON_INLINE__ const bool jaffarCommon::json::popBoolean | ( | object & | json, |
| const std::string & | key | ||
| ) |
Like getBoolean(), but erases the key from the json object. See popString().
| [in,out] | json | The json object to read from and erase the key from |
| [in] | key | The key to read and erase |
| __JAFFAR_COMMON_INLINE__ const T jaffarCommon::json::popNumber | ( | object & | json, |
| const std::string & | key | ||
| ) |
Like getNumber(), but erases the key from the json object. See popString().
| [in,out] | json | The json object to read from and erase the key from |
| [in] | key | The key to read and erase |
| __JAFFAR_COMMON_INLINE__ const object jaffarCommon::json::popObject | ( | object & | json, |
| const std::string & | key | ||
| ) |
Like getObject(), but returns a copy and erases the key from the parent. See popString().
| [in,out] | json | The json object to read from and erase the key from |
| [in] | key | The key to read and erase |
| __JAFFAR_COMMON_INLINE__ const std::string jaffarCommon::json::popString | ( | object & | json, |
| const std::string & | key | ||
| ) |
Consuming variant of getString(): reads the string value, then erases the key from the (mutable) json object. After a parser has read every key it recognizes with the pop*() functions, any keys left in the object are unrecognized – pass the object to checkEmpty().
| [in,out] | json | The json object to read from and erase the key from |
| [in] | key | The key to read and erase |