130 int size ()
const {
return this->_value.size(); }
143 const Value *v = (*this)[key];
144 return (v !=
nullptr) ? v->
asObject() :
nullptr;
151 const Value *v = (*this)[key];
152 return (v !=
nullptr) ? v->
asArray() :
nullptr;
159 const Value *v = (*this)[key];
160 return (v !=
nullptr) ? v->
asNumber() :
nullptr;
167 const Value *v = (*this)[key];
168 return (v !=
nullptr) ? v->
asInteger() :
nullptr;
175 const Value *v = (*this)[key];
176 return (v !=
nullptr) ? v->
asReal() :
nullptr;
183 const Value *v = (*this)[key];
184 return (v !=
nullptr) ? v->
asString() :
nullptr;
191 const Value *v = (*this)[key];
192 return (v !=
nullptr) ? v->
asBool() :
nullptr;
198 std::map<std::string, Value *> _value;
207 int length ()
const {
return static_cast<int>(this->_value.size()); }
215 std::vector<Value *> _value;
236 int64_t
intVal ()
const {
return this->_value; }
237 double realVal ()
const {
return static_cast<double>(this->_value); }
250 double realVal ()
const {
return this->_value; }
263 std::string
value ()
const {
return this->_value; }
276 bool value ()
const {
return this->_value; }
JSON arrays.
Definition json.hpp:202
void add(Value *v)
Definition json.hpp:208
int length() const
Definition json.hpp:207
Array()
Definition json.hpp:204
Value * operator[](int idx) const
Definition json.hpp:210
Bool(bool v)
Definition json.hpp:273
bool value() const
Definition json.hpp:276
double realVal() const
Definition json.hpp:237
Integer(int64_t v)
Definition json.hpp:233
int64_t intVal() const
Definition json.hpp:236
Null()
Definition json.hpp:286
base class for JSON numbers
Definition json.hpp:219
Number(Type ty)
Definition json.hpp:227
virtual double realVal() const =0
virtual std::string toString()=0
JSON objects.
Definition json.hpp:124
void insert(std::string key, Value *val)
insert a key-value pair into the object
const String * fieldAsString(std::string key) const
Definition json.hpp:181
const Real * fieldAsReal(std::string key) const
Definition json.hpp:173
const Object * fieldAsObject(std::string key) const
Definition json.hpp:141
Object()
Definition json.hpp:126
int size() const
return the number of fields in the object
Definition json.hpp:130
const Integer * fieldAsInteger(std::string key) const
Definition json.hpp:165
const Array * fieldAsArray(std::string key) const
Definition json.hpp:149
Value * operator[](std::string key) const
const Number * fieldAsNumber(std::string key) const
Definition json.hpp:157
const Bool * fieldAsBool(std::string key) const
Definition json.hpp:189
Real(double v)
Definition json.hpp:247
double realVal() const
Definition json.hpp:250
String(std::string v)
Definition json.hpp:260
std::string value() const
Definition json.hpp:263
const Number * asNumber() const
dynamic cast to JSON number
bool isNull() const
return true if this value is the null value
Definition json.hpp:85
bool isObject() const
return true if this value is an object
Definition json.hpp:61
Type type() const
return the type of this JSON value
Definition json.hpp:58
const Real * asReal() const
dynamic cast to JSON real number
Type _ty
Definition json.hpp:115
const Object * asObject() const
dynamic cast to JSON object
const Array * asArray() const
dynamic cast to JSON array
bool isBool() const
return true if this value is a boolean
Definition json.hpp:82
virtual std::string toString()=0
const Bool * asBool() const
dynamic cast to JSON boolean
const Integer * asInteger() const
dynamic cast to JSON integer
bool isNumber() const
return true if this value is a number
Definition json.hpp:67
bool isArray() const
return true if this value is an array
Definition json.hpp:64
bool isString() const
return true if this value is a string
Definition json.hpp:79
Value(Type ty)
Definition json.hpp:113
bool isInteger() const
return true if this value is an integer
Definition json.hpp:73
bool isReal() const
return true if this value is a real number
Definition json.hpp:76
const String * asString() const
dynamic cast to JSON string
Value * parseFile(std::string filename)
std::ostream & operator<<(std::ostream &s, Value *v)
Definition json.hpp:118
Type
the types of JSON values
Definition json.hpp:30
@ T_NULL
the null value
Definition json.hpp:37
@ T_REAL
real numbers (represented as doubles)
Definition json.hpp:34
@ T_ARRAY
arrays of JSON values
Definition json.hpp:32
@ T_BOOL
booleans
Definition json.hpp:36
@ T_STRING
strings
Definition json.hpp:35
@ T_INTEGER
integer numbers (represented as int64_t)
Definition json.hpp:33
@ T_OBJECT
object consisting of name-value pairs
Definition json.hpp:31