Conscience Core
Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
conscience_utils::JSON::CscJsonObjectReader Class Reference

#include <json.h>

Inheritance diagram for conscience_utils::JSON::CscJsonObjectReader:
conscience_utils::JSON::CscJsonObject conscience_utils::JSON::CscJsonParser

Public Member Functions

vector< string > getKeys ()
 
bool hasKey (const string &key)
 
bool isArray (const string &key)
 
unsigned getArrayLength (const string &arrayKey)
 
bool isNull (const string &key)
 
string getRequiredStringValue (const string &key, bool allowEmpty=false)
 
optional< int > getIntValue (const string &key)
 
int getRequiredIntValue (const string &key)
 
optional< unsigned long long > getUnsignedLongValue (const string &key)
 
unsigned long long getRequiredUnsignedLongValue (const string &key)
 
optional< bool > getBooleanValue (const string &key)
 
bool getRequiredBooleanValue (const string &key)
 
optional< double > getDoubleValue (const string &key)
 
double getRequiredDoubleValue (const string &key)
 
optional< float > getFloatValue (const string &key)
 
float getRequiredFloatValue (const string &key)
 
optional< string > getStringValue (const string &key)
 
CscJsonObjectReader getRequiredObjectValue (const string &key)
 
optional< CscJsonObjectReadergetObjectValue (const string &key)
 
CscJsonObjectReadergetRequiredObjectPtrValue (const string &key)
 
optional< CscJsonObjectReader * > getObjectPtrValue (const string &key)
 
ptr< CscJsonObjectReadergetRequiredObjectSharedPtrValue (const string &key)
 
optional< ptr< CscJsonObjectReader > > getObjectSharedPtrValue (const string &key)
 
map< string, optional< any > > getRequiredObjectValueAsMap (const string &key)
 
map< string, string > getRequiredObjectValueAsMapOfStrings (const string &key)
 
optional< map< string, optional< any > > > getObjectValueAsMap (const string &key)
 
optional< any > getAnyValue (string key)
 
template<class T >
vector< T > getRequiredArrayValue (const string &key)
 
template<class T >
optional< vector< T > > getArrayValue (const string &key)
 
template<class T >
optional< T > getArrayItemValue (const string &arrayKey, size_t index)
 
template<class T >
getRequiredArrayItemValue (const string &arrayKey, size_t index)
 
template<class T >
vector< T > asArrayValue ()
 
 CscJsonObjectReader (ptr< yyjson_doc > yyjsonDoc, yyjson_val *yyjsonValue=nullptr, bool doNotReleaseYyjsonObjects=false)
 
 CscJsonObjectReader (const fs::path filePath)
 
 CscJsonObjectReader (const string &jsonContent)
 
virtual ~CscJsonObjectReader ()
 
string toString ()
 
string toJsonString (bool prettyPrint=false)
 
CscJsonObjecttoMutable (yyjson_mut_doc *parentDoc=nullptr)
 
yyjson_val * getLowLevelParser ()
 

Static Public Member Functions

static vector< CscJsonObject * > toMutableList (const vector< ptr< CscJsonObjectReader >> values)
 

Protected Member Functions

virtual ptr< yyjson_doc > getYyjsonDoc ()
 
virtual yyjson_val * getYyjsonValue ()
 
yyjson_val * getValueByPropertyPath (const string &propertyPath)
 

Static Protected Member Functions

static ptr< yyjson_doc > createYyjsonSharedPtr (yyjson_doc *doc)
 
static yyjson_doc * parseFromFile (const fs::path filePath)
 
static yyjson_doc * parseFromString (const string &jsonString)
 

Protected Attributes

ptr< yyjson_doc > yyjsonDoc = nullptr
 
yyjson_val * yyjsonValue = nullptr
 

Detailed Description

Note
this class is NOT thread safe

Constructor & Destructor Documentation

◆ CscJsonObjectReader() [1/3]

conscience_utils::JSON::CscJsonObjectReader::CscJsonObjectReader ( ptr< yyjson_doc >  yyjsonDoc,
yyjson_val *  yyjsonValue = nullptr,
bool  doNotReleaseYyjsonObjects = false 
)
Parameters
yyjsonDoccurrently read doc, yyjson type. nullptr can be passed by subclass for editing purpose for instance
yyjsonValuethe value connected to this reader object. The reader will read from this value.

◆ CscJsonObjectReader() [2/3]

conscience_utils::JSON::CscJsonObjectReader::CscJsonObjectReader ( const fs::path  filePath)

