You.i Engine
CYIRapidJSONUtility Class Reference

Detailed Description

A front-end utility class aimed to simplify the use of RapidJSON tools.

#include <utility/YiRapidJSONUtility.h>

Public Member Functions

virtual ~CYIRapidJSONUtility ()=default
 

Static Public Member Functions

static CYIString TypeToString (yi::rapidjson::Type type)
 
static std::unique_ptr< yi::rapidjson::Document > CreateDocumentFromString (const CYIString &rJsonString, CYIParsingError &rParsingError)
 
static yi::rapidjson::Document CreateMoveableDocumentFromString (const CYIString &rJsonString, CYIParsingError &rParsingError)
 
static std::unique_ptr< yi::rapidjson::Document > CreateDocumentFromFile (const CYIString &rFilePath, CYIParsingError &rParsingError)
 
static yi::rapidjson::Document CreateMoveableDocumentFromFile (const CYIString &rFilePath, CYIParsingError &rParsingError)
 
static CYIString CreateStringFromDocument (const yi::rapidjson::Document &rDocument)
 
template<typename Encoding , typename Allocator >
static CYIString CreateStringFromValue (const yi::rapidjson::GenericValue< Encoding, Allocator > &rGenericValue)
 
static bool GetBooleanField (const yi::rapidjson::Value *pValue, const char *pFieldName, bool *pFieldData, CYIParsingError &rParsingError)
 
static bool GetIntegerField (const yi::rapidjson::Value *pValue, const char *pFieldName, int32_t *pFieldData, CYIParsingError &rParsingError)
 
static bool GetLongField (const yi::rapidjson::Value *pValue, const char *pFieldName, int64_t *pFieldData, CYIParsingError &rParsingError)
 
static bool GetUnsignedLongField (const yi::rapidjson::Value *pValue, const char *pFieldName, uint64_t *pFieldData, CYIParsingError &rParsingError)
 
static bool GetStringField (const yi::rapidjson::Value *pValue, const char *pFieldName, CYIString &rFieldData, CYIParsingError &rParsingError)
 
static bool GetFloatField (const yi::rapidjson::Value *pValue, const char *pFieldName, float *pFieldData, CYIParsingError &rParsingError)
 
static bool GetDateField (const yi::rapidjson::Value *pValue, const char *pFieldName, CYIDateTime &rFieldData, CYIParsingError &rParsingError)
 
static bool IsNullField (const yi::rapidjson::Value *pValue, const char *pFieldName, bool *pFieldIsNull, CYIParsingError &rParsingError)
 
static bool AddBooleanField (yi::rapidjson::Document *pDocument, const CYIString &rFieldName, bool value)
 
static bool AddIntegerField (yi::rapidjson::Document *pDocument, const CYIString &rFieldName, int32_t value)
 
static bool AddLongField (yi::rapidjson::Document *pDocument, const CYIString &rFieldName, int64_t value)
 
static bool AddUnsignedLongField (yi::rapidjson::Document *pDocument, const CYIString &rField, uint64_t value)
 
static bool AddFloatField (yi::rapidjson::Document *pDocument, const CYIString &rFieldName, float value)
 
static bool AddObjectField (yi::rapidjson::Document *pDocument, const CYIString &rFieldName, yi::rapidjson::Value &rValue)
 
static bool AddStringField (yi::rapidjson::Document *pDocument, const CYIString &rFieldName, const CYIString &rValue)
 

Constructor & Destructor Documentation

◆ ~CYIRapidJSONUtility()

virtual CYIRapidJSONUtility::~CYIRapidJSONUtility ( )
virtualdefault

Member Function Documentation

◆ AddBooleanField()

static bool CYIRapidJSONUtility::AddBooleanField ( yi::rapidjson::Document *  pDocument,
const CYIString rFieldName,
bool  value 
)
static

Adds a new boolean field, value, to the RapidJSON pDocument for the given rFieldName.

◆ AddFloatField()

static bool CYIRapidJSONUtility::AddFloatField ( yi::rapidjson::Document *  pDocument,
const CYIString rFieldName,
float  value 
)
static

Adds a new float field, value, to the RapidJSON pDocument for the given rFieldName.

