OROCHI
 
Loading...
Searching...
No Matches
GxJson.h
Go to the documentation of this file.
1//===========================================================================
9//===========================================================================
10#pragma once
11
12#include "document.h"
13
14GX_CORE_NAMESPACE_BEGIN()
15
16//===========================================================================
18//===========================================================================
19class GxJson : public GxClassBase
20{
21 //-----------------------------------------------------------
23 //-----------------------------------------------------------
25public:
26 // RTTI定義
27 GX_RTTI_CLASS(GxJson, GxClassBase)
28 // GxClassBase継承クラス用禁止宣言
30
31#if GX_DEVELOP
32 // new, delete定義
33 GX_OPERATOR_NEW_DELETE(GxAllocatorList::ALLOCATOR_TYPE::DEVELOP)
34
35 //===========================================================================
37 //===========================================================================
38 class GxJsonObject
39 {
40 //-----------------------------------------------------------
42 //-----------------------------------------------------------
44 public:
45 friend class GxJson;
46
48 enum class TYPE
49 {
50 OBJECT = 3,
51 ARRAY,
52 };
53
55 //-----------------------------------------------------------
57 //-----------------------------------------------------------
59 private:
61 GxJsonObject(void) {}
63 GxJsonObject(rapidjson::Document* pDocument, TYPE type) : _pDocument(pDocument), _value(static_cast<rapidjson::Type>(type)) {}
64
66 //-----------------------------------------------------------
68 //-----------------------------------------------------------
70 public:
72 void addObject(GxJsonObject* pObject, GX_CSTR name);
74 void addS32(s32 value, GX_CSTR name);
76 void addU32(u32 value, GX_CSTR name);
78 void addS64(s64 value, GX_CSTR name);
80 void addU64(u64 value, GX_CSTR name);
82 void addF32(f32 value, GX_CSTR name);
84 void addF64(f64 value, GX_CSTR name);
86 void addB32(b32 value, GX_CSTR name);
88 void addSTR(GX_CSTR value, GX_CSTR name);
89
91 //-----------------------------------------------------------
93 //-----------------------------------------------------------
95
96 private:
97 rapidjson::Document* _pDocument;
98 rapidjson::Value _value;
99
101 };
102#endif //GX_DEVELOP
103
104 //===========================================================================
106 //===========================================================================
108 {
109 //-----------------------------------------------------------
111 //-----------------------------------------------------------
113 public:
114 friend class GxJson;
115
117 //-----------------------------------------------------------
119 //-----------------------------------------------------------
121 public:
123 GxJsonNode(const GxJsonNode& node) : _value(node._value) {}
124 private:
126 GxJsonNode(void) = delete;
128 GxJsonNode(rapidjson::Value& value) : _value(value) {}
129
131 //-----------------------------------------------------------
133 //-----------------------------------------------------------
135 public:
137 GX_FORCE_INLINE const GxJsonNode operator[](GX_CSTR name) const { return GxJsonNode(_value[name]); }
139 GX_FORCE_INLINE const GxJsonNode operator[](u32 i) const { return GxJsonNode(_value[i]); }
141 GX_FORCE_INLINE b32 hasMember(GX_CSTR name) const { return _value.HasMember(name); }
143 GX_FORCE_INLINE b32 isArray(void) const { return _value.IsArray(); }
145 GX_FORCE_INLINE u32 getArrayCount(void) const { GX_ASSERT(isArray(), "is not array!"); return _value.Size(); }
147 GX_FORCE_INLINE b32 isS32(void) const { return _value.IsInt(); }
149 GX_FORCE_INLINE s32 getS32(void) const { GX_ASSERT(isS32(), "is not s32!"); return _value.GetInt(); }
151 s32 getS32(GX_CSTR name, s32 defaultValue, s32 index = -1) const;
153 GX_FORCE_INLINE b32 isU32(void) const { return _value.IsUint(); }
155 GX_FORCE_INLINE u32 getU32(void) const { GX_ASSERT(isU32(), "is not u32!"); return _value.GetUint(); }
157 u32 getU32(GX_CSTR name, u32 defaultValue, s32 index = -1) const;
159 GX_FORCE_INLINE b32 isS64(void) const { return _value.IsInt64(); }
161 GX_FORCE_INLINE s64 getS64(void) const { GX_ASSERT(isS64(), "is not s64!"); return _value.GetInt64(); }
163 s64 getS64(GX_CSTR name, s64 defaultValue, s32 index = -1) const;
165 GX_FORCE_INLINE b32 isU64(void) const { return _value.IsUint64(); }
167 GX_FORCE_INLINE u64 getU64(void) const { GX_ASSERT(isU64(), "is not u64!"); return _value.GetUint64(); }
169 u64 getU64(GX_CSTR name, u64 defaultValue, s32 index = -1) const;
171 GX_FORCE_INLINE b32 isF32(void) const { return _value.IsFloat(); }
173 GX_FORCE_INLINE f32 getF32(void) const { GX_ASSERT(isF32(), "is not f32!"); return _value.GetFloat(); }
175 f32 getF32(GX_CSTR name, f32 defaultValue, s32 index = -1) const;
177 GX_FORCE_INLINE b32 isF64(void) const { return _value.IsDouble(); }
179 GX_FORCE_INLINE f64 getF64(void) const { GX_ASSERT(isF64(), "is not f64!"); return _value.GetDouble(); }
181 f64 getF64(GX_CSTR name, f64 defaultValue, s32 index = -1) const;
183 GX_FORCE_INLINE b32 isB32(void) const { return _value.IsBool(); }
185 GX_FORCE_INLINE b32 getB32(void) const { GX_ASSERT(isB32(), "is not b32!"); return _value.GetBool(); }
187 b32 getB32(GX_CSTR name, b32 defaultValue, s32 index = -1) const;
189 GX_FORCE_INLINE b32 isString(void) const { return _value.IsString(); }
191 GX_FORCE_INLINE GX_CSTR getString(void) const { GX_ASSERT(isString(), "is not string!"); return _value.GetString(); }
193 GX_CSTR getString(GX_CSTR name, GX_CSTR defaultValue, s32 index = -1) const;
195 GX_FORCE_INLINE u32 getStringLength(void) const { GX_ASSERT(isString(), "is not string!"); return _value.GetStringLength(); }
197 GX_FORCE_INLINE b32 isObject(void) const { return _value.IsObject(); }
199 GX_FORCE_INLINE b32 isNumber(void) const { return _value.IsNumber(); }
201 GX_FORCE_INLINE b32 isNull(void) const { return _value.IsNull(); }
203 GxSize getSize(GX_CSTR name, const GxSize& defaultValue, s32 index = -1) const;
205 GxRect getRect(GX_CSTR name, const GxRect& defaultValue, s32 index = -1) const;
207 GxColor getColor(GX_CSTR name, const GxColor& defaultValue, s32 index = -1) const;
209 GxVector2 getVector2(GX_CSTR name, const GxVector2& defaultValue, s32 index = -1) const;
211 GxPoint2 getPoint2(GX_CSTR name, const GxPoint2& defaultValue, s32 index = -1) const;
213 GxFlag32Base getFlag32Base(GX_CSTR name, const GxFlag32Base& defaultValue, s32 index = -1) const;
214
216 //-----------------------------------------------------------
218 //-----------------------------------------------------------
220 private:
221 rapidjson::Value& _value;
222
224 };
225
227 //-----------------------------------------------------------
229 //-----------------------------------------------------------
231public:
233 GxJson(u32 memorySize = 0);
235 virtual ~GxJson(void);
236
238 //-----------------------------------------------------------
240 //-----------------------------------------------------------
242public:
244 GX_FORCE_INLINE const GxJsonNode operator[](GX_CSTR name) const { return GxJsonNode(const_cast<rapidjson::Value&>((*_pDocument)[name])); }
246 GX_FORCE_INLINE b32 hasMember(GX_CSTR name) const { return _pDocument->HasMember(name); }
247#if GX_DEVELOP
249 GxJsonObject* createObject(GxJsonObject::TYPE type);
251 void addObject(GxJsonObject* pObject, GX_CSTR name);
253 void readJson(GxStream& stream);
255 void writeJson(GxStream& stream, b32 isCompress = false);
256#endif //GX_DEVELOP
258 GX_FORCE_INLINE void parse(GX_CHAR* pBuffer) { _pDocument->Parse(pBuffer); }
259
261 //-----------------------------------------------------------
263 //-----------------------------------------------------------
265private:
266 rapidjson::Document* _pDocument;
267#if GX_DEVELOP
268 GxArray _objects;
269 void* _pBuffer;
270#endif //GX_DEVELOP
271
273};
274
275GX_CORE_NAMESPACE_END()
#define GX_PROHIBIT_CLASS_BASE(__CLASS__)
GxClassBase継承の禁止宣言
Definition GxBase.h:240
配列クラス
Definition GxArray.h:18
オブジェクト基底クラス
Definition GxBase.h:88
JSON解析用ノード
Definition GxJson.h:108
GX_FORCE_INLINE f32 getF32(void) const
F32値を取得
Definition GxJson.h:173
GX_FORCE_INLINE b32 isArray(void) const
配列か判定
Definition GxJson.h:143
GX_FORCE_INLINE b32 hasMember(GX_CSTR name) const
メンバ保持判定
Definition GxJson.h:141
GX_FORCE_INLINE GX_CSTR getString(void) const
文字列を取得
Definition GxJson.h:191
GX_FORCE_INLINE b32 isNull(void) const
Nullか判定
Definition GxJson.h:201
GX_FORCE_INLINE b32 isU64(void) const
U64か判定
Definition GxJson.h:165
GxColor getColor(GX_CSTR name, const GxColor &defaultValue, s32 index=-1) const
GxColorを取得
Definition GxJson.cpp:537
GX_FORCE_INLINE b32 isF64(void) const
F64か判定
Definition GxJson.h:177
GX_FORCE_INLINE u64 getU64(void) const
U64値を取得
Definition GxJson.h:167
GX_FORCE_INLINE const GxJsonNode operator[](GX_CSTR name) const
文字列指定
Definition GxJson.h:137
GxJsonNode(const GxJsonNode &node)
コピーコンストラクタ
Definition GxJson.h:123
GX_FORCE_INLINE s64 getS64(void) const
S64値を取得
Definition GxJson.h:161
GX_FORCE_INLINE b32 isString(void) const
文字列か判定
Definition GxJson.h:189
GX_FORCE_INLINE b32 isU32(void) const
U32か判定
Definition GxJson.h:153
GX_FORCE_INLINE u32 getU32(void) const
U32値を取得
Definition GxJson.h:155
GX_FORCE_INLINE u32 getArrayCount(void) const
配列要素数を取得
Definition GxJson.h:145
GxFlag32Base getFlag32Base(GX_CSTR name, const GxFlag32Base &defaultValue, s32 index=-1) const
GxFlag32Baseを取得
Definition GxJson.cpp:619
GX_FORCE_INLINE s32 getS32(void) const
S32値を取得
Definition GxJson.h:149
GX_FORCE_INLINE b32 isS32(void) const
S32か判定
Definition GxJson.h:147
GX_FORCE_INLINE const GxJsonNode operator[](u32 i) const
インデックス指定
Definition GxJson.h:139
GX_FORCE_INLINE b32 isNumber(void) const
数値か判定
Definition GxJson.h:199
GX_FORCE_INLINE f64 getF64(void) const
F64値を取得
Definition GxJson.h:179
GX_FORCE_INLINE b32 isF32(void) const
F32か判定
Definition GxJson.h:171
GX_FORCE_INLINE b32 isS64(void) const
S64か判定
Definition GxJson.h:159
GxRect getRect(GX_CSTR name, const GxRect &defaultValue, s32 index=-1) const
GxRectを取得
Definition GxJson.cpp:505
GX_FORCE_INLINE u32 getStringLength(void) const
文字列の長さを取得
Definition GxJson.h:195
GxSize getSize(GX_CSTR name, const GxSize &defaultValue, s32 index=-1) const
GxSizeを取得
Definition GxJson.cpp:477
GxVector2 getVector2(GX_CSTR name, const GxVector2 &defaultValue, s32 index=-1) const
GxVector2を取得
Definition GxJson.cpp:563
GX_FORCE_INLINE b32 isB32(void) const
B32か判定
Definition GxJson.h:183
GX_FORCE_INLINE b32 isObject(void) const
オブジェクトか判定
Definition GxJson.h:197
GX_FORCE_INLINE b32 getB32(void) const
B32値を取得
Definition GxJson.h:185
GxPoint2 getPoint2(GX_CSTR name, const GxPoint2 &defaultValue, s32 index=-1) const
GxPoint2を取得
Definition GxJson.cpp:591
JSONパーサ
Definition GxJson.h:20
GX_FORCE_INLINE const GxJsonNode operator[](GX_CSTR name) const
文字列指定
Definition GxJson.h:244
GX_FORCE_INLINE b32 hasMember(GX_CSTR name) const
メンバ保持判定
Definition GxJson.h:246
GxJson(u32 memorySize=0)
コンストラクタ
Definition GxJson.cpp:29
virtual ~GxJson(void)
デストラクタ
Definition GxJson.cpp:53
ストリーム基礎クラス
Definition GxStream.h:20
Definition GxColor.h:21
フラグ
Definition GxStruct.h:1243
座標
Definition GxStruct.h:867
矩形
Definition GxStruct.h:951
サイズ
Definition GxStruct.h:730
2次元ベクトル
Definition GxVector.h:34
32bitブーリアン
Definition GxDefine.h:173