◆ CscJsonObjectReader() [3/3]

conscience_utils::JSON::CscJsonObjectReader::CscJsonObjectReader ( const string &  jsonContent)

◆ ~CscJsonObjectReader()

conscience_utils::JSON::CscJsonObjectReader::~CscJsonObjectReader ( )
virtual

Member Function Documentation

◆ asArrayValue()

template<class T >
vector<T> conscience_utils::JSON::CscJsonObjectReader::asArrayValue ( )
inline

valid types for T: double, int, uint, string , CscJsonObjectReader* or ptr<CscJsonObjectReader>

◆ createYyjsonSharedPtr()

ptr< yyjson_doc > conscience_utils::JSON::CscJsonObjectReader::createYyjsonSharedPtr ( yyjson_doc *  doc)
staticprotected

◆ getAnyValue()

optional< any > conscience_utils::JSON::CscJsonObjectReader::getAnyValue ( string  key)

gets optional any value

◆ getArrayItemValue()

template<class T >
optional<T> conscience_utils::JSON::CscJsonObjectReader::getArrayItemValue ( const string &  arrayKey,
size_t  index 
)
inline

valid types for T: double, int, uint, string , CscJsonObjectReader* or ptr<CscJsonObjectReader>

◆ getArrayLength()

unsigned conscience_utils::JSON::CscJsonObjectReader::getArrayLength ( const string &  arrayKey)

returns length if array property exists at property path (can be separated by '.' to access nested props), otherwise throws MissingRequiredPropertyException

◆ getArrayValue()

template<class T >
optional<vector<T> > conscience_utils::JSON::CscJsonObjectReader::getArrayValue ( const string &  key)
inline

valid types for T: double, int, uint, string , CscJsonObjectReader* or ptr<CscJsonObjectReader>

◆ getBooleanValue()

optional< bool > conscience_utils::JSON::CscJsonObjectReader::getBooleanValue ( const string &  key)

◆ getDoubleValue()

optional< double > conscience_utils::JSON::CscJsonObjectReader::getDoubleValue ( const string &  key)

gets optional double value

◆ getFloatValue()

optional< float > conscience_utils::JSON::CscJsonObjectReader::getFloatValue ( const string &  key)

gets optional double value

◆ getIntValue()

optional< int > conscience_utils::JSON::CscJsonObjectReader::getIntValue ( const string &  key)

gets optional int value

◆ getKeys()

vector< string > conscience_utils::JSON::CscJsonObjectReader::getKeys ( )

◆ getLowLevelParser()

yyjson_val * conscience_utils::JSON::CscJsonObjectReader::getLowLevelParser ( )

sometimes it can be useful to work with raw values to avoid conversions

◆ getObjectPtrValue()

optional< CscJsonObjectReader * > conscience_utils::JSON::CscJsonObjectReader::getObjectPtrValue ( const string &  key)

gets optional object value, you need to delete it

◆ getObjectSharedPtrValue()

optional< ptr< CscJsonObjectReader > > conscience_utils::JSON::CscJsonObjectReader::getObjectSharedPtrValue ( const string &  key)

gets optional object value

◆ getObjectValue()

optional< CscJsonObjectReader > conscience_utils::JSON::CscJsonObjectReader::getObjectValue ( const string &  key)

gets optional object value

◆ getObjectValueAsMap()

optional< map< string, optional< any > > > conscience_utils::JSON::CscJsonObjectReader::getObjectValueAsMap ( const string &  key)

gets optional object value as map

◆ getRequiredArrayItemValue()

template<class T >
T conscience_utils::JSON::CscJsonObjectReader::getRequiredArrayItemValue ( const string &  arrayKey,
size_t  index 
)
inline

valid types for T: double, int, uint, string , CscJsonObjectReader* or ptr<CscJsonObjectReader>

◆ getRequiredArrayValue()

template<class T >
vector<T> conscience_utils::JSON::CscJsonObjectReader::getRequiredArrayValue ( const string &  key)
inline

valid types for T: double, int, uint, string , CscJsonObjectReader* or ptr<CscJsonObjectReader>

◆ getRequiredBooleanValue()

bool conscience_utils::JSON::CscJsonObjectReader::getRequiredBooleanValue ( const string &  key)

◆ getRequiredDoubleValue()

double conscience_utils::JSON::CscJsonObjectReader::getRequiredDoubleValue ( const string &  key)

gets double value, or throw error

◆ getRequiredFloatValue()

float conscience_utils::JSON::CscJsonObjectReader::getRequiredFloatValue ( const string &  key)