◆ AddIntegerField()

static bool CYIRapidJSONUtility::AddIntegerField ( yi::rapidjson::Document *  pDocument,
const CYIString rFieldName,
int32_t  value 
)
static

Adds a new integer field, value, to the RapidJSON pDocument for the given rFieldName.

◆ AddLongField()

static bool CYIRapidJSONUtility::AddLongField ( yi::rapidjson::Document *  pDocument,
const CYIString rFieldName,
int64_t  value 
)
static

Adds a new long field, value, to the RapidJSON pDocument for the given rFieldName.

◆ AddObjectField()

static bool CYIRapidJSONUtility::AddObjectField ( yi::rapidjson::Document *  pDocument,
const CYIString rFieldName,
yi::rapidjson::Value &  rValue 
)
static

Adds a new RapidJSon object field, rValue, to the RapidJSON pDocument for the given rFieldName.

◆ AddStringField()

static bool CYIRapidJSONUtility::AddStringField ( yi::rapidjson::Document *  pDocument,
const CYIString rFieldName,
const CYIString rValue 
)
static

Adds a new CYIString field, rValue, to the RapidJSON pDocument for the given rFieldName.

◆ AddUnsignedLongField()

static bool CYIRapidJSONUtility::AddUnsignedLongField ( yi::rapidjson::Document *  pDocument,
const CYIString rField,
uint64_t  value 
)
static

Adds a new unsigned long field, value, to the RapidJSON pDocument for the given rFieldName.

◆ CreateDocumentFromFile()

static std::unique_ptr<yi::rapidjson::Document> CYIRapidJSONUtility::CreateDocumentFromFile ( const CYIString rFilePath,
CYIParsingError rParsingError 
)
static

Creates a new RapidJSON Document object containing the parsed data from the file at the given rFilePath. Parsing errors will be returned in rParsingError.

Warning
The developer is responsible for cleaning up the returned document.

◆ CreateDocumentFromString()

static std::unique_ptr<yi::rapidjson::Document> CYIRapidJSONUtility::CreateDocumentFromString ( const CYIString rJsonString,
CYIParsingError rParsingError 
)
static

Creates a new RapidJSON Document object containing the parsed data from the given rJsonString. Parsing errors will be returned in rParsingError.

Warning
The developer is responsible for cleaning up the returned document.
When assigning the result of this function only assign it to a variable of the type rapidjson::Document and not rapidjson::Value. Otherwise deleting the pointer to the rapidjson::Value will leak memory. Refer to the RapidJSON documentation http://rapidjson.org/classrapidjson_1_1_generic_document.html

◆ CreateMoveableDocumentFromFile()

static yi::rapidjson::Document CYIRapidJSONUtility::CreateMoveableDocumentFromFile ( const CYIString rFilePath,
CYIParsingError rParsingError 
)
static

Creates a RapidJSON Document containing the parsed data from the file at the given rFilePath. Parsing errors will be returned in rParsingError.

◆ CreateMoveableDocumentFromString()

static yi::rapidjson::Document CYIRapidJSONUtility::CreateMoveableDocumentFromString ( const CYIString rJsonString,
CYIParsingError rParsingError 
)
static

Creates a RapidJSON Document containing the parsed data from the given rJsonString. Parsing errors will be returned in rParsingError.

◆ CreateStringFromDocument()

static CYIString CYIRapidJSONUtility::CreateStringFromDocument ( const yi::rapidjson::Document &  rDocument)
static

Returns a CYIString representation of the RapidJSON Document.

◆ CreateStringFromValue()

template<typename Encoding , typename Allocator >
static CYIString CYIRapidJSONUtility::CreateStringFromValue ( const yi::rapidjson::GenericValue< Encoding, Allocator > &  rGenericValue)
static

Returns a CYIString representation of the RapidJSON GenericValue.

◆ GetBooleanField()

static bool CYIRapidJSONUtility::GetBooleanField ( const yi::rapidjson::Value *  pValue,
const char *  pFieldName,
bool *  pFieldData,
CYIParsingError rParsingError 
)
static

