Monado OpenXR Runtime
xrt::auxiliary::util::json::JSONNode Class Reference

A JSONNode wraps a cJSON object and presents useful functions for accessing the different properties of the json structure like operator[], isType() and asType() methods. More...

#include <util/u_json.hpp>

Public Member Functions

 JSONNode (cJSON *cjson, bool is_owner, const JSONNode::Ptr &parent)
 This is public so that make_shared works; do not use outside of this file. More...
 
 JSONNode (cJSON *cjson)
 Wrap cJSON object for easy manipulation, does not take ownership. More...
 
 JSONNode ()
 Makes a null object; isInvalid() on it returns true. More...
 
 JSONNode (const string &content)
 Receives a json string and constructs a wrapped cJSON object out of it. More...
 
 JSONNode (JSONNode &&)=default
 
 JSONNode (const JSONNode &node)
 
JSONNodeoperator= (JSONNode &&)=default
 
JSONNodeoperator= (JSONNode rhs)
 
bool saveToFile (const string &filepath) const
 
JSONNode operator[] (const string &key) const
 
JSONNode operator[] (int i) const
 
bool isObject () const
 
bool isArray () const
 
bool isString () const
 
bool isNumber () const
 
bool isInt () const
 
bool isDouble () const
 
bool isNull () const
 
bool isBool () const
 
bool isInvalid () const
 
bool isValid () const
 
bool canBool () const
 
map< string, JSONNodeasObject (const map< string, JSONNode > &otherwise=map< string, JSONNode >()) const
 
vector< JSONNodeasArray (const vector< JSONNode > &otherwise=vector< JSONNode >()) const
 
string asString (const string &otherwise="") const
 
int asInt (int otherwise=0) const
 
double asDouble (double otherwise=0.0) const
 
void * asNull (void *otherwise=nullptr) const
 
bool asBool (bool otherwise=false) const
 
bool hasKey (const string &key) const
 
string toString (bool show_field=true) const
 
string getName () const
 
cJSON * getCJSON ()
 

Static Public Member Functions

static JSONNode loadFromFile (const string &filepath)
 

Friends

class JSONBuilder
 
void swap (JSONNode &lhs, JSONNode &rhs) noexcept
 

Detailed Description

A JSONNode wraps a cJSON object and presents useful functions for accessing the different properties of the json structure like operator[], isType() and asType() methods.

The main ways a user can build a JSONNode is from a json string, from a json file with loadFromFile or with the JSONBuilder.

Constructor & Destructor Documentation

◆ JSONNode() [1/4]

xrt::auxiliary::util::json::JSONNode::JSONNode ( cJSON *  cjson,
bool  is_owner,
const JSONNode::Ptr &  parent 
)
inline

This is public so that make_shared works; do not use outside of this file.

◆ JSONNode() [2/4]

xrt::auxiliary::util::json::JSONNode::JSONNode ( cJSON *  cjson)
inline

Wrap cJSON object for easy manipulation, does not take ownership.

◆ JSONNode() [3/4]

xrt::auxiliary::util::json::JSONNode::JSONNode ( )
inline

Makes a null object; isInvalid() on it returns true.

◆ JSONNode() [4/4]

xrt::auxiliary::util::json::JSONNode::JSONNode ( const string &  content)
inline

Receives a json string and constructs a wrapped cJSON object out of it.


The documentation for this class was generated from the following file: