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 PlayStation via rapidjson.
29 #if defined(YI_PLAYSTATION)
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 &jsonString, CYIParsingError &parsingError);
69 
74  static yi::rapidjson::Document CreateMoveableDocumentFromString(const CYIString &jsonString, CYIParsingError &parsingError);
75 
82  static std::unique_ptr<yi::rapidjson::Document> CreateDocumentFromFile(const CYIString &filePath, CYIParsingError &parsingError);
83 
88  static yi::rapidjson::Document CreateMoveableDocumentFromFile(const CYIString &filePath, CYIParsingError &parsingError);
89 
93  static CYIString CreateStringFromDocument(const yi::rapidjson::Document &document);
94 
98  template<typename Encoding, typename Allocator>
99  static CYIString CreateStringFromValue(const yi::rapidjson::GenericValue<Encoding, Allocator> &genericValue);
100 
109  static bool GetBooleanField(const yi::rapidjson::Value *pValue, const char *pFieldName, bool *pFieldData, CYIParsingError &parsingError);
110 
118  static bool GetIntegerField(const yi::rapidjson::Value *pValue, const char *pFieldName, int32_t *pFieldData, CYIParsingError &parsingError);
119 
127  static bool GetLongField(const yi::rapidjson::Value *pValue, const char *pFieldName, int64_t *pFieldData, CYIParsingError &parsingError);
128 
136  static bool GetUnsignedLongField(const yi::rapidjson::Value *pValue, const char *pFieldName, uint64_t *pFieldData, CYIParsingError &parsingError);
137 
144  static bool GetStringField(const yi::rapidjson::Value *pValue, const char *pFieldName, CYIString &fieldData, CYIParsingError &parsingError);
145 
153  static bool GetFloatField(const yi::rapidjson::Value *pValue, const char *pFieldName, float *pFieldData, CYIParsingError &parsingError);
154 
163  static bool GetDateField(const yi::rapidjson::Value *pValue, const char *pFieldName, CYIDateTime &fieldData, CYIParsingError &parsingError);
164 
168  static bool IsNullField(const yi::rapidjson::Value *pValue, const char *pFieldName, bool *pFieldIsNull, CYIParsingError &parsingError);
169 
173  static bool AddBooleanField(yi::rapidjson::Document *pDocument, const CYIString &fieldName, bool value);
174 
178  static bool AddIntegerField(yi::rapidjson::Document *pDocument, const CYIString &fieldName, int32_t value);
179 
183  static bool AddLongField(yi::rapidjson::Document *pDocument, const CYIString &fieldName, int64_t value);
184 
188  static bool AddUnsignedLongField(yi::rapidjson::Document *pDocument, const CYIString &field, uint64_t value);
189 
193  static bool AddFloatField(yi::rapidjson::Document *pDocument, const CYIString &fieldName, float value);
194 
198  static bool AddObjectField(yi::rapidjson::Document *pDocument, const CYIString &fieldName, yi::rapidjson::Value &value);
199 
204  static bool AddObjectField(yi::rapidjson::Value *pValue, const CYIString &fieldName, yi::rapidjson::Value &fieldValue, yi::rapidjson::Document::AllocatorType &allocator);
205 
209  static bool AddStringField(yi::rapidjson::Document *pDocument, const CYIString &fieldName, const CYIString &value);
210 
214  static bool AddStringField(yi::rapidjson::Value *pValue, const CYIString &fieldName, const CYIString &fieldValue, yi::rapidjson::Document::AllocatorType &allocator);
215 
216 private:
218 };
219 
224 #include "utility/YiRapidJSONUtility.inl"
225 
226 #endif /* _YI_RAPID_JSON_UTILITY_H_ */
static bool GetBooleanField(const yi::rapidjson::Value *pValue, const char *pFieldName, bool *pFieldData, CYIParsingError &parsingError)
static bool AddBooleanField(yi::rapidjson::Document *pDocument, const CYIString &fieldName, bool value)
Container class for Unicode strings. Conceptually, a CYIString object is a sequence of Unicode charac...
Definition: YiString.h:32
static bool AddIntegerField(yi::rapidjson::Document *pDocument, const CYIString &fieldName, int32_t value)
static CYIString CreateStringFromDocument(const yi::rapidjson::Document &document)
static bool AddFloatField(yi::rapidjson::Document *pDocument, const CYIString &fieldName, float value)
static std::unique_ptr< yi::rapidjson::Document > CreateDocumentFromFile(const CYIString &filePath, CYIParsingError &parsingError)
static bool GetDateField(const yi::rapidjson::Value *pValue, const char *pFieldName, CYIDateTime &fieldData, CYIParsingError &parsingError)
static std::unique_ptr< yi::rapidjson::Document > CreateDocumentFromString(const CYIString &jsonString, CYIParsingError &parsingError)
static bool GetStringField(const yi::rapidjson::Value *pValue, const char *pFieldName, CYIString &fieldData, CYIParsingError &parsingError)
static bool GetFloatField(const yi::rapidjson::Value *pValue, const char *pFieldName, float *pFieldData, CYIParsingError &parsingError)
A class to store errors in the parsing of encoded data, such as JSON or XML.
Definition: YiParsingError.h:15
static CYIString CreateStringFromValue(const yi::rapidjson::GenericValue< Encoding, Allocator > &genericValue)
static bool IsNullField(const yi::rapidjson::Value *pValue, const char *pFieldName, bool *pFieldIsNull, CYIParsingError &parsingError)
static bool GetUnsignedLongField(const yi::rapidjson::Value *pValue, const char *pFieldName, uint64_t *pFieldData, CYIParsingError &parsingError)
static bool GetLongField(const yi::rapidjson::Value *pValue, const char *pFieldName, int64_t *pFieldData, CYIParsingError &parsingError)
static bool AddStringField(yi::rapidjson::Document *pDocument, const CYIString &fieldName, const CYIString &value)
static yi::rapidjson::Document CreateMoveableDocumentFromString(const CYIString &jsonString, CYIParsingError &parsingError)
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 bool AddObjectField(yi::rapidjson::Document *pDocument, const CYIString &fieldName, yi::rapidjson::Value &value)
static bool AddUnsignedLongField(yi::rapidjson::Document *pDocument, const CYIString &field, uint64_t value)
A front-end utility class aimed to simplify the use of RapidJSON tools.
Definition: YiRapidJSONUtility.h:50
static yi::rapidjson::Document CreateMoveableDocumentFromFile(const CYIString &filePath, CYIParsingError &parsingError)
static bool AddLongField(yi::rapidjson::Document *pDocument, const CYIString &fieldName, int64_t value)
static bool GetIntegerField(const yi::rapidjson::Value *pValue, const char *pFieldName, int32_t *pFieldData, CYIParsingError &parsingError)