IQRF Gateway Daemon
Functions
jutils Namespace Reference

Rapid Json values manipulation functions. More...

Functions

void parseJsonFile (const std::string &fname, rapidjson::Document &json)
 Parse file with Json content. More...
 
void parseIstream (std::istream &istr, rapidjson::Document &json)
 Parse stream with Json content. More...
 
void parseString (const std::string &str, rapidjson::Document &json)
 Parse string with Json content. More...
 
template<typename T >
void assertIs (const std::string &name, const rapidjson::Value &v)
 Assert json value holds T type. More...
 
template<>
void assertIs< std::string > (const std::string &name, const rapidjson::Value &v)
 Assert json value holds std::string type. More...
 
void assertIsObject (const std::string &name, const rapidjson::Value &v)
 Assert json value holds Json object. More...
 
void assertIsArray (const std::string &name, const rapidjson::Value &v)
 Assert json value holds Json array. More...
 
const rapidjson::Value::ConstMemberIterator getMember (const std::string &name, const rapidjson::Value &jsonValue)
 Get rapidjson member iterator. More...
 
template<typename T >
getMemberAs (const std::string &name, const rapidjson::Value &v)
 Get member with value of type T. More...
 
template<>
std::string getMemberAs< std::string > (const std::string &name, const rapidjson::Value &v)
 Get member with value of type std::string. More...
 
const rapidjson::Value & getMemberAsObject (const std::string &name, const rapidjson::Value &v)
 Get member with value of type Json object. More...
 
template<typename T >
std::vector< T > getMemberAsVector (const std::string &name, const rapidjson::Value &v)
 Get member with value std::vector of values of template type T. More...
 
template<>
std::vector< std::string > getMemberAsVector< std::string > (const std::string &name, const rapidjson::Value &v)
 Get member with value std::vector of values of type std::string. More...
 
template<typename T >
getPossibleMemberAs (const std::string &name, const rapidjson::Value &v, T defaultVal)
 Get possible member with value of type T. More...
 
template<>
std::string getPossibleMemberAs< std::string > (const std::string &name, const rapidjson::Value &v, std::string defaultVal)
 Get possible member with value of type std::string. More...
 
template<typename T >
std::vector< T > getPossibleMemberAsVector (const std::string &name, const rapidjson::Value &v, std::vector< T > defaultVal=std::vector< T >())
 Get possible member with std::vector of values of template type T. More...
 
template<typename T >
bool getMemberIfExistsAs (const std::string &name, const rapidjson::Value &v, T &member)
 Get member value if exists of template type T. More...
 
template<>
bool getMemberIfExistsAs< std::string > (const std::string &name, const rapidjson::Value &v, std::string &member)
 Get member value if exists of template type std::string. More...
 

Detailed Description

Rapid Json values manipulation functions.

Function Documentation

◆ assertIs()

template<typename T >
void jutils::assertIs ( const std::string &  name,
const rapidjson::Value &  v 
)
inline

Assert json value holds T type.

Parameters
[in]namejson item name (key)
[in]vjson value to be checked
Exceptions
std::logic_errorin case of assert failure

Json value named name is checked if its content is template type T else the exception std::logic_error is thrown

◆ assertIs< std::string >()

template<>
void jutils::assertIs< std::string > ( const std::string &  name,
const rapidjson::Value &  v 
)
inline

Assert json value holds std::string type.

Parameters
[in]namejson item name (key)
[in]vjson value to be checked
Exceptions
std::logic_errorin case of assert failure

Json value named name is checked if its content is std::string else the exception std::logic_error is thrown. It is template specialization for std::string.

◆ assertIsArray()

void jutils::assertIsArray ( const std::string &  name,
const rapidjson::Value &  v 
)
inline

Assert json value holds Json array.

Parameters
[in]namejson item name (key)
[in]vjson value to be checked
Exceptions
std::logic_errorin case of assert failure

