TrueReality  v0.1.1912
Object.cpp
Go to the documentation of this file.
1 /*
2 * True Reality Open Source Game and Simulation Engine
3 * Copyright © 2021 Acid Rain Studios LLC
4 *
5 * This library is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU Lesser General Public License as published by the Free
7 * Software Foundation; either version 3.0 of the License, or (at your option)
8 * any later version.
9 *
10 * This library is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13 * details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this library; if not, write to the Free Software Foundation, Inc.,
17 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 * @author Maxim Serebrennik
20 */
21 
22 #include <trUtil/JSON/Object.h>
23 
24 #include <trUtil/JSON/Array.h>
25 
26 #include <iostream>
27 
28 namespace trUtil::JSON
29 {
32  {}
33 
36  {
37  mRoot = Object;
38  }
39 
42  {}
43 
46  {
47  return mRoot.GetMemberNames();
48  }
49 
51  void Object::SetComment(const std::string& comment)
52  {
53  mRoot.SetComment(comment);
54  }
55 
57  bool Object::HasComment() const
58  {
59  return mRoot.HasComment();
60  }
61 
63  std::string Object::GetComment() const
64  {
65  return mRoot.GetComment();
66  }
67 
70  {
71  mRoot.Clear();
72  }
73 
76  {
77  return mRoot;
78  }
79 
82  {
83  std::cout << mRoot << std::endl;
84  }
85 
87  bool Object::KeyPresent(const std::string &key) const
88  {
89  return mRoot.KeyPresent(key);
90  }
91 
93  bool Object::IsNull(const std::string &key) const
94  {
95  return mRoot.IsNull(key);
96  }
97 
99  void Object::SetNull(const std::string &key)
100  {
101  mRoot.SetNull(key);
102  }
103 
105  bool Object::IsBool(const std::string &key) const
106  {
107  return mRoot.IsBool(key);
108  }
109 
111  bool Object::GetBool(const std::string &key) const
112  {
113  return mRoot.GetBool(key);
114  }
115 
117  void Object::SetBool(const std::string &key, const bool &value)
118  {
119  mRoot.SetBool(key, value);
120  }
121 
123  bool Object::IsTrue(const std::string &key) const
124  {
125  if (KeyPresent(key))
126  {
127  if (GetBool(key) == true)
128  {
129  return true;
130  }
131  else
132  {
133  return false;
134  }
135  }
136  return false;
137  }
138 
140  bool Object::IsFalse(const std::string &key) const
141  {
142  if (KeyPresent(key))
143  {
144  if (GetBool(key) == false)
145  {
146  return true;
147  }
148  else
149  {
150  return false;
151  }
152  }
153  return false;
154  }
155 
157  bool Object::IsNumber(const std::string &key) const
158  {
159  return mRoot.IsNumber(key);
160  }
161 
163  bool Object::IsInt(const std::string &key) const
164  {
165  return mRoot.IsInt(key);
166  }
167 
169  int Object::GetInt(const std::string &key) const
170  {
171  return mRoot.GetInt(key);
172  }
173 
175  void Object::SetInt(const std::string &key, const int &value)
176  {
177  mRoot.SetInt(key, value);
178  }
179 
181  bool Object::IsDouble(const std::string &key) const
182  {
183  return mRoot.IsDouble(key);
184  }
185 
187  double Object::GetDouble(const std::string &key) const
188  {
189  return mRoot.GetDouble(key);
190  }
191 
193  void Object::SetDouble(const std::string &key, const double &value)
194  {
195  mRoot.SetDouble(key, value);
196  }
197 
199  bool Object::IsUInt(const std::string &key) const
200  {
201  return mRoot.IsUInt(key);
202  }
203 
205  unsigned int Object::GetUInt(const std::string &key) const
206  {
207  return mRoot.GetUInt(key);
208  }
209 
211  void Object::SetUInt(const std::string &key, const unsigned int &value)
212  {
213  mRoot.SetUInt(key, value);
214  }
215 
217  bool Object::IsInt64(const std::string &key) const
218  {
219  return mRoot.IsInt64(key);
220  }
221 
223  Int64 Object::GetInt64(const std::string &key) const
224  {
225  return mRoot.GetInt64(key);
226  }
227 
229  void Object::SetInt64(const std::string &key, const Int64 &value)
230  {
231  mRoot.SetInt64(key, value);
232  }
233 
235  bool Object::IsUInt64(const std::string &key) const
236  {
237  return mRoot.IsUInt64(key);
238  }
239 
241  UInt64 Object::GetUInt64(const std::string &key) const
242  {
243  return mRoot.GetUInt64(key);
244  }
245 
247  void Object::SetUInt64(const std::string &key, const UInt64 &value)
248  {
249  mRoot.SetUInt64(key, value);
250  }
251 
253  bool Object::IsFloat(const std::string &key) const
254  {
255  return mRoot.IsFloat(key);
256  }
257 
259  float Object::GetFloat(const std::string &key) const
260  {
261  return mRoot.GetFloat(key);
262  }
263 
265  void Object::SetFloat(const std::string &key, const float &value)
266  {
267  mRoot.SetFloat(key, value);
268  }
269 
271  bool Object::IsString(const std::string &key) const
272  {
273  return mRoot.IsString(key);
274  }
275 
277  const std::string Object::GetString(const std::string &key) const
278  {
279  return mRoot.GetString(key);
280  }
281 
283  void Object::SetString(const std::string &key, const std::string &value)
284  {
285  mRoot.SetString(key, value);
286  }
287 
289  bool Object::IsArray(const std::string &key) const
290  {
291  return mRoot.IsArray(key);
292  }
293 
295  Array Object::GetArray(const std::string &key) const
296  {
297  return mRoot.GetArray(key);
298  }
299 
301  void Object::SetArray(const std::string &key, Array& value)
302  {
303  mRoot.SetArray(key, value);
304  }
305 
307  bool Object::IsObject(const std::string &key) const
308  {
309  return mRoot.IsObject(key);
310  }
311 
313  Object Object::GetObject(const std::string &key) const
314  {
315  return mRoot.GetObject(key);
316  }
317 
319  void Object::SetObject(const std::string &key, Object& value)
320  {
321  mRoot.SetObject(key, value);
322  }
323 }
virtual bool IsArray() const
Checks if the value stored is an Array.
Definition: Value.cpp:696
virtual bool IsNull(const std::string &key) const override
Checks if the value stored at the specific key is a NULL.
Definition: Object.cpp:93
virtual bool IsUInt64() const
Checks if the value stored is a 64bit Unsigned Integer.
Definition: Value.cpp:570
virtual float GetFloat(const std::string &key) const override
Returns the float value stored at the given key.
Definition: Object.cpp:259
virtual void SetUInt64(const std::string &key, const UInt64 &value) override
Sets the 64bit Integer value to be stored at the given key.
Definition: Object.cpp:247
virtual bool IsBool() const
Checks if the value stored is a Boolean.
Definition: Value.cpp:342
virtual void SetInt64(const std::string &key, Int64 value)
Sets the Int64 value in the Object.
Definition: Value.cpp:564
std::string GetComment() const
Returns the internal comment.
Definition: Value.cpp:226
virtual bool IsString(const std::string &key) const override
Checks if the value stored at the specific key is a String.
Definition: Object.cpp:271
virtual bool IsInt() const
Checks if the value stored is an Integer.
Definition: Value.cpp:402
Value mRoot
The root.
Definition: Object.h:522
virtual bool KeyPresent(const std::string &key) const
Checks if the JSON Root Node has an entry with a given key present.
Definition: Value.cpp:288
virtual bool IsFalse(const std::string &key) const override
Checks if the value stored at the specific key is False.
Definition: Object.cpp:140
virtual bool IsUInt() const
Checks if the value stored Unsigned Integer.
Definition: Value.cpp:486
virtual bool IsInt64(const std::string &key) const override
Checks if the value stored at the specific key is a 64bit Integer.
Definition: Object.cpp:217
virtual bool IsFloat() const
Checks if the value stored is a float.
Definition: Value.cpp:612
virtual unsigned int GetUInt() const
Returns the Unsigned Integer value.
Definition: Value.cpp:504
virtual bool GetBool(const std::string &key) const override
Returns the Boolean value stored at the given key.
Definition: Object.cpp:111
virtual bool IsFloat(const std::string &key) const override
Checks if the value stored at the specific key is a float.
Definition: Object.cpp:253
virtual void SetFloat(const std::string &key, const float &value) override
Sets the float value to be stored at the given key.
Definition: Object.cpp:265
virtual const std::string GetString(const std::string &key) const override
Returns the String value stored at the given key.
Definition: Object.cpp:277
virtual double GetDouble(const std::string &key) const override
Returns the Double value stored at the given key.
Definition: Object.cpp:187
A JSON array.
Definition: Array.h:46
virtual bool KeyPresent(const std::string &key) const override
Checks if the JSON Root Node has an entry with a given key present.
Definition: Object.cpp:87
virtual void SetUInt(const std::string &key, unsigned int value)
Sets the Unsigned Int value in the Object.
Definition: Value.cpp:522
virtual int GetInt() const
Returns the Integer value.
Definition: Value.cpp:420
virtual void SetString(const std::string &key, const std::string &value)
Sets the String value in the Object.
Definition: Value.cpp:690
virtual bool IsString() const
Checks if the value stored is a String.
Definition: Value.cpp:654
virtual void Clear()
Clears the internal JSON Root node.
Definition: Value.cpp:240
virtual Value & GetJSONRoot() override
Returns a reference to the internal JSON Root node.
Definition: Object.cpp:75
virtual void SetArray(const std::string &key, Array &value) override
Sets the Array to be stored at the given key.
Definition: Object.cpp:301
Represents a JSON value.
Definition: Value.h:139
virtual bool IsBool(const std::string &key) const override
Checks if the value stored at the specific key is a Boolean.
Definition: Object.cpp:105
int64_t Int64
The fourth int 6.
Definition: Value.h:72
virtual void SetUInt(const std::string &key, const unsigned int &value) override
Sets the Unsigned Integer value to be stored at the given key.
Definition: Object.cpp:211
virtual double GetDouble() const
Returns the Double value.
Definition: Value.cpp:462
virtual bool IsNull() const
Checks if the value stored is a NULL.
Definition: Value.cpp:294
virtual void SetDouble(const std::string &key, const double &value) override
Sets the Double value to be stored at the given key.
Definition: Object.cpp:193
virtual void SetNull(const std::string &key) const
Sets the NULL value in the Object.
Definition: Value.cpp:312
virtual bool GetBool() const
Returns the Boolean value.
Definition: Value.cpp:360
Forward declaration.
Definition: Object.h:46
void SetComment(const std::string &comment)
Sets a comment.
Definition: Object.cpp:51
virtual void SetBool(const std::string &key, const bool &value) override
Sets the Boolean value to be stored at the given key.
Definition: Object.cpp:117
virtual void SetUInt64(const std::string &key, UInt64 value)
Sets the Unsigned Int64 value in the Object.
Definition: Value.cpp:606
virtual bool IsDouble() const
Checks if the value stored is a Double.
Definition: Value.cpp:444
virtual float GetFloat() const
Returns the float value stored.
Definition: Value.cpp:630
virtual void SetNull(const std::string &key) override
Sets the value stored at the specific key to NULL.
Definition: Object.cpp:99
virtual UInt64 GetUInt64() const
Returns the Unsigned 64bit Integer value.
Definition: Value.cpp:588
virtual void SetInt(const std::string &key, int value)
Sets the Integer value in the Object.
Definition: Value.cpp:438
void Clear() override
Clears the internal JSON Root node.
Definition: Object.cpp:69
virtual bool IsUInt64(const std::string &key) const override
Checks if the value stored at the specific key is a 64bit Integer.
Definition: Object.cpp:235
virtual bool IsDouble(const std::string &key) const override
Checks if the value stored at the specific key is a Double.
Definition: Object.cpp:181
virtual void PrintJSONRoot() override
Prints out to the screen the whole JSON Root content.
Definition: Object.cpp:81
virtual void SetObject(const std::string &key, Object &value)
Sets the Object value in the Object.
Definition: Value.cpp:780
virtual Int64 GetInt64(const std::string &key) const override
Returns the 64bit Integer value stored at the given key.
Definition: Object.cpp:223
virtual const Array GetArray() const
Returns the Array value stored.
Definition: Value.cpp:714
virtual void SetInt(const std::string &key, const int &value) override
Sets the Integer value to be stored at the given key.
Definition: Object.cpp:175
virtual Object GetObject(const std::string &key) const override
Returns the Object value stored at the given key.
Definition: Object.cpp:313
std::string GetComment() const
Returns the internal comment.
Definition: Object.cpp:63
virtual int GetInt(const std::string &key) const override
Returns the Integer value stored at the given key.
Definition: Object.cpp:169
void SetComment(const std::string &comment)
Adds a comment to the internal value.
Definition: Value.cpp:214
const Value::Members GetMemberNames() const
Returns the value names contained in the object.
Definition: Value.cpp:276
virtual void SetObject(const std::string &key, Object &value) override
Sets the Array to be stored at the given key.
Definition: Object.cpp:319
virtual void SetFloat(const std::string &key, float value)
Sets the Float value in the Object.
Definition: Value.cpp:648
virtual void SetBool(const std::string &key, bool value)
Sets the Boolean value in the Object.
Definition: Value.cpp:378
virtual bool IsInt64() const
Checks if the value stored is a 64bit Integer.
Definition: Value.cpp:528
virtual const Object GetObject() const
Returns the Object value stored.
Definition: Value.cpp:759
const Value::Members GetMemberNames() const
Returns the value names contained in the object.
Definition: Object.cpp:45
virtual unsigned int GetUInt(const std::string &key) const override
Returns the Unsigned Integer value stored at the given key.
Definition: Object.cpp:205
virtual void SetInt64(const std::string &key, const Int64 &value) override
Sets the 64bit Integer value to be stored at the given key.
Definition: Object.cpp:229
virtual void SetArray(const std::string &key, Array &value)
Sets the Array value in the Object.
Definition: Value.cpp:735
bool HasComment() const
Checks if the internal value has a comment.
Definition: Object.cpp:57
virtual void SetDouble(const std::string &key, double value)
Sets the Double value in the Object.
Definition: Value.cpp:480
virtual bool IsArray(const std::string &key) const override
Checks if the value stored at the specific key is an Array.
Definition: Object.cpp:289
virtual bool IsTrue(const std::string &key) const override
Checks if the value stored at the specific key is True.
Definition: Object.cpp:123
virtual bool IsObject() const
Checks if the value stored is an Object.
Definition: Value.cpp:741
virtual const std::string GetString() const
Returns the String value stored.
Definition: Value.cpp:672
virtual UInt64 GetUInt64(const std::string &key) const override
Returns the 64bit Integer value stored at the given key.
Definition: Object.cpp:241
uint64_t UInt64
The fourth u int 6.
Definition: Value.h:74
virtual bool IsUInt(const std::string &key) const override
Checks if the value stored at the specific key is an Unsigned Integer.
Definition: Object.cpp:199
virtual bool IsObject(const std::string &key) const override
Checks if the value stored at the specific key is an Object.
Definition: Object.cpp:307
std::vector< std::string > Members
The members.
Definition: Value.h:144
virtual bool IsNumber(const std::string &key) const override
Checks if the value stored at the specific key is a Number.
Definition: Object.cpp:157
virtual void SetString(const std::string &key, const std::string &value) override
Sets the String to be stored at the given key.
Definition: Object.cpp:283
virtual Int64 GetInt64() const
Returns the 64bit Integer value.
Definition: Value.cpp:546
bool HasComment() const
Checks if the internal value has a comment.
Definition: Value.cpp:220
virtual bool IsInt(const std::string &key) const override
Checks if the value stored at the specific key is an Integer.
Definition: Object.cpp:163
virtual Array GetArray(const std::string &key) const override
Returns the Array value stored at the given key.
Definition: Object.cpp:295
virtual bool IsNumber() const
Checks if the value stored is a Number.
Definition: Value.cpp:384