gets double value, or throw error

◆ getRequiredIntValue()

int conscience_utils::JSON::CscJsonObjectReader::getRequiredIntValue ( const string &  key)

gets int value, or throw error

◆ getRequiredObjectPtrValue()

CscJsonObjectReader * conscience_utils::JSON::CscJsonObjectReader::getRequiredObjectPtrValue ( const string &  key)

gets object value, or throw error, you need to delete it

◆ getRequiredObjectSharedPtrValue()

ptr< CscJsonObjectReader > conscience_utils::JSON::CscJsonObjectReader::getRequiredObjectSharedPtrValue ( const string &  key)

gets object value, or throw error

◆ getRequiredObjectValue()

CscJsonObjectReader conscience_utils::JSON::CscJsonObjectReader::getRequiredObjectValue ( const string &  key)

gets object value, or throw error

◆ getRequiredObjectValueAsMap()

map< string, optional< any > > conscience_utils::JSON::CscJsonObjectReader::getRequiredObjectValueAsMap ( const string &  key)

gets object value as map, or throws error

◆ getRequiredObjectValueAsMapOfStrings()

map< string, string > conscience_utils::JSON::CscJsonObjectReader::getRequiredObjectValueAsMapOfStrings ( const string &  key)

gets object value as map of strings, or throws error

Note
if map values are not strings inside json, it will throw an error

◆ getRequiredStringValue()

string conscience_utils::JSON::CscJsonObjectReader::getRequiredStringValue ( const string &  key,
bool  allowEmpty = false 
)

gets string value, or throw error

◆ getRequiredUnsignedLongValue()

unsigned long long conscience_utils::JSON::CscJsonObjectReader::getRequiredUnsignedLongValue ( const string &  key)

gets unsigned long long value, or throw error

◆ getStringValue()

optional< string > conscience_utils::JSON::CscJsonObjectReader::getStringValue ( const string &  key)

gets optional string value

◆ getUnsignedLongValue()

optional< unsigned long long > conscience_utils::JSON::CscJsonObjectReader::getUnsignedLongValue ( const string &  key)

gets optional unsigned long long value

◆ getValueByPropertyPath()

yyjson_val * conscience_utils::JSON::CscJsonObjectReader::getValueByPropertyPath ( const string &  propertyPath)
protected

◆ getYyjsonDoc()

ptr< yyjson_doc > conscience_utils::JSON::CscJsonObjectReader::getYyjsonDoc ( )
protectedvirtual

◆ getYyjsonValue()

yyjson_val * conscience_utils::JSON::CscJsonObjectReader::getYyjsonValue ( )
protectedvirtual

◆ hasKey()

bool conscience_utils::JSON::CscJsonObjectReader::hasKey ( const string &  key)

returns true if property exists from property path (can be separated by '.' to access nested props)

◆ isArray()

bool conscience_utils::JSON::CscJsonObjectReader::isArray ( const string &  key)

returns true if property exists at property path (can be separated by '.' to access nested props) and is an array

◆ isNull()

bool conscience_utils::JSON::CscJsonObjectReader::isNull ( const string &  key)

returns true if property value at given key is either absent, null, or unknown type

◆ parseFromFile()

yyjson_doc * conscience_utils::JSON::CscJsonObjectReader::parseFromFile ( const fs::path  filePath)
staticprotected

◆ parseFromString()

yyjson_doc * conscience_utils::JSON::CscJsonObjectReader::parseFromString ( const string &  jsonString)
staticprotected

◆ toJsonString()

string conscience_utils::JSON::CscJsonObjectReader::toJsonString ( bool  prettyPrint = false)

◆ toMutable()

CscJsonObject * conscience_utils::JSON::CscJsonObjectReader::toMutable ( yyjson_mut_doc *  parentDoc = nullptr)
Parameters
parentDocimportant if your value must be attached to another json object root. If null -> a new detached json doc will be created

◆ toMutableList()

vector< CscJsonObject * > conscience_utils::JSON::CscJsonObjectReader::toMutableList ( const vector< ptr< CscJsonObjectReader >>  values)
static

◆ toString()

string conscience_utils::JSON::CscJsonObjectReader::toString ( )

Member Data Documentation

◆ yyjsonDoc

ptr<yyjson_doc> conscience_utils::JSON::CscJsonObjectReader::yyjsonDoc = nullptr
protected

◆ yyjsonValue

yyjson_val* conscience_utils::JSON::CscJsonObjectReader::yyjsonValue = nullptr
protected

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