Stochastic Loading Module
Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
utilities::JsonObject Class Reference

#include <json_object.h>

Public Member Functions

 JsonObject ()
 
virtual ~JsonObject ()
 
bool operator== (const JsonObject &json_value) const
 
bool operator!= (const JsonObject &json_value) const
 
template<typename Tparam >
bool add_value (const std::string &key, const Tparam &value)
 
template<typename Tparam >
Tparam get_value (const std::string &key) const
 
bool delete_key (const std::string &key)
 
bool write_to_file (const std::string &output_location) const
 
void clear ()
 
bool is_empty () const
 
unsigned int get_size () const
 
json get_library_json () const
 

Protected Member Functions

 JsonObject (json library_json)
 

Protected Attributes

json json_object_
 

Friends

std::ostream & operator<< (std::ostream &out, const utilities::JsonObject &json_object)
 

Detailed Description

Wrapper class for JSON implementation

Definition at line 16 of file json_object.h.

Constructor & Destructor Documentation

utilities::JsonObject::JsonObject ( )

Construct JSON wrapper

Definition at line 10 of file json_object.cc.

virtual utilities::JsonObject::~JsonObject ( )
inlinevirtual

Virtual destructor

Definition at line 31 of file json_object.h.

utilities::JsonObject::JsonObject ( json  library_json)
protected

Construct JsonObject from underlying library object

Parameters
[in]library_jsonLibrary JSON object

Definition at line 15 of file json_object.cc.

Member Function Documentation

template<typename Tparam >
bool utilities::JsonObject::add_value ( const std::string &  key,
const Tparam &  value 
)

Add value to key in JSON object. If key doesn't exist, it will automatically added.

Template Parameters
TparamTemplate parameter for value
Parameters
[in]keyKey to add values to
[in]valueValue to add to key
Returns
Returns true if successful, false otherwise
void utilities::JsonObject::clear ( )

Clear JSON object contents

Definition at line 64 of file json_object.cc.

bool utilities::JsonObject::delete_key ( const std::string &  key)

Delete key from JSON object

Parameters
[in]keyKey to remove from JSON object
Returns
Returns true if successful, false otherwise

Definition at line 21 of file json_object.cc.

json utilities::JsonObject::get_library_json ( ) const
inline

Get underlying JSON library object

Returns
Copy of interal JSON implementation

Definition at line 106 of file json_object.h.

unsigned int utilities::JsonObject::get_size ( ) const

Get the number of keys in the JSON object

Returns
Number of keys in the JSON object

Definition at line 72 of file json_object.cc.

template<typename Tparam >
Tparam utilities::JsonObject::get_value ( const std::string &  key) const

Get the value associated with the input key

Template Parameters
TparamTemplate parameter value
Parameters
[in]keyKey at which to get value
Returns
Returns value at input key. Throws exception if key is not present.
bool utilities::JsonObject::is_empty ( ) const

Check if JSON object is empty

Returns
Returns true if object is empty, false otherwise

Definition at line 68 of file json_object.cc.

bool utilities::JsonObject::operator!= ( const JsonObject json_value) const
inline

Compares input JsonObject to this JsonObject for inequality

Parameters
[in]json_valueJsonObject to compare this JsonObject to
Returns
Returns true if JsonObjects are not equal, false otherwise

Definition at line 47 of file json_object.h.

bool utilities::JsonObject::operator== ( const JsonObject json_value) const
inline

Compares input JsonObject to this JsonObject for equality

Parameters
[in]json_valueJsonObject to compare this JsonObject to
Returns
Returns true if JsonObjects are equal, false otherwise

Definition at line 38 of file json_object.h.

bool utilities::JsonObject::write_to_file ( const std::string &  output_location) const

Write prettified JSON object to file

Parameters
[in]output_locationLocation to write JSON object to
Returns
Returns true if successful, false otherwise

Definition at line 36 of file json_object.cc.

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  out,
const utilities::JsonObject json_object 
)
friend

Friend operator for output stream insertion

Overload for output stream insertion operator

Parameters
[in]outOutput stream to insert JSON object into
[in]json_objectJSON object to insert into output stream
Returns
Reference to output stream that JSON object has been inserted into

Definition at line 126 of file json_object.h.

Member Data Documentation

json utilities::JsonObject::json_object_
protected

JSON object for this class

Definition at line 117 of file json_object.h.


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