TrueReality  v0.1.1912
Array.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 
23 #include <trUtil/JSON/Array.h>
24 
25 #include <trUtil/JSON/Object.h>
26 #include <trUtil/Logging/Log.h>
27 
28 #include <iostream>
29 
30 namespace trUtil::JSON
31 {
34  {
35  }
36 
39  {
40  mRoot = Array;
41  }
42 
45  {
46  }
47 
50  {
51  if (index < 0)
52  {
53  LOG_E("Array Index cannot be negative!");
54  }
55  return mRoot.Index(index);
56  }
57 
59  void Array::SetComment(const std::string& comment)
60  {
61  mRoot.SetComment(comment);
62  }
63 
65  bool Array::HasComment() const
66  {
67  return mRoot.HasComment();
68  }
69 
71  std::string Array::GetComment() const
72  {
73  return mRoot.GetComment();
74  }
77  {
78  return mRoot.Size();
79  }
80 
82  void Array::Resize(int newSize)
83  {
84  mRoot.Resize(newSize);
85  }
86 
88  void Array::Clear()
89  {
90  mRoot.Clear();
91  }
92 
94  bool Array::RemoveIndex(int index, Value *removedVal)
95  {
96  return mRoot.RemoveIndex(index, removedVal);
97  }
98 
101  {
102  return mRoot;
103  }
104 
107  {
108  std::cout << mRoot << std::endl;
109  }
110 
112  bool Array::IsNull(int &index) const
113  {
114  return mRoot.IsNull(index);
115  }
116 
119  {
120  mRoot.Append(Value());
121  }
122 
124  bool Array::IsBool(int &index) const
125  {
126  return mRoot.IsBool(index);
127  }
128 
130  bool Array::GetBool(int &index) const
131  {
132  return mRoot.GetBool(index);
133  }
134 
136  void Array::AddBool(const bool &value)
137  {
138  mRoot.Append(value);
139  }
140 
142  bool Array::IsTrue(int &index) const
143  {
144  if (GetBool(index) == true)
145  {
146  return true;
147  }
148  else
149  {
150  return false;
151  }
152  }
153 
155  bool Array::IsFalse(int &index) const
156  {
157  if (GetBool(index) == false)
158  {
159  return true;
160  }
161  else
162  {
163  return false;
164  }
165  }
166 
168  bool Array::IsNumber(int &index) const
169  {
170  return mRoot.IsNumber(index);
171  }
172 
174  bool Array::IsInt(int &index) const
175  {
176  return mRoot.IsInt(index);
177  }
178 
180  int Array::GetInt(int &index) const
181  {
182  return mRoot.GetInt(index);
183  }
184 
186  void Array::AddInt(const int &value)
187  {
188  mRoot.Append(value);
189  }
190 
192  bool Array::IsDouble(int &index) const
193  {
194  return mRoot.IsDouble(index);
195  }
196 
198  double Array::GetDouble(int &index) const
199  {
200  return mRoot.GetDouble(index);
201  }
202 
204  void Array::AddDouble(const double &value)
205  {
206  mRoot.Append(value);
207  }
208 
210  bool Array::IsUInt(int &index) const
211  {
212  return mRoot.IsUInt(index);
213  }
214 
216  unsigned int Array::GetUInt(int &index) const
217  {
218  return mRoot.GetUInt(index);
219  }
220 
222  void Array::AddUInt(const unsigned int &value)
223  {
224  mRoot.Append(value);
225  }
226 
228  bool Array::IsInt64(int &index) const
229  {
230  return mRoot.IsInt64(index);
231  }
232 
234  Int64 Array::GetInt64(int &index) const
235  {
236  return mRoot.GetInt64(index);
237  }
238 
240  void Array::AddInt64(const Int64 &value)
241  {
242  mRoot.Append(value);
243  }
244 
246  bool Array::IsUInt64(int &index) const
247  {
248  return mRoot.IsUInt64(index);
249  }
250 
252  UInt64 Array::GetUInt64(int &index) const
253  {
254  return mRoot.GetUInt64(index);
255  }
256 
258  void Array::AddUInt64(const UInt64 &value)
259  {
260  mRoot.Append(value);
261  }
262 
264  bool Array::IsFloat(int &index) const
265  {
266  return mRoot.IsFloat(index);
267  }
268 
270  float Array::GetFloat(int &index) const
271  {
272  return mRoot.GetFloat(index);
273  }
274 
276  void Array::AddFloat(const float &value)
277  {
278  mRoot.Append(value);
279  }
280 
282  bool Array::IsString(int &index) const
283  {
284  return mRoot.IsString(index);
285  }
286 
288  const std::string Array::GetString(int &index) const
289  {
290  return mRoot.GetString(index);
291  }
292 
294  void Array::AddString(const std::string &value)
295  {
296  mRoot.Append(value);
297  }
298 
300  bool Array::IsArray(int &index) const
301  {
302  return mRoot.IsArray(index);
303  }
304 
306  Array Array::GetArray(int &index) const
307  {
308  return mRoot.GetArray(index);
309  }
310 
313  {
314  mRoot.Append(Array.GetJSONRoot());
315  }
316 
318  bool Array::IsObject(int &index) const
319  {
320  return mRoot.IsObject(index);
321  }
322 
324  Object Array::GetObject(int &index) const
325  {
326  return mRoot.GetObject(index);
327  }
328 
331  {
332  mRoot.Append(Object.GetJSONRoot());
333  }
334 }
virtual bool IsArray() const
Checks if the value stored is an Array.
Definition: Value.cpp:696
virtual UInt64 GetUInt64(int &index) const override
Returns the 64bit Integer value stored at the given index.
Definition: Array.cpp:252
virtual bool IsUInt64() const
Checks if the value stored is a 64bit Unsigned Integer.
Definition: Value.cpp:570
virtual bool IsBool() const
Checks if the value stored is a Boolean.
Definition: Value.cpp:342
void Clear() override
Clears the internal JSON Root node.
Definition: Array.cpp:88
virtual void AddBool(const bool &value) override
Adds a Boolean to the Array.
Definition: Array.cpp:136
std::string GetComment() const
Returns the internal comment.
Definition: Value.cpp:226
int Size()
Returns the size of the array.
Definition: Value.cpp:246
virtual double GetDouble(int &index) const override
Returns the Double value stored at the given index.
Definition: Array.cpp:198
virtual bool IsInt() const
Checks if the value stored is an Integer.
Definition: Value.cpp:402
virtual Array GetArray(int &index) const override
Returns the Array value stored at the given index.
Definition: Array.cpp:306
virtual Object GetObject(int &index) const override
Returns the Object value stored at the given index.
Definition: Array.cpp:324
void Resize(int newSize)
Change the size of the array.
Definition: Value.cpp:252
Value operator[](int index)
Access an array element (zero based index ).
Definition: Array.cpp:49
virtual bool IsUInt() const
Checks if the value stored Unsigned Integer.
Definition: Value.cpp:486
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
bool RemoveIndex(int index, Value *removedVal)
Removes a given element of the array.
Definition: Array.cpp:94
virtual void PrintJSONRoot() override
Prints out to the screen the whole JSON Root content.
Definition: Array.cpp:106
virtual bool IsObject(int &index) const override
Checks if the value stored at the specific index is an Object.
Definition: Array.cpp:318
virtual bool IsUInt64(int &index) const override
Checks if the value stored at the specific index is a 64bit Integer.
Definition: Array.cpp:246
A JSON array.
Definition: Array.h:46
int Size()
Get the size of the array.
Definition: Array.cpp:76
virtual void AddArray(Array &Array) override
Adds the Array to the Array.
Definition: Array.cpp:312
virtual bool IsFalse(int &index) const override
Checks if the value stored at the specific index is False.
Definition: Array.cpp:155
virtual bool IsArray(int &index) const override
Checks if the value stored at the specific index is an Array.
Definition: Array.cpp:300
virtual int GetInt() const
Returns the Integer value.
Definition: Value.cpp:420
virtual bool IsNull(int &index) const override
Checks if the value stored at the specific index is a NULL.
Definition: Array.cpp:112
bool RemoveIndex(int index, Value *removedVal)
Remove the given Index value.
Definition: Value.cpp:264
virtual void AddNull() override
Add a NULL Value to the Array.
Definition: Array.cpp:118
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 Int64 GetInt64(int &index) const override
Returns the 64bit Integer value stored at the given index.
Definition: Array.cpp:234
virtual Value & GetJSONRoot() override
Returns a reference to the internal JSON Root node.
Definition: Object.cpp:75
virtual bool IsDouble(int &index) const override
Checks if the value stored at the specific index is a Double.
Definition: Array.cpp:192
Represents a JSON value.
Definition: Value.h:139
virtual void AddInt(const int &value) override
Adds the Integer value to the Array.
Definition: Array.cpp:186
~Array()
dtor.
Definition: Array.cpp:44
int64_t Int64
The fourth int 6.
Definition: Value.h:72
virtual bool IsInt(int &index) const override
Checks if the value stored at the specific index is an Integer.
Definition: Array.cpp:174
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 bool IsNumber(int &index) const override
Checks if the value stored at the specific index is a Number.
Definition: Array.cpp:168
virtual void AddFloat(const float &value) override
Adds the float value to the Array.
Definition: Array.cpp:276
virtual bool GetBool() const
Returns the Boolean value.
Definition: Value.cpp:360
Value mRoot
The root.
Definition: Array.h:533
virtual Value & GetJSONRoot() override
Returns a reference to the internal JSON Root node.
Definition: Array.cpp:100
Forward declaration.
Definition: Object.h:46
virtual bool GetBool(int &index) const override
Returns the Boolean value stored at the given index.
Definition: Array.cpp:130
virtual const std::string GetString(int &index) const override
Returns the String value stored at the given index.
Definition: Array.cpp:288
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 UInt64 GetUInt64() const
Returns the Unsigned 64bit Integer value.
Definition: Value.cpp:588
virtual void Append(const Value &val)
Add a value at the end of the array.
Definition: Value.cpp:336
#define LOG_E(msg)
Log an ERROR message.
Definition: Log.h:165
void SetComment(const std::string &comment)
Sets a comment.
Definition: Array.cpp:59
virtual void AddString(const std::string &value) override
Adds the String to the Array.
Definition: Array.cpp:294
virtual int GetInt(int &index) const override
Returns the Integer value stored at the given index.
Definition: Array.cpp:180
virtual void AddUInt64(const UInt64 &value) override
Adds the 64bit Integer value to the Array.
Definition: Array.cpp:258
std::string GetComment() const
Returns the internal comment.
Definition: Array.cpp:71
virtual void AddInt64(const Int64 &value) override
Adds the 64bit Integer value to the Array.
Definition: Array.cpp:240
virtual void AddUInt(const unsigned int &value) override
Adds the Unsigned Integer value the Array.
Definition: Array.cpp:222
virtual const Array GetArray() const
Returns the Array value stored.
Definition: Value.cpp:714
virtual bool IsInt64(int &index) const override
Checks if the value stored at the specific index is a 64bit Integer.
Definition: Array.cpp:228
virtual float GetFloat(int &index) const override
Returns the float value stored at the given index.
Definition: Array.cpp:270
void SetComment(const std::string &comment)
Adds a comment to the internal value.
Definition: Value.cpp:214
virtual void AddObject(Object &Object) override
Adds the Object to the Array.
Definition: Array.cpp:330
virtual bool IsInt64() const
Checks if the value stored is a 64bit Integer.
Definition: Value.cpp:528
Value Index(int index)
Returns the Value at the given index if this Value is an Array The return is by value, but the internal json object is stored by reference.
Definition: Value.cpp:270
virtual const Object GetObject() const
Returns the Object value stored.
Definition: Value.cpp:759
virtual unsigned int GetUInt(int &index) const override
Returns the Unsigned Integer value stored at the given index.
Definition: Array.cpp:216
virtual void AddDouble(const double &value) override
Adds the Double value to the Array.
Definition: Array.cpp:204
bool HasComment() const
Checks if the internal value has a comment.
Definition: Array.cpp:65
virtual bool IsString(int &index) const override
Checks if the value stored at the specific index is a String.
Definition: Array.cpp:282
virtual bool IsFloat(int &index) const override
Checks if the value stored at the specific index is a float.
Definition: Array.cpp:264
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 bool IsTrue(int &index) const override
Checks if the value stored at the specific index is True.
Definition: Array.cpp:142
virtual bool IsUInt(int &index) const override
Checks if the value stored at the specific index is an Unsigned Integer.
Definition: Array.cpp:210
uint64_t UInt64
The fourth u int 6.
Definition: Value.h:74
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 IsBool(int &index) const override
Checks if the value stored at the specific index is a Boolean.
Definition: Array.cpp:124
void Resize(int newSize)
Change the size of the array to the new passed in size.
Definition: Array.cpp:82
virtual bool IsNumber() const
Checks if the value stored is a Number.
Definition: Value.cpp:384