Json value named name is checked if its content is Json object [...] else the exception std::logic_error is thrown

◆ assertIsObject()

void jutils::assertIsObject ( const std::string &  name,
const rapidjson::Value &  v 
)
inline

Assert json value holds Json object.

Parameters
[in]namejson item name (key)
[in]vjson value to be checked
Exceptions
std::logic_errorin case of assert failure

Json value named name is checked if its content is Json object {...} else the exception std::logic_error is thrown If not the exception std::logic_error is thrown

◆ getMember()

const rapidjson::Value::ConstMemberIterator jutils::getMember ( const std::string &  name,
const rapidjson::Value &  jsonValue 
)
inline

Get rapidjson member iterator.

Parameters
[in]namejson item name (key)
[in]vjson value to be checked
Returns
rapidjson member iterator
Exceptions
std::logic_errorin case the item doesn't exist

Tries to find Json value named name and if found returns its iterator else the exception std::logic_error is thrown

◆ getMemberAs()

template<typename T >
T jutils::getMemberAs ( const std::string &  name,
const rapidjson::Value &  v 
)
inline

Get member with value of type T.

Parameters
[in]namejson member
[in]vjson value to be examined for the member
Returns
value of type T
Exceptions
std::logic_errorin case the member doesn't exist or has different type

Tries to find Json member named name and if it is found and holds a value of the template type T it returns the value else the exception std::logic_error is thrown

◆ getMemberAs< std::string >()

template<>
std::string jutils::getMemberAs< std::string > ( const std::string &  name,
const rapidjson::Value &  v 
)
inline

Get member with value of type std::string.

Parameters
[in]namejson member
[in]vjson value to be examined for the member
Returns
value of type std::string
Exceptions
std::logic_errorin case the member doesn't exist or has different type

Tries to find Json member named name and if it is found and holds a value of the type std::string it returns the value else the exception std::logic_error is thrown It is template specialization for std::string

◆ getMemberAsObject()

const rapidjson::Value& jutils::getMemberAsObject ( const std::string &  name,
const rapidjson::Value &  v 
)
inline

Get member with value of type Json object.

Parameters
[in]namejson member
[in]vjson value to be examined for the member
Returns
value of type Json object
Exceptions
std::logic_errorin case the member doesn't exist or has different type

Tries to find Json member named name and if it is found and holds Json object {...} it returns the object else the exception std::logic_error is thrown

◆ getMemberAsVector()

template<typename T >
std::vector<T> jutils::getMemberAsVector ( const std::string &  name,
const rapidjson::Value &  v 
)
inline

Get member with value std::vector of values of template type T.

Parameters
[in]namejson member
[in]vjson value to be examined for the member
Returns
std::vector of values of type std::string
Exceptions
std::logic_errorin case the member doesn't exist or has different type

Tries to find Json member named name and if it is found and holds Json vector [...] of values of template type T it returns the vector else the exception std::logic_error is thrown.

◆ getMemberAsVector< std::string >()

template<>
std::vector<std::string> jutils::getMemberAsVector< std::string > ( const std::string &  name,
const rapidjson::Value &  v 
)
inline

Get member with value std::vector of values of type std::string.

Parameters
[in]namejson member
[in]vjson value to be examined for the member
Returns
std::vector of values of type std::string
Exceptions
std::logic_errorin case the member doesn't exist or has different type

Tries to find Json member named name and if it is found and holds Json vector [...] of values of types std::string it returns the vector else the exception std::logic_error is thrown. It is template specialization for std::string.

◆ getMemberIfExistsAs()

template<typename T >
bool jutils::getMemberIfExistsAs ( const std::string &  name,
const rapidjson::Value &  v,
T &  member 
)
inline

Get member value if exists of template type T.

Parameters
[in]namejson member
[in]vjson value to be examined for the member
[out]memberthe value to be set if the member is found
Returns
true if the member exists else false
Exceptions
std::logic_errorin case the member exists but has different type

