FaceModel
 All Classes Namespaces Functions Variables Enumerations Enumerator Pages
Public Types | Public Member Functions | List of all members
iyf::JsonJig Class Reference

utility class to help managing typical operations on json files. (loading, manipulating, writing) More...

#include <JsonJig.h>

Public Types

enum  Mode { WRITE, READ }
 this enum helps to determine the performed operation wheter the file is going to ber read or written More...
 
enum  Format { COMPACT, PRETTY }
 enumeration that defines the format the json is going to be written, either if it's minified/compact and request volumn friends or pretty and easily readable for humans More...
 

Public Member Functions

 JsonJig ()
 constructs a plain object ready to have values added
 
 JsonJig (const char *path)
 initially reads the json files contents from the provided path and creates a iyf::JsonJig object for manipulation of this json More...
 
 ~JsonJig ()
 properly cleans up
 
bool readFromFile (const char *path)
 reads a jsonfiles contents More...
 
bool readFromString (const std::string &json)
 creates a iyf::JsonJig file from an input string instead from a file read from disk More...
 
bool writeToFile (const char *path)
 writes the currently stored json structure to a file More...
 
bool writeToFile (const char *path, Format format)
 write to file and specify the format PRETTY, COMPACT it is going to be written in More...
 
Json::ValuegetRoot ()
 returns the root node of the json structure currently stored More...
 
Json::ValuegetValue (const char *path)
 traverses the json and trys to find the Json::Value at the specified path More...
 
Json::ValuegetValue (const char *path, Json::Value &startRef)
 traverses down a json structure from a certain start point onwards More...
 
void setValue (const char *path, Json::Value &val)
 stets a json Value at a certain position More...
 

Detailed Description

utility class to help managing typical operations on json files. (loading, manipulating, writing)

this class is a convenience wrapper around JsonCpp to help setting values at a certain path to take the hastle of manually stepping down the json hierarchy.

Member Enumeration Documentation

enumeration that defines the format the json is going to be written, either if it's minified/compact and request volumn friends or pretty and easily readable for humans

Enumerator
COMPACT 

print the json nicely compact for transmission

PRETTY 

print the json pretty and human readable

this enum helps to determine the performed operation wheter the file is going to ber read or written

Enumerator
WRITE 

the file processed by iyf::JsonJig is going to be written

READ 

the file processed by iyf::JsonJig is going to be read

Constructor & Destructor Documentation

JsonJig::JsonJig ( const char *  path)

initially reads the json files contents from the provided path and creates a iyf::JsonJig object for manipulation of this json

Parameters
constchar* path the path to read the json file from

Member Function Documentation

Json::Value & JsonJig::getRoot ( )

returns the root node of the json structure currently stored

Returns
the root node of the json structure
Json::Value & JsonJig::getValue ( const char *  path)

traverses the json and trys to find the Json::Value at the specified path

Parameters
constchar* path to the Json::Value in question
Returns
the Json::Value if found or the nullValue otherwise
Json::Value & JsonJig::getValue ( const char *  path,
Json::Value startRef 
)

traverses down a json structure from a certain start point onwards

Parameters
constchar* path to the Json::Value in question
Json::Value&startRef the node to start traversal from
Returns
the Json::Value if found or the nullValue otherwise
bool JsonJig::readFromFile ( const char *  path)

reads a jsonfiles contents

Parameters
constchar* path the path to read the json file from
Returns
false if the file could not be read, true otherwise (iyf::JsonJig object is ready to manipulate json)
bool JsonJig::readFromString ( const std::string &  json)

creates a iyf::JsonJig file from an input string instead from a file read from disk

Parameters
conststd::string &json the json string to be converted into a JsonCpp object tree
Returns
true if the json was parsed successfully, false if the json was malformed
void JsonJig::setValue ( const char *  path,
Json::Value val 
)

stets a json Value at a certain position

Parameters
constchar* path to the destination of the value
Json::Value&val to be set at the position path points to
bool JsonJig::writeToFile ( const char *  path)

writes the currently stored json structure to a file

Parameters
constchar* path the json is going to be saved to
Returns
true if the file was written successfully, false otherwise
bool JsonJig::writeToFile ( const char *  path,
JsonJig::Format  format 
)

write to file and specify the format PRETTY, COMPACT it is going to be written in

Parameters
constchar* path the json is going to be saved to
Formatformat the file is going to be saved in (PRETTY/COMPACT)
Returns
true if the file was written successfully, false otherwise

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