Retrieves pFieldData as a boolean given a RapidJSON pValue and a pFieldName. In addition to reading Boolean data type, Number values of 1 and 0 and String values of "1", "0", "true" and "false" are all successfully read. pFieldData is only modified if parsing is successful (and function returns true) Returns false on error with rParsingError populated with error information from the last parsing error. Json value 'null' also returns false.

◆ GetDateField()

static bool CYIRapidJSONUtility::GetDateField ( const yi::rapidjson::Value *  pValue,
const char *  pFieldName,
CYIDateTime rFieldData,
CYIParsingError rParsingError 
)
static

Retrieves pFieldData as a CYIDateTime given a RapidJSON pValue and a pFieldName. pFieldData is only modified if parsing is successful (and function returns true) Returns false on error with rParsingError populated with error information from the last parsing error. Json value 'null' also returns false.

Note
This function works with dates in the ISO 8601 format as well as epoch time in seconds.

◆ GetFloatField()

static bool CYIRapidJSONUtility::GetFloatField ( const yi::rapidjson::Value *  pValue,
const char *  pFieldName,
float *  pFieldData,
CYIParsingError rParsingError 
)
static

Retrieves pFieldData as a float given a RapidJSON pValue and a pFieldName. In addition to reading Number data type, also reads String values containing a numeric value. pFieldData is only modified if parsing is successful (and function returns true) Returns false on error with rParsingError populated with error information from the last parsing error. Json value 'null' also returns false.

◆ GetIntegerField()

static bool CYIRapidJSONUtility::GetIntegerField ( const yi::rapidjson::Value *  pValue,
const char *  pFieldName,
int32_t *  pFieldData,
CYIParsingError rParsingError 
)
static

Retrieves pFieldData as an integer given a RapidJSON pValue and a pFieldName. In addition to reading Number data type, also reads String values containing a numeric value. pFieldData is only modified if parsing is successful (and function returns true) Returns false on error with rParsingError populated with error information from the last parsing error. Json value 'null' also returns false.

◆ GetLongField()

static bool CYIRapidJSONUtility::GetLongField ( const yi::rapidjson::Value *  pValue,
const char *  pFieldName,
int64_t *  pFieldData,
CYIParsingError rParsingError 
)
static

Retrieves pFieldData as a long given a RapidJSON pValue and a pFieldName. In addition to reading Number data type, also reads String values containing a numeric value. pFieldData is only modified if parsing is successful (and function returns true) Returns false on error with rParsingError populated with error information from the last parsing error. Json value 'null' also returns false.

◆ GetStringField()

static bool CYIRapidJSONUtility::GetStringField ( const yi::rapidjson::Value *  pValue,
const char *  pFieldName,
CYIString rFieldData,
CYIParsingError rParsingError 
)
static

Retrieves pFieldData as a CYIString given a RapidJSON pValue and a pFieldName. pFieldData is only modified if parsing is successful (and function returns true) Returns false on error with rParsingError populated with error information from the last parsing error. Json value 'null' also returns false.

◆ GetUnsignedLongField()

static bool CYIRapidJSONUtility::GetUnsignedLongField ( const yi::rapidjson::Value *  pValue,
const char *  pFieldName,
uint64_t *  pFieldData,
CYIParsingError rParsingError 
)
static

Retrieves pFieldData as an unsigned long given a RapidJSON pValue and a pFieldName. In addition to reading Number data type, also reads String values containing a numeric value. pFieldData is only modified if parsing is successful (and function returns true) Returns false on error with rParsingError populated with error information from the last parsing error. Json value 'null' also returns false.

◆ IsNullField()

static bool CYIRapidJSONUtility::IsNullField ( const yi::rapidjson::Value *  pValue,
const char *  pFieldName,
bool *  pFieldIsNull,
CYIParsingError rParsingError 
)
static

Sets pFieldIsNull to true if the pFieldName contained within the RapidJSON pValue is null and false otherwise. Returns true when parsing the field succeeded and false otherwise. When false is returned rParsingError will be populated.

◆ TypeToString()

static CYIString CYIRapidJSONUtility::TypeToString ( yi::rapidjson::Type  type)
static

Returns a string representation of the RapidJSON value type.


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