10Duke Scale C++ Client
Loading...
Searching...
No Matches
JSONElement.h
1#ifndef TENDUKE_JSON_JSONELEMENT_H
2#define TENDUKE_JSON_JSONELEMENT_H
3
4#include <string>
5
6namespace tenduke { namespace json {
7
12{
13public:
17 enum Type {
18 UNDEFINED,
19 NULLISH,
20 OBJECT,
21 ARRAY,
22 NUMBER,
23 STRING,
24 BOOLEAN
25 };
26
27public:
28 virtual ~JSONElement() = default;
29
34 virtual enum Type getType() const = 0;
35
40 virtual std::string asString() const = 0;
41
46 bool isArray() const {return (getType() == Type::ARRAY);}
47
52 bool isBoolean() const {return (getType() == Type::BOOLEAN);}
53
58 bool isNull() const {return (getType() == Type::NULLISH);}
59
64 bool isNumber() const {return (getType() == Type::NUMBER);}
65
70 bool isObject() const {return (getType() == Type::OBJECT);}
71
76 bool isString() const {return (getType() == Type::STRING);}
77
82 bool isUndefined() const {return (getType() == Type::UNDEFINED);}
83
84
90 static std::string typeToString(const enum Type type) {
91 switch (type) {
92 case UNDEFINED:
93 return "UNDEFINED";
94 case NULLISH:
95 return "NULLISH";
96 case OBJECT:
97 return "OBJECT";
98 case ARRAY:
99 return "ARRAY";
100 case NUMBER:
101 return "NUMBER";
102 case STRING:
103 return "STRING";
104 case BOOLEAN:
105 return "BOOLEAN";
106 default:
107 return "(INVALID TYPE)";
108 }
109 }
110
111};
112
113}}
114
115#endif // TENDUKE_JSON_JSONELEMENT_H
Superclass of JSON elements.
Definition JSONElement.h:12
bool isObject() const
Utility to check if this element is JSONObject.
Definition JSONElement.h:70
bool isNull() const
Utility to check if this element is null.
Definition JSONElement.h:58
virtual enum Type getType() const =0
Returns type of this element.
bool isUndefined() const
Utility to check if this element is undefined.
Definition JSONElement.h:82
bool isNumber() const
Utility to check if this element is JSONNumber.
Definition JSONElement.h:64
static std::string typeToString(const enum Type type)
Converts the type to string.
Definition JSONElement.h:90
bool isArray() const
Utility to check if this element is JSONArray.
Definition JSONElement.h:46
virtual std::string asString() const =0
Returns string representation of this element.
Type
Type of the element.
Definition JSONElement.h:17
bool isString() const
Utility to check if this element is JSONString.
Definition JSONElement.h:76
bool isBoolean() const
Utility to check if this element is JSONBoolean.
Definition JSONElement.h:52
JSON support.
Definition JSONArray.h:10
Root for classes, functions and globals of 10Duke C++ Client.
Definition BackendConfiguration.h:7