TrueReality  v0.1.1912
Value.h
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 #pragma once
23 
24 #include <trUtil/Export.h>
25 
26 #include <ostream>
27 #include <memory>
28 #include <vector>
29 
30 // Forward declarations to avoid including Json/valu.h
31 namespace Json
32 {
38  class Value;
39 }
40 
46 namespace trUtil::JSON
47 {
51  class Array;
52  class Object;
53 
55  using Int = int;
57  using UInt = unsigned int;
58 #if defined(JSON_NO_INT64)
59 
60  using LargestInt = int;
62  using LargestUInt = unsigned int;
63 #else // if defined(JSON_NO_INT64)
64  // For Microsoft Visual use specific types as long long is not supported
65 #if defined(_MSC_VER) // Microsoft Visual Studio
66 
67  using Int64 = __int64;
69  using UInt64 = unsigned __int64;
70 #else // if defined(_MSC_VER) // Other platforms, use long long
71 
72  using Int64 = int64_t;
74  using UInt64 = uint64_t;
75 #endif // if defined(_MSC_VER)
76 
77  using LargestInt = Int64;
80 #endif // if defined(JSON_NO_INT64)
81 
89  enum ValueType
90  {
91  NullValue = 0,
92  IntValue = 1,
93  UintValue = 2,
94  RealValue = 3,
97  ArrayValue = 6,
99  };
100 
140  {
141  public:
142 
144  using Members = std::vector<std::string>;
145 
153  Value(Json::Value& value);
154 
162  Value(ValueType type = NullValue);
163 
171  Value(Int value);
172 
180  Value(UInt value);
181 
189  Value(Int64 value);
190 
198  Value(UInt64 value);
199 
207  Value(double value);
208 
216  Value(const char* value);
217 
226  Value(const char* begin, const char* end);
227 
235  Value(const std::string& value);
236 
244  Value(bool value);
245 
253  Value(const Value& other);
254 
265  //Value(Value&& other);
266 
272  ~Value();
273 
281  Json::Value& GetJsonValue();
282 
290  const Json::Value& GetJsonValue() const;
291 
299  void SetComment(const std::string& comment);
300 
308  bool HasComment() const;
309 
317  std::string GetComment() const;
318 
324  virtual void Clear();
325 
333  int Size();
334 
342  void Resize(int newSize);
343 
353  bool IsValidIndex(int index) const;
354 
365  bool RemoveIndex(int index, Value *removedVal);
366 
377  Value Index(int index);
378 
386  const Value::Members GetMemberNames() const;
387 
397  bool HasMember(const std::string& key) const;
398 
408  virtual bool KeyPresent(const std::string &key) const;
409 
417  virtual bool IsNull() const;
418 
428  virtual bool IsNull(const int index) const;
429 
439  virtual bool IsNull(const std::string& key) const;
440 
448  virtual void SetNull(const std::string& key) const;
449 
457  virtual bool IsEmpty() const;
458 
468  virtual bool IsEmpty(const int index) const;
469 
479  virtual bool IsEmpty(const std::string& key) const;
480 
488  virtual void Append(const Value& val);
489 
497  virtual bool IsBool() const;
498 
508  virtual bool IsBool(const int index) const;
509 
519  virtual bool IsBool(const std::string& key) const;
520 
528  virtual bool GetBool() const;
529 
539  virtual bool GetBool(const int index) const;
540 
550  virtual bool GetBool(const std::string& key) const;
551 
560  virtual void SetBool(const std::string& key, bool value);
561 
569  virtual bool IsNumber() const;
570 
580  virtual bool IsNumber(const int index) const;
581 
591  virtual bool IsNumber(const std::string& key) const;
592 
600  virtual bool IsInt() const;
601 
611  virtual bool IsInt(const int index) const;
612 
622  virtual bool IsInt(const std::string& key) const;
623 
631  virtual int GetInt() const;
632 
642  virtual int GetInt(const int index) const;
643 
653  virtual int GetInt(const std::string& key) const;
654 
663  virtual void SetInt(const std::string& key, int value);
664 
672  virtual bool IsDouble() const;
673 
683  virtual bool IsDouble(const int index) const;
684 
694  virtual bool IsDouble(const std::string& key) const;
695 
703  virtual double GetDouble() const;
704 
714  virtual double GetDouble(const int index) const;
715 
725  virtual double GetDouble(const std::string& key) const;
726 
735  virtual void SetDouble(const std::string& key, double value);
736 
744  virtual bool IsUInt() const;
745 
755  virtual bool IsUInt(const int index) const;
756 
766  virtual bool IsUInt(const std::string& key) const;
767 
775  virtual unsigned int GetUInt() const;
776 
786  virtual unsigned int GetUInt(const int index) const;
787 
797  virtual unsigned int GetUInt(const std::string& key) const;
798 
807  virtual void SetUInt(const std::string& key, unsigned int value);
808 
816  virtual bool IsInt64() const;
817 
827  virtual bool IsInt64(const int index) const;
828 
838  virtual bool IsInt64(const std::string& key) const;
839 
847  virtual Int64 GetInt64() const;
848 
858  virtual Int64 GetInt64(const int index) const;
859 
869  virtual Int64 GetInt64(const std::string& key) const;
870 
879  virtual void SetInt64(const std::string& key, Int64 value);
880 
888  virtual bool IsUInt64() const;
889 
899  virtual bool IsUInt64(const int index) const;
900 
910  virtual bool IsUInt64(const std::string& key) const;
911 
919  virtual UInt64 GetUInt64() const;
920 
930  virtual UInt64 GetUInt64(const int index) const;
931 
941  virtual UInt64 GetUInt64(const std::string& key) const;
942 
951  virtual void SetUInt64(const std::string& key, UInt64 value);
952 
960  virtual bool IsFloat() const;
961 
971  virtual bool IsFloat(const int index) const;
972 
982  virtual bool IsFloat(const std::string& key) const;
983 
991  virtual float GetFloat() const;
992 
1002  virtual float GetFloat(const int index) const;
1003 
1013  virtual float GetFloat(const std::string& key) const;
1014 
1023  virtual void SetFloat(const std::string& key, float value);
1024 
1032  virtual bool IsString() const;
1033 
1043  virtual bool IsString(const int index) const;
1044 
1054  virtual bool IsString(const std::string& key) const;
1055 
1063  virtual const std::string GetString() const;
1064 
1074  virtual const std::string GetString(const int index) const;
1075 
1085  virtual const std::string GetString(const std::string& key) const;
1086 
1095  virtual void SetString(const std::string& key, const std::string& value);
1096 
1104  virtual bool IsArray() const;
1105 
1115  virtual bool IsArray(const int index) const;
1116 
1126  virtual bool IsArray(const std::string& key) const;
1127 
1135  virtual const Array GetArray() const;
1136 
1146  virtual const Array GetArray(const int index) const;
1147 
1157  virtual const Array GetArray(const std::string& key) const;
1158 
1167  virtual void SetArray(const std::string& key, Array& value);
1168 
1176  virtual bool IsObject() const;
1177 
1187  virtual bool IsObject(const int index) const;
1188 
1198  virtual bool IsObject(const std::string& key) const;
1199 
1207  virtual const Object GetObject() const;
1208 
1218  virtual const Object GetObject(const int index) const;
1219 
1229  virtual const Object GetObject(const std::string& key) const;
1230 
1239  virtual void SetObject(const std::string& key, Object& value);
1240 
1248  operator Json::Value() const;
1249 
1257  operator Json::Value& ();
1258 
1266  operator const Json::Value& () const;
1267 
1275  operator Json::Value* ();
1276 
1283  //Value operator[](int index);
1284 
1288  //const Value operator[](int index) const;
1289 
1293  //Value operator[](const char* key);
1294 
1297  //const Value operator[](const char* key) const;
1298 
1301  //Value operator[](const std::string& key);
1302 
1315  Value& operator=(Value other);
1316 
1317  protected:
1318 
1320  bool clearInternalVal = true;
1322  Json::Value* mValuePtr = nullptr;
1323  };
1324 
1337  TR_UTIL_EXPORT std::ostream& operator<<(std::ostream&, const Value& root);
1338 }
array value (ordered list)
Definition: Value.h:98
unsigned integer value
Definition: Value.h:94
A JSON array.
Definition: Array.h:46
ValueType
Type of the value held by a Value object.
Definition: Value.h:89
A value.
Int64 LargestInt
The largest int.
Definition: Value.h:77
Represents a JSON value.
Definition: Value.h:139
int64_t Int64
The fourth int 6.
Definition: Value.h:72
UInt64 LargestUInt
The largest u int.
Definition: Value.h:79
Definition: Value.h:31
Forward declaration.
Definition: Object.h:46
unsigned int UInt
The int.
Definition: Value.h:57
int Int
The int.
Definition: Value.h:55
A class that represents date time utility.
double value
Definition: Value.h:95
&#39;null&#39; value
Definition: Value.h:92
signed integer value
Definition: Value.h:93
TR_UTIL_EXPORT std::ostream & operator<<(std::ostream &, const Value &root)
OStream operator.
Definition: Value.cpp:856
bool value
Definition: Value.h:97
uint64_t UInt64
The fourth u int 6.
Definition: Value.h:74
std::vector< std::string > Members
The members.
Definition: Value.h:144
UTF-8 string value.
Definition: Value.h:96