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 asJSON() const = 0;
41
48 virtual std::string asString() const = 0;
49
54 bool isArray() const {return (getType() == Type::ARRAY);}
55
60 bool isBoolean() const {return (getType() == Type::BOOLEAN);}
61
66 bool isNull() const {return (getType() == Type::NULLISH);}
67
72 bool isNumber() const {return (getType() == Type::NUMBER);}
73
78 bool isObject() const {return (getType() == Type::OBJECT);}
79
84 bool isString() const {return (getType() == Type::STRING);}
85
90 bool isUndefined() const {return (getType() == Type::UNDEFINED);}
91
92
98 static std::string typeToString(const enum Type type) {
99 switch (type) {
100 case UNDEFINED:
101 return "UNDEFINED";
102 case NULLISH:
103 return "NULLISH";
104 case OBJECT:
105 return "OBJECT";
106 case ARRAY:
107 return "ARRAY";
108 case NUMBER:
109 return "NUMBER";
110 case STRING:
111 return "STRING";
112 case BOOLEAN:
113 return "BOOLEAN";
114 default:
115 return "(INVALID TYPE)";
116 }
117 }
118
119};
120
121}}
122
123#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:78
bool isNull() const
Utility to check if this element is null.
Definition JSONElement.h:66
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:90
bool isNumber() const
Utility to check if this element is JSONNumber.
Definition JSONElement.h:72
static std::string typeToString(const enum Type type)
Converts the type to string.
Definition JSONElement.h:98
bool isArray() const
Utility to check if this element is JSONArray.
Definition JSONElement.h:54
virtual std::string asString() const =0
Gets the value of the element as a string.
virtual std::string asJSON() const =0
Serializes the element as JSON.
Type
Type of the element.
Definition JSONElement.h:17
bool isString() const
Utility to check if this element is JSONString.
Definition JSONElement.h:84
bool isBoolean() const
Utility to check if this element is JSONBoolean.
Definition JSONElement.h:60
JSON support.
Definition JSONArray.h:10
Root for classes, functions and globals of 10Duke C++ Client.
Definition AbstractClientFactory.h:16