DiFfRG
Loading...
Searching...
No Matches
DiFfRG::JSONValue Class Reference

A wrapper around the boost json value class. More...

#include <json.hh>

Public Member Functions

 JSONValue ()
 Construct an empty JSONValue object.
 
 JSONValue (const std::string filename)
 Construct a new JSONValue object from a json file.
 
 JSONValue (const json::value &v)
 Construct a new JSONValue object.
 
json::value & operator() ()
 The call operator gives access to the wrapped json value.
 
 operator json::value () const
 The call operator gives access to the wrapped json value.
 
bool operator== (const JSONValue &other) const
 Equality operator. Checks all values in the json object to be equal.
 
double get_double (const std::string &key) const
 Get the value of a key in the json object.
 
int get_int (const std::string &key) const
 Get the value of a key in the json object.
 
uint get_uint (const std::string &key) const
 Get the value of a key in the json object.
 
std::string get_string (const std::string &key) const
 Get the value of a key in the json object.
 
bool get_bool (const std::string &key) const
 Get the value of a key in the json object.
 
double get_double (const std::string &key, const double def) const
 Get the value of a key in the json object, with a default value.
 
int get_int (const std::string &key, const int def) const
 Get the value of a key in the json object, with a default value.
 
uint get_uint (const std::string &key, const uint def) const
 Get the value of a key in the json object, with a default value.
 
std::string get_string (const std::string &key, const std::string &def) const
 Get the value of a key in the json object, with a default value.
 
bool get_bool (const std::string &key, const bool def) const
 Get the value of a key in the json object, with a default value.
 
void set_double (const std::string &key, double value)
 Set the value of a key in the json object.
 
void set_int (const std::string &key, int value)
 Set the value of a key in the json object.
 
void set_uint (const std::string &key, uint value)
 Set the value of a key in the json object.
 
void set_string (const std::string &key, const std::string &value)
 Set the value of a key in the json object.
 
void set_bool (const std::string &key, bool value)
 Set the value of a key in the json object.
 
void print (std::ostream &os) const
 Pretty-print the json value to a stream.
 

Private Member Functions

void pretty_print (std::ostream &os, json::value const &v, std::string *indent=nullptr) const
 

Private Attributes

json::value value
 

Detailed Description

A wrapper around the boost json value class.

This class allows to easily access and modify the values stored in a json object.

Constructor & Destructor Documentation

◆ JSONValue() [1/3]

DiFfRG::JSONValue::JSONValue ( )

Construct an empty JSONValue object.

◆ JSONValue() [2/3]

DiFfRG::JSONValue::JSONValue ( const std::string filename)

Construct a new JSONValue object from a json file.

Parameters
filenameThe name of the file to read.

◆ JSONValue() [3/3]

DiFfRG::JSONValue::JSONValue ( const json::value & v)

Construct a new JSONValue object.

Parameters
vThe json value to wrap.

Member Function Documentation

◆ get_bool() [1/2]

bool DiFfRG::JSONValue::get_bool ( const std::string & key) const

Get the value of a key in the json object.

Parameters
keyThe key to get the value for. Format: "/category/subcategory/.../key".
Returns
bool The value.

◆ get_bool() [2/2]

bool DiFfRG::JSONValue::get_bool ( const std::string & key,
const bool def ) const

Get the value of a key in the json object, with a default value.

Parameters
keyThe key to get the value for. Format: "/category/subcategory/.../key".
defThe default value to return if the key is not found.
Returns
bool The value.

◆ get_double() [1/2]

double DiFfRG::JSONValue::get_double ( const std::string & key) const

Get the value of a key in the json object.

Parameters
keyThe key to get the value for. Format: "/category/subcategory/.../key".
Returns
double The value.

◆ get_double() [2/2]

double DiFfRG::JSONValue::get_double ( const std::string & key,
const double def ) const

Get the value of a key in the json object, with a default value.

Parameters
keyThe key to get the value for. Format: "/category/subcategory/.../key".
defThe default value to return if the key is not found.
Returns
double The value.

◆ get_int() [1/2]

int DiFfRG::JSONValue::get_int ( const std::string & key) const

Get the value of a key in the json object.

Parameters
keyThe key to get the value for. Format: "/category/subcategory/.../key".
Returns
int The value.

◆ get_int() [2/2]

int DiFfRG::JSONValue::get_int ( const std::string & key,
const int def ) const

Get the value of a key in the json object, with a default value.

Parameters
keyThe key to get the value for. Format: "/category/subcategory/.../key".
defThe default value to return if the key is not found.
Returns
int The value.

◆ get_string() [1/2]

std::string DiFfRG::JSONValue::get_string ( const std::string & key) const

Get the value of a key in the json object.

Parameters
keyThe key to get the value for. Format: "/category/subcategory/.../key".
Returns
std::string The value.

◆ get_string() [2/2]

std::string DiFfRG::JSONValue::get_string ( const std::string & key,
const std::string & def ) const

Get the value of a key in the json object, with a default value.

Parameters
keyThe key to get the value for. Format: "/category/subcategory/.../key".
defThe default value to return if the key is not found.
Returns
std::string The value.

◆ get_uint() [1/2]

uint DiFfRG::JSONValue::get_uint ( const std::string & key) const

Get the value of a key in the json object.

Parameters
keyThe key to get the value for. Format: "/category/subcategory/.../key".
Returns
uint The value.

◆ get_uint() [2/2]

uint DiFfRG::JSONValue::get_uint ( const std::string & key,
const uint def ) const

Get the value of a key in the json object, with a default value.

Parameters
keyThe key to get the value for. Format: "/category/subcategory/.../key".
defThe default value to return if the key is not found.
Returns
uint The value.

◆ operator json::value()

DiFfRG::JSONValue::operator json::value ( ) const

The call operator gives access to the wrapped json value.

◆ operator()()

json::value & DiFfRG::JSONValue::operator() ( )

The call operator gives access to the wrapped json value.

◆ operator==()

bool DiFfRG::JSONValue::operator== ( const JSONValue & other) const

Equality operator. Checks all values in the json object to be equal.

◆ pretty_print()

void DiFfRG::JSONValue::pretty_print ( std::ostream & os,
json::value const & v,
std::string * indent = nullptr ) const
private

◆ print()

void DiFfRG::JSONValue::print ( std::ostream & os) const

Pretty-print the json value to a stream.

◆ set_bool()

void DiFfRG::JSONValue::set_bool ( const std::string & key,
bool value )

Set the value of a key in the json object.

Parameters
keyThe key to set the value for. Format: "/category/subcategory/.../key".
valueThe value to set.

◆ set_double()

void DiFfRG::JSONValue::set_double ( const std::string & key,
double value )

Set the value of a key in the json object.

Parameters
keyThe key to set the value for. Format: "/category/subcategory/.../key".
valueThe value to set.

◆ set_int()

void DiFfRG::JSONValue::set_int ( const std::string & key,
int value )

Set the value of a key in the json object.

Parameters
keyThe key to set the value for. Format: "/category/subcategory/.../key".
valueThe value to set.

◆ set_string()

void DiFfRG::JSONValue::set_string ( const std::string & key,
const std::string & value )

Set the value of a key in the json object.

Parameters
keyThe key to set the value for. Format: "/category/subcategory/.../key".
valueThe value to set.

◆ set_uint()

void DiFfRG::JSONValue::set_uint ( const std::string & key,
uint value )

Set the value of a key in the json object.

Parameters
keyThe key to set the value for. Format: "/category/subcategory/.../key".
valueThe value to set.

Member Data Documentation

◆ value

json::value DiFfRG::JSONValue::value
private

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