You.i Engine
YiRapidJSONUtility.h
Go to the documentation of this file.
1 // © You i Labs Inc. 2000-2020. All rights reserved.
2 #ifndef _YI_RAPID_JSON_UTILITY_H_
3 #define _YI_RAPID_JSON_UTILITY_H_
4 
6 #include "utility/YiString.h"
7 
8 #ifdef RAPIDJSON_NAMESPACE
9 # error Including YiRapidJSONUtility.h when RAPIDJSON_NAMESPACE has already been defined. To use these utilities first un-define RAPIDJSON_NAMESPACE.
10 #endif
11 #define RAPIDJSON_NAMESPACE yi::rapidjson
12 
13 #ifdef RAPIDJSON_NAMESPACE_BEGIN
14 # error Including YiRapidJSONUtility.h when RAPIDJSON_NAMESPACE_BEGIN has already been defined. To use these utilities first un-define RAPIDJSON_NAMESPACE_BEGIN.
15 #endif
16 #define RAPIDJSON_NAMESPACE_BEGIN \
17  namespace yi \
18  { \
19  namespace rapidjson \
20  {
21 #ifdef RAPIDJSON_NAMESPACE_END
22 # error Including YiRapidJSONUtility.h when RAPIDJSON_NAMESPACE_END has already been defined. To use these utilities first un-define RAPIDJSON_NAMESPACE_END.
23 #endif
24 #define RAPIDJSON_NAMESPACE_END \
25  } \
26  }
27 
28 // These features are not automatically detected properly for PS4 via rapidjson.
29 #ifdef YI_PS4
30 # define RAPIDJSON_HAS_CXX11_RVALUE_REFS 1
31 # define RAPIDJSON_HAS_CXX11_NOEXCEPT 1
32 # define RAPIDJSON_HAS_CXX11_RANGE_FOR 1
33 #endif
34 
35 #include <rapidjson/document.h>
36 
42 class CYIDateTime;
43 class CYIParsingError;
44 
49 {
50 public:
51  virtual ~CYIRapidJSONUtility() = default;
52 
56  static CYIString TypeToString(yi::rapidjson::Type type);
57 
66  static std::unique_ptr<yi::rapidjson::Document> CreateDocumentFromString(const CYIString &rJsonString, CYIParsingError &rParsingError);
67 
72  static yi::rapidjson::Document CreateMoveableDocumentFromString(const CYIString &rJsonString, CYIParsingError &rParsingError);
73 
80  static std::unique_ptr<yi::rapidjson::Document> CreateDocumentFromFile(const CYIString &rFilePath, CYIParsingError &rParsingError);
81 
86  static yi::rapidjson::Document CreateMoveableDocumentFromFile(const CYIString &rFilePath, CYIParsingError &rParsingError);
87 
91  static CYIString CreateStringFromDocument(const yi::rapidjson::Document &rDocument);
92 
96  template<typename Encoding, typename Allocator>
97  static CYIString CreateStringFromValue(const yi::rapidjson::GenericValue<Encoding, Allocator> &rGenericValue);
98 
107  static bool GetBooleanField(const yi::rapidjson::Value *pValue, const char *pFieldName, bool *pFieldData, CYIParsingError &rParsingError);
108 
116  static bool GetIntegerField(const yi::rapidjson::Value *pValue, const char *pFieldName, int32_t *pFieldData, CYIParsingError &rParsingError);
117 
125  static bool GetLongField(const yi::rapidjson::Value *pValue, const char *pFieldName, int64_t *pFieldData, CYIParsingError &rParsingError);
126 
134  static bool GetUnsignedLongField(const yi::rapidjson::Value *pValue, const char *pFieldName, uint64_t *pFieldData, CYIParsingError &rParsingError);
135 
142  static bool GetStringField(const yi::rapidjson::Value *pValue, const char *pFieldName, CYIString &rFieldData, CYIParsingError &rParsingError);
143 
151  static bool GetFloatField(const yi::rapidjson::Value *pValue, const char *pFieldName, float *pFieldData, CYIParsingError &rParsingError);
152 
161  static bool GetDateField(const yi::rapidjson::Value *pValue, const char *pFieldName, CYIDateTime &rFieldData, CYIParsingError &rParsingError);
162 
166  static bool IsNullField(const yi::rapidjson::Value *pValue, const char *pFieldName, bool *pFieldIsNull, CYIParsingError &rParsingError);
167 
171  static bool AddBooleanField(yi::rapidjson::Document *pDocument, const CYIString &rFieldName, bool value);
172 
176  static bool AddIntegerField(yi::rapidjson::Document *pDocument, const CYIString &rFieldName, int32_t value);
177 
181  static bool AddLongField(yi::rapidjson::Document *pDocument, const CYIString &rFieldName, int64_t value);
182 
186  static bool AddUnsignedLongField(yi::rapidjson::Document *pDocument, const CYIString &rField, uint64_t value);
187 
191  static bool AddFloatField(yi::rapidjson::Document *pDocument, const CYIString &rFieldName, float value);
192 
196  static bool AddObjectField(yi::rapidjson::Document *pDocument, const CYIString &rFieldName, yi::rapidjson::Value &rValue);
197 
201  static bool AddStringField(yi::rapidjson::Document *pDocument, const CYIString &rFieldName, const CYIString &rValue);
202 
203 private:
205 };
206 
211 #include "utility/YiRapidJSONUtility.inl"
212 
213 #endif /* _YI_RAPID_JSON_UTILITY_H_ */
static bool AddStringField(yi::rapidjson::Document *pDocument, const CYIString &rFieldName, const CYIString &rValue)
static bool GetBooleanField(const yi::rapidjson::Value *pValue, const char *pFieldName, bool *pFieldData, CYIParsingError &rParsingError)
Container class for Unicode strings. Conceptually, a CYIString object is a sequence of Unicode charac...
Definition: YiString.h:36
static bool AddFloatField(yi::rapidjson::Document *pDocument, const CYIString &rFieldName, float value)
static bool IsNullField(const yi::rapidjson::Value *pValue, const char *pFieldName, bool *pFieldIsNull, CYIParsingError &rParsingError)
static bool AddLongField(yi::rapidjson::Document *pDocument, const CYIString &rFieldName, int64_t value)
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 std::unique_ptr< yi::rapidjson::Document > CreateDocumentFromString(const CYIString &rJsonString, CYIParsingError &rParsingError)
static CYIString CreateStringFromValue(const yi::rapidjson::GenericValue< Encoding, Allocator > &rGenericValue)
static std::unique_ptr< yi::rapidjson::Document > CreateDocumentFromFile(const CYIString &rFilePath, CYIParsingError &rParsingError)
static bool GetLongField(const yi::rapidjson::Value *pValue, const char *pFieldName, int64_t *pFieldData, CYIParsingError &rParsingError)
static CYIString CreateStringFromDocument(const yi::rapidjson::Document &rDocument)
static yi::rapidjson::Document CreateMoveableDocumentFromString(const CYIString &rJsonString, CYIParsingError &rParsingError)
static bool AddBooleanField(yi::rapidjson::Document *pDocument, const CYIString &rFieldName, bool value)
static bool AddUnsignedLongField(yi::rapidjson::Document *pDocument, const CYIString &rField, uint64_t value)
A class to store errors in the parsing of encoded data, such as JSON or XML.
Definition: YiParsingError.h:15
static bool GetIntegerField(const yi::rapidjson::Value *pValue, const char *pFieldName, int32_t *pFieldData, CYIParsingError &rParsingError)
static bool AddObjectField(yi::rapidjson::Document *pDocument, const CYIString &rFieldName, yi::rapidjson::Value &rValue)
static bool GetDateField(const yi::rapidjson::Value *pValue, const char *pFieldName, CYIDateTime &rFieldData, CYIParsingError &rParsingError)
static bool AddIntegerField(yi::rapidjson::Document *pDocument, const CYIString &rFieldName, int32_t value)
Utility class that requires a string as per the following format: http://en.wikipedia.org/wiki/ISO_8601 to construct an instance and provides some commmonly used parts like year, month, hour etc. in different data types and formats. All dates are in the local timezone unless otherwise specified.
Definition: YiDateTime.h:17
static CYIString TypeToString(yi::rapidjson::Type type)
virtual ~CYIRapidJSONUtility()=default
static yi::rapidjson::Document CreateMoveableDocumentFromFile(const CYIString &rFilePath, CYIParsingError &rParsingError)
static bool GetFloatField(const yi::rapidjson::Value *pValue, const char *pFieldName, float *pFieldData, CYIParsingError &rParsingError)
A front-end utility class aimed to simplify the use of RapidJSON tools.
Definition: YiRapidJSONUtility.h:48