You.i Engine
YiRapidJSONUtility.h
Go to the documentation of this file.
1 // © You i Labs Inc. 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 #include <rapidjson/stringbuffer.h>
37 #include <rapidjson/writer.h>
38 
44 class CYIDateTime;
45 class CYIParsingError;
46 
51 {
52 public:
53  virtual ~CYIRapidJSONUtility() = default;
54 
58  static CYIString TypeToString(yi::rapidjson::Type type);
59 
68  static std::unique_ptr<yi::rapidjson::Document> CreateDocumentFromString(const CYIString &rJsonString, CYIParsingError &rParsingError);
69 
74  static yi::rapidjson::Document CreateMoveableDocumentFromString(const CYIString &rJsonString, CYIParsingError &rParsingError);
75 
82  static std::unique_ptr<yi::rapidjson::Document> CreateDocumentFromFile(const CYIString &rFilePath, CYIParsingError &rParsingError);
83 
88  static yi::rapidjson::Document CreateMoveableDocumentFromFile(const CYIString &rFilePath, CYIParsingError &rParsingError);
89 
93  static CYIString CreateStringFromDocument(const yi::rapidjson::Document &rDocument);
94 
98  template<typename Encoding, typename Allocator>
99  static CYIString CreateStringFromValue(const yi::rapidjson::GenericValue<Encoding, Allocator> &rGenericValue);
100 
109  static bool GetBooleanField(const yi::rapidjson::Value *pValue, const char *pFieldName, bool *pFieldData, CYIParsingError &rParsingError);
110 
118  static bool GetIntegerField(const yi::rapidjson::Value *pValue, const char *pFieldName, int32_t *pFieldData, CYIParsingError &rParsingError);
119 
127  static bool GetLongField(const yi::rapidjson::Value *pValue, const char *pFieldName, int64_t *pFieldData, CYIParsingError &rParsingError);
128 
136  static bool GetUnsignedLongField(const yi::rapidjson::Value *pValue, const char *pFieldName, uint64_t *pFieldData, CYIParsingError &rParsingError);
137 
144  static bool GetStringField(const yi::rapidjson::Value *pValue, const char *pFieldName, CYIString &rFieldData, CYIParsingError &rParsingError);
145 
153  static bool GetFloatField(const yi::rapidjson::Value *pValue, const char *pFieldName, float *pFieldData, CYIParsingError &rParsingError);
154 
163  static bool GetDateField(const yi::rapidjson::Value *pValue, const char *pFieldName, CYIDateTime &rFieldData, CYIParsingError &rParsingError);
164 
168  static bool IsNullField(const yi::rapidjson::Value *pValue, const char *pFieldName, bool *pFieldIsNull, CYIParsingError &rParsingError);
169 
173  static bool AddBooleanField(yi::rapidjson::Document *pDocument, const CYIString &rFieldName, bool value);
174 
178  static bool AddIntegerField(yi::rapidjson::Document *pDocument, const CYIString &rFieldName, int32_t value);
179 
183  static bool AddLongField(yi::rapidjson::Document *pDocument, const CYIString &rFieldName, int64_t value);
184 
188  static bool AddUnsignedLongField(yi::rapidjson::Document *pDocument, const CYIString &rField, uint64_t value);
189 
193  static bool AddFloatField(yi::rapidjson::Document *pDocument, const CYIString &rFieldName, float value);
194 
198  static bool AddObjectField(yi::rapidjson::Document *pDocument, const CYIString &rFieldName, yi::rapidjson::Value &rValue);
199 
203  static bool AddStringField(yi::rapidjson::Document *pDocument, const CYIString &rFieldName, const CYIString &rValue);
204 
205 private:
207 };
208 
213 #include "utility/YiRapidJSONUtility.inl"
214 
215 #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:32
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:19
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:50