LeviLamina
Loading...
Searching...
No Matches
Value.h
1#pragma once
2
3#include "mc/_HeaderOutputPredefine.h"
4
5// auto generated inclusion list
6#include "mc/deps/json/ValueType.h"
7
8// auto generated forward declare list
9// clang-format off
10namespace Json { class ValueConstIterator; }
11namespace Json { class ValueIterator; }
12// clang-format on
13
14namespace Json {
15
16class Value {
17public:
18 // Value inner types declare
19 // clang-format off
20 class CZString;
21 struct CZStringCompare;
22 // clang-format on
23
24 // Value inner types define
25 using Members = ::std::vector<::std::string>;
26
28
30
31 using UInt = uint;
32
33 using Int = int;
34
35 using UInt64 = uint64;
36
37 using Int64 = int64;
38
39 using LargestInt = int64;
40
41 using LargestUInt = uint64;
42
43 using ArrayIndex = uint;
44
45 class CZString {
46 public:
47 // member variables
48 // NOLINTBEGIN
49 ::ll::TypedStorage<8, 8, char*> cstr_;
50 // NOLINTEND
51 public:
52 bool operator<(CZString const& other) const {
53 if (cstr_) {
54 return strcmp(cstr_, other.cstr_) < 0;
55 }
56 return false;
57 }
58 template <size_t N>
59 bool operator<(char const (&other)[N]) const {
60 return operator<(std::string_view{other, N - 1});
61 }
62 bool operator<(std::string_view other) const {
63 if (cstr_) {
64 return cstr_ < other;
65 }
66 return false;
67 }
68
69 public:
70 // member functions
71 // NOLINTBEGIN
72 MCAPI CZString(char const* cstr);
73
74 MCAPI ~CZString();
75 // NOLINTEND
76
77 public:
78 // constructor thunks
79 // NOLINTBEGIN
80 MCAPI void* $ctor(char const* cstr);
81 // NOLINTEND
82
83 public:
84 // destructor thunk
85 // NOLINTBEGIN
86 MCAPI void $dtor();
87 // NOLINTEND
88 };
89
91 public:
92 // CZStringCompare inner types define
93 using is_transparent = void;
94
95 public:
96 template <class T>
97 constexpr auto operator()(CZString const& l, T const& r) const {
98 return l < r;
99 }
100 template <class T>
101 constexpr auto operator()(T const& l, CZString const& r) const {
102 return l < r;
103 }
104 };
105
106 using ObjectValues = ::std::map<::Json::Value::CZString, ::Json::Value, ::Json::Value::CZStringCompare>;
107
108 using ArrayValues = ::std::vector<::Json::Value*>;
109
111 public:
112 // member variables
113 // NOLINTBEGIN
114 ::ll::TypedStorage<8, 8, int64> int_;
115 ::ll::TypedStorage<8, 8, uint64> uint_;
116 ::ll::TypedStorage<8, 8, double> real_;
117 ::ll::TypedStorage<1, 8, bool> bool_;
118 ::ll::TypedStorage<8, 8, ::Json::Value::CZString*> string_;
119 ::ll::TypedStorage<8, 8, ::std::map<::Json::Value::CZString, ::Json::Value, ::Json::Value::CZStringCompare>*>
120 map_;
121 ::ll::TypedStorage<8, 8, ::std::vector<::Json::Value*>*> array_;
122 // NOLINTEND
123 };
124
125public:
126 // member variables
127 // NOLINTBEGIN
129 ::Json::ValueType type_;
130 // NOLINTEND
131
132public:
133 using enum ::Json::ValueType;
134 static constexpr LargestInt minLargestInt = LargestInt(~(LargestUInt(-1) / 2));
135 static constexpr LargestInt maxLargestInt = LargestInt(LargestUInt(-1) / 2);
136 static constexpr LargestUInt maxLargestUInt = LargestUInt(-1);
137 static constexpr Int minInt = Int(~(UInt(-1) / 2));
138 static constexpr Int maxInt = Int(UInt(-1) / 2);
139 static constexpr UInt maxUInt = UInt(-1);
140 static constexpr Int64 minInt64 = Int64(~(UInt64(-1) / 2));
141 static constexpr Int64 maxInt64 = Int64(UInt64(-1) / 2);
142 static constexpr UInt64 maxUInt64 = UInt64(-1);
143 static constexpr UInt defaultRealPrecision = 17;
144 static constexpr double maxUInt64AsDouble = 18446744073709551615.0;
145
146 static bool IsIntegral(double d) {
147 double integral_part;
148 return modf(d, &integral_part) == 0.0;
149 }
150
151public:
152 ValueType type() const { return type_; }
153
154 operator bool() const { return !isNull(); }
155
156 bool isNull() const { return type() == NullValue; }
157
158 bool isBool() const { return type() == BooleanValue; }
159
160 bool isInt() const {
161 switch (type()) {
162 case IntValue:
163 return value_.int_ >= minInt && value_.int_ <= maxInt;
164 case UintValue:
165 return value_.uint_ <= UInt(maxInt);
166 case RealValue:
167 return value_.real_ >= minInt && value_.real_ <= maxInt && IsIntegral(value_.real_);
168 default:
169 break;
170 }
171 return false;
172 }
173
174 bool isUInt() const {
175 switch (type()) {
176 case IntValue:
177 return value_.int_ >= 0 && LargestUInt(value_.int_) <= LargestUInt(maxUInt);
178 case UintValue:
179 return value_.uint_ <= maxUInt;
180 case RealValue:
181 return value_.real_ >= 0 && value_.real_ <= maxUInt && IsIntegral(value_.real_);
182 default:
183 break;
184 }
185 return false;
186 }
187
188 bool isInt64() const {
189 switch (type()) {
190 case IntValue:
191 return true;
192 case UintValue:
193 return value_.uint_ <= UInt64(maxInt64);
194 case RealValue:
195 return value_.real_ > double(minInt64) && value_.real_ < double(maxInt64) && IsIntegral(value_.real_);
196 default:
197 break;
198 }
199 return false;
200 }
201
202 bool isUInt64() const {
203 switch (type()) {
204 case IntValue:
205 return value_.int_ >= 0;
206 case UintValue:
207 return true;
208 case RealValue:
209 return value_.real_ >= 0 && value_.real_ < maxUInt64AsDouble && IsIntegral(value_.real_);
210 default:
211 break;
212 }
213 return false;
214 }
215
216 bool isIntegral() const {
217 switch (type()) {
218 case IntValue:
219 case UintValue:
220 return true;
221 case RealValue:
222 return value_.real_ > double(minInt64) && value_.real_ < maxUInt64AsDouble && IsIntegral(value_.real_);
223 default:
224 break;
225 }
226 return false;
227 }
228
229 bool isDouble() const { return type() == IntValue || type() == UintValue || type() == RealValue; }
230
231 bool isNumeric() const { return isDouble(); }
232
233 bool isString() const { return type() == StringValue; }
234
235 bool isArray() const { return type() == ArrayValue; }
236
237 bool isObject() const { return type() == ObjectValue; }
238
239 Int64 asInt64(Int64 defaultValue = 0) const {
240 switch (type()) {
241 case IntValue:
242 return Int64(value_.int_);
243 case UintValue:
244 return isInt64() ? Int64(value_.uint_) : defaultValue;
245 case RealValue:
246 return isInt64() ? Int64(value_.real_) : defaultValue;
247 case NullValue:
248 return 0;
249 case BooleanValue:
250 return value_.bool_ ? 1 : 0;
251 default:
252 break;
253 }
254 return defaultValue;
255 }
256
257 UInt64 asUInt64(UInt64 defaultValue = 0) const {
258 switch (type()) {
259 case IntValue:
260 return isUInt64() ? UInt64(value_.int_) : defaultValue;
261 case UintValue:
262 return UInt64(value_.uint_);
263 case RealValue:
264 return isUInt64() ? UInt64(value_.real_) : defaultValue;
265 case NullValue:
266 return 0;
267 case BooleanValue:
268 return value_.bool_ ? 1 : 0;
269 default:
270 break;
271 }
272 return defaultValue;
273 }
274
275 Value& operator[](char const* key) { return operator[](std::string{key}); }
276 Value& operator[](int key) { return operator[](uint(key)); }
277 Value const& operator[](uint key) const { return operator[](int(key)); }
278
279 Value(Int value) : Value(IntValue) { value_.int_ = value; }
280 Value(UInt value) : Value(UintValue) { value_.uint_ = value; }
281
282 Value(Int64 value) : Value(IntValue) { value_.int_ = value; }
283 Value(UInt64 value) : Value(UintValue) { value_.uint_ = value; }
284
285 Value(double value) : Value(RealValue) { value_.real_ = value; }
286 Value(bool value) : Value(BooleanValue) { value_.bool_ = value; }
287
288public:
289 // member functions
290 // NOLINTBEGIN
291 MCAPI Value(::Json::Value const& other);
292
293 MCAPI Value(::Json::Value&& other);
294
295 MCAPI Value(::Json::ValueType type = NullValue);
296
297 MCAPI Value(char const* value);
298
299 MCAPI Value(::std::string const& value);
300
301 MCAPI ::Json::Value& _resolveReference(char const* key);
302
303 MCAPI ::Json::Value& append(::Json::Value&& value);
304
305 MCAPI ::Json::Value& append(::Json::Value const& value);
306
307 MCAPI bool asBool(bool defaultValue) const;
308
309 MCAPI double asDouble(double defaultValue) const;
310
311 MCAPI float asFloat(float defaultValue) const;
312
313 MCAPI int asInt(int defaultValue) const;
314
315 MCAPI ::std::string asString(::std::string const& defaultValue) const;
316
317 MCAPI uint asUInt(uint defaultValue) const;
318
319 MCFOLD ::Json::ValueConstIterator begin() const;
320
321 MCAPI ::Json::ValueIterator begin();
322
323 MCAPI void clear();
324
325 MCAPI bool empty() const;
326
327 MCAPI ::Json::ValueConstIterator end() const;
328
329 MCFOLD ::Json::ValueIterator end();
330
331 MCAPI ::Json::Value get(::std::string const& key, ::Json::Value const& defaultValue) const;
332
333 MCAPI ::Json::Value get(char const* key, ::Json::Value const& defaultValue) const;
334
335 MCAPI ::std::vector<::std::string> getMemberNames() const;
336
337 MCAPI bool isConvertibleTo(::Json::ValueType other) const;
338
339 MCAPI bool isMember(char const* key) const;
340
341 MCAPI bool isMember(::std::string const& key) const;
342
343 MCAPI bool operator!=(::Json::Value const& other) const;
344
345 MCAPI bool operator<(::Json::Value const& other) const;
346
347 MCAPI ::Json::Value& operator=(::Json::Value const& other);
348
349 MCAPI ::Json::Value& operator=(::Json::Value&& other);
350
351 MCAPI bool operator==(::Json::Value const& other) const;
352
353 MCAPI ::Json::Value const& operator[](int index) const;
354
355 MCAPI ::Json::Value const& operator[](char const* key) const;
356
357 MCAPI ::Json::Value const& operator[](::std::string const& key) const;
358
359 MCAPI ::Json::Value& operator[](uint index);
360
361 MCAPI ::Json::Value& operator[](::std::string const& key);
362
363 MCAPI ::Json::Value removeMember(char const* key);
364
365 MCAPI void resize(uint newSize);
366
367 MCAPI uint size() const;
368
369 MCAPI ::std::string toStyledString() const;
370
371 MCAPI ~Value();
372 // NOLINTEND
373
374public:
375 // static variables
376 // NOLINTBEGIN
377 MCAPI static ::Json::Value const& null();
378 // NOLINTEND
379
380public:
381 // constructor thunks
382 // NOLINTBEGIN
383 MCAPI void* $ctor(::Json::Value const& other);
384
385 MCAPI void* $ctor(::Json::Value&& other);
386
387 MCAPI void* $ctor(::Json::ValueType type);
388
389 MCAPI void* $ctor(char const* value);
390
391 MCAPI void* $ctor(::std::string const& value);
392 // NOLINTEND
393
394public:
395 // destructor thunk
396 // NOLINTBEGIN
397 MCAPI void $dtor();
398 // NOLINTEND
399};
400
401} // namespace Json
Definition ValueConstIterator.h:15
Definition ValueIterator.h:15
Definition Value.h:45
Definition Value.h:16
Definition Value.h:90
Definition Value.h:110