Rebel Fork Framework
Urho3D::JSONValue Class Reference

JSON value class. More...

#include <Urho3D/Resource/JSONValue.h>

Public Member Functions

 JSONValue ()
 Construct null value.
 
 JSONValue (JSONValueType valueType, JSONNumberType numberType=JSONNT_NAN)
 Construct a default value with defined type.
 
 JSONValue (bool value)
 Construct with a boolean.
 
 JSONValue (int value)
 Construct with a integer.
 
 JSONValue (unsigned value)
 Construct with a unsigned integer.
 
 JSONValue (float value)
 Construct with a float.
 
 JSONValue (double value)
 Construct with a double.
 
 JSONValue (const ea::string &value)
 Construct with a string.
 
 JSONValue (const char *value)
 Construct with a C string.
 
 JSONValue (const ea::vector< JSONValue > &value)
 Construct with a JSON array.
 
 JSONValue (const ea::map< ea::string, JSONValue > &value)
 Construct with a JSON object.
 
 JSONValue (const JSONValue &value)
 Copy-construct from another JSON value.
 
 JSONValue (JSONValue &&value)
 Move-construct from another JSON value.
 
 ~JSONValue ()
 Destruct.
 
JSONValueoperator= (bool rhs)
 Assign from a boolean.
 
JSONValueoperator= (int rhs)
 Assign from an integer.
 
JSONValueoperator= (unsigned rhs)
 Assign from an unsigned integer.
 
JSONValueoperator= (float rhs)
 Assign from a float.
 
JSONValueoperator= (double rhs)
 Assign from a double.
 
JSONValueoperator= (const ea::string &rhs)
 Assign from a string.
 
JSONValueoperator= (const char *rhs)
 Assign from a C string.
 
JSONValueoperator= (const ea::vector< JSONValue > &rhs)
 Assign from a JSON array.
 
JSONValueoperator= (const ea::map< ea::string, JSONValue > &rhs)
 Assign from a JSON object.
 
JSONValueoperator= (const JSONValue &rhs)
 Assign from another JSON value.
 
JSONValueoperator= (JSONValue &&rhs)
 Move-assign from another JSON value.
 
bool operator== (const JSONValue &rhs) const
 Value equality operator.
 
bool operator!= (const JSONValue &rhs) const
 Value inequality operator.
 
JSONValueType GetValueType () const
 
JSONNumberType GetNumberType () const
 
ea::string GetValueTypeName () const
 
ea::string GetNumberTypeName () const
 
bool IsNull () const
 
bool IsBool () const
 
bool IsNumber () const
 
bool IsString () const
 
bool IsArray () const
 
bool IsObject () const
 
bool GetBool (bool defaultValue=false) const
 Return boolean value.
 
int GetInt (int defaultValue=0) const
 Return integer value.
 
unsigned GetUInt (unsigned defaultValue=0) const
 Return unsigned integer value.
 
float GetFloat (float defaultValue=0.0f) const
 Return float value.
 
double GetDouble (double defaultValue=0.0) const
 Return double value.
 
const ea::string & GetString (const ea::string &defaultValue=EMPTY_STRING) const
 Return string value. The 'defaultValue' may potentially be returned as is, so it is the responsibility of the caller to ensure the 'defaultValue' remains valid while the return value is being referenced.
 
const char * GetCString (const char *defaultValue="") const
 Return C string value. Default to empty string literal.
 
const ea::vector< JSONValue > & GetArray () const
 Return JSON array value.
 
const ea::map< ea::string, JSONValue > & GetObject () const
 Return JSON object value.
 
JSONValueoperator[] (unsigned index)
 Return JSON value at index.
 
const JSONValueoperator[] (unsigned index) const
 Return JSON value at index.
 
void Push (JSONValue value)
 Add JSON value at end.
 
void Pop ()
 Remove the last JSON value.
 
void Insert (unsigned pos, JSONValue value)
 Insert an JSON value at position.
 
void Erase (unsigned pos, unsigned length=1)
 Erase a range of JSON values.
 
void Resize (unsigned newSize)
 Resize array.
 
unsigned Size () const
 
JSONValueoperator[] (const ea::string &key)
 Return JSON value with key.
 
const JSONValueoperator[] (const ea::string &key) const
 Return JSON value with key.
 
void Set (const ea::string &key, JSONValue value)
 Set JSON value with key.
 
const JSONValueGet (const ea::string &key) const
 Return JSON value with key.
 
const JSONValueGet (int index) const
 Return JSON value with index.
 
bool Erase (const ea::string &key)
 Erase a pair by key.
 
bool Contains (const ea::string &key) const
 Return whether contains a pair with key.
 
void Clear ()
 Clear array or object.
 
void SetType (JSONValueType valueType, JSONNumberType numberType=JSONNT_NAN)
 Set value type and number type, internal function.
 