Tries to find Json member named name and if it is found and holds a value of the type std::vector of values of type T it returns the vector else the default one. If the member exists but has different type the exception std::logic_error is thrown.

◆ getMemberIfExistsAs< std::string >()

template<>
bool jutils::getMemberIfExistsAs< std::string > ( const std::string &  name,
const rapidjson::Value &  v,
std::string &  member 
)
inline

Get member value if exists of template type std::string.

Parameters
[in]namejson member
[in]vjson value to be examined for the member
[out]memberthe value to be set if the member is found
Returns
true if the member exists else false
Exceptions
std::logic_errorin case the member exists but has different type

Tries to find Json member named name and if it is found and holds a value of the type std::vector of values of type std::string it returns the vector else the default one. If the member exists but has different type the exception std::logic_error is thrown. It is template specialization for std::string.

◆ getPossibleMemberAs()

template<typename T >
T jutils::getPossibleMemberAs ( const std::string &  name,
const rapidjson::Value &  v,
defaultVal 
)
inline

Get possible member with value of type T.

Parameters
[in]namejson member
[in]vjson value to be examined for the member
[in]defaultValthe value to be returned if the member is not found
Returns
value of type T
Exceptions
std::logic_errorin case the member has different type

Tries to find Json member named name and if it is found and holds a value of the template type T it returns the value else the default one. If the member exists but has different type the exception std::logic_error is thrown.

◆ getPossibleMemberAs< std::string >()

template<>
std::string jutils::getPossibleMemberAs< std::string > ( const std::string &  name,
const rapidjson::Value &  v,
std::string  defaultVal 
)
inline

Get possible member with value of type std::string.

Parameters
[in]namejson member
[in]vjson value to be examined for the member
[in]defaultValthe value to be returned if the member is not found
Returns
value of type std::string
Exceptions
std::logic_errorin case the member has different type

Tries to find Json member named name and if it is found and holds a value of the type std::string it returns the value else the default one. If the member exists but has different type the exception std::logic_error is thrown. It is template specialization for std::string.

◆ getPossibleMemberAsVector()

template<typename T >
std::vector<T> jutils::getPossibleMemberAsVector ( const std::string &  name,
const rapidjson::Value &  v,
std::vector< T >  defaultVal = std::vector<T>() 
)
inline

Get possible member with std::vector of values of template type T.

Parameters
[in]namejson member
[in]vjson value to be examined for the member
[in]defaultValthe value to be returned if the member is not found
Returns
value of type std::vector of values of template type T
Exceptions
std::logic_errorin case the member has different type

Tries to find Json member named name and if it is found and holds a value of the type std::vector of values of template type T it returns the vector else the default one. If the member exists but has different type the exception std::logic_error is thrown.

◆ parseIstream()

void jutils::parseIstream ( std::istream &  istr,
rapidjson::Document &  json 
)
inline

Parse stream with Json content.

Parameters
[in]istrstream object
[out]jsonvalue to hold parsed result
Exceptions
std::logic_errorin case of parse error

Stream content is taken and parsed to json value by rapidjson functions, In case of json syntax error the exception std::logic_error is thrown

◆ parseJsonFile()

void jutils::parseJsonFile ( const std::string &  fname,
rapidjson::Document &  json 
)
inline

Parse file with Json content.

Parameters
[in]fnamefile name
[out]jsonvalue to hold parsed result
Exceptions
std::logic_errorin case of parse error

File fname is parsed to json value by rapidjson functions, In case of file open error or json syntax error the exception std::logic_error is thrown

◆ parseString()

void jutils::parseString ( const std::string &  str,
rapidjson::Document &  json 
)
inline

Parse string with Json content.

Parameters
[in]strstring object
[out]jsonvalue to hold parsed result
Exceptions
std::logic_errorin case of parse error

String content is taken and parsed to json value by rapidjson functions, In case of json syntax error the exception std::logic_error is thrown