void SetVariant (const Variant &variant, Context *context=nullptr)
 Set variant, context must provide for resource ref.
 
Variant GetVariant () const
 Return a variant.
 
void SetVariantValue (const Variant &variant, Context *context=nullptr)
 Set variant value, context must provide for resource ref.
 
Variant GetVariantValue (VariantType type, Context *context=nullptr) const
 Return a variant with type, context must be provided for serializables.
 
void SetVariantMap (const VariantMap &variantMap, Context *context=nullptr)
 Set variant map, context must provide for resource ref.
 
VariantMap GetVariantMap () const
 Return a variant map. More...
 
void SetVariantVector (const VariantVector &variantVector, Context *context=nullptr)
 Set variant vector, context must provide for resource ref.
 
VariantVector GetVariantVector () const
 Return a variant vector.
 
void SetStringVariantMap (const StringVariantMap &variantMap, Context *context=nullptr)
 Set string variant map, context must provide for resource ref.
 
StringVariantMap GetStringVariantMap () const
 Return a string variant map.
 

Static Public Member Functions

static ea::string GetValueTypeName (JSONValueType type)
 Return name corresponding to a value type.
 
static ea::string GetNumberTypeName (JSONNumberType type)
 Return name corresponding to a number type.
 
static JSONValueType GetValueTypeFromName (const ea::string &typeName)
 Return a value type from name; null if unrecognized.
 
static JSONValueType GetValueTypeFromName (const char *typeName)
 Return a value type from name; null if unrecognized.
 
static JSONNumberType GetNumberTypeFromName (const ea::string &typeName)
 Return a number type from name; NaN if unrecognized.
 
static JSONNumberType GetNumberTypeFromName (const char *typeName)
 Return a value type from name; NaN if unrecognized.
 

Static Public Attributes

static const JSONValue EMPTY
 Empty JSON value.
 
static const ea::vector< JSONValueemptyArray { }
 Empty JSON array.
 
static const ea::map< ea::string, JSONValueemptyObject
 Empty JSON object.
 

Protected Attributes

unsigned type_
 type.
 
union {
   bool   boolValue_
 
   double   numberValue_
 
   ea::string *   stringValue_
 
   ea::vector< JSONValue > *   arrayValue_
 
   ea::map< ea::string, JSONValue > *   objectValue_
 
}; 
 

Friends

URHO3D_API ea::map< ea::string, JSONValue >::iterator begin (JSONValue &value)
 Return iterator to the beginning.
 
URHO3D_API ea::map< ea::string, JSONValue >::const_iterator begin (const JSONValue &value)
 Return iterator to the beginning.
 
URHO3D_API ea::map< ea::string, JSONValue >::iterator end (JSONValue &value)
 Return iterator to the end.
 
URHO3D_API ea::map< ea::string, JSONValue >::const_iterator end (const JSONValue &value)
 Return iterator to the beginning.
 

Detailed Description

JSON value class.

Member Function Documentation

◆ GetNumberType()

JSONNumberType Urho3D::JSONValue::GetNumberType ( ) const

Return number type.

◆ GetNumberTypeName()

ea::string Urho3D::JSONValue::GetNumberTypeName ( ) const

Return number type's name.

◆ GetValueType()

JSONValueType Urho3D::JSONValue::GetValueType ( ) const

Return value type.

◆ GetValueTypeName()

ea::string Urho3D::JSONValue::GetValueTypeName ( ) const

Return value type's name.

◆ GetVariantMap()

VariantMap Urho3D::JSONValue::GetVariantMap ( ) const

Return a variant map.

◆ IsArray()

bool Urho3D::JSONValue::IsArray ( ) const
inline

Check is array.

◆ IsBool()

bool Urho3D::JSONValue::IsBool ( ) const
inline

Check is boolean.

◆ IsNull()

bool Urho3D::JSONValue::IsNull ( ) const
inline

Check is null.

◆ IsNumber()

bool Urho3D::JSONValue::IsNumber ( ) const
inline

Check is number.

◆ IsObject()

bool Urho3D::JSONValue::IsObject ( ) const
inline

Check is object.

◆ IsString()

bool Urho3D::JSONValue::IsString ( ) const
inline

Check is string.

◆ Size()

unsigned Urho3D::JSONValue::Size ( ) const

Return size of array or number of keys in object.

Member Data Documentation

◆ arrayValue_

ea::vector<JSONValue>* Urho3D::JSONValue::arrayValue_

Array value.

◆ boolValue_

bool Urho3D::JSONValue::boolValue_

Boolean value.

◆ numberValue_

double Urho3D::JSONValue::numberValue_

Number value.

◆ objectValue_

ea::map<ea::string, JSONValue>* Urho3D::JSONValue::objectValue_

Object value.

◆ stringValue_

ea::string* Urho3D::JSONValue::stringValue_

String value.


The documentation for this class was generated from the following files: