| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197 |
- $#include "Resource/JSONValue.h"
- enum JSONValueType
- {
- JSON_NULL = 0,
- JSON_BOOL,
- JSON_NUMBER,
- JSON_STRING,
- JSON_ARRAY,
- JSON_OBJECT
- };
- enum JSONNumberType
- {
- JSONNT_NAN = 0,
- JSONNT_INT,
- JSONNT_UINT,
- JSONNT_FLOAT_DOUBLE
- };
- class JSONValue
- {
- JSONValue();
- JSONValue(bool value);
- JSONValue(const char* value); // This works for Lua string and Urho3D:String
- JSONValue(double value); // This works for all number types, must be declared after string overload
- JSONValue(const JSONArray& value);
- JSONValue(const JSONObject& value);
- JSONValue(const JSONValue& value);
- ~JSONValue();
- tolua_outside void JSONValueSetBool @ SetBool(bool value);
- tolua_outside void JSONValueSetInt @ SetInt(int value);
- tolua_outside void JSONValueSetUint @ SetUint(unsigned value);
- tolua_outside void JSONValueSetFloat @ SetFloat(float value);
- tolua_outside void JSONValueSetDouble @ SetDouble(double value);
- tolua_outside void JSONValueSetString @ SetString(const String value);
- tolua_outside void JSONValueSetArray @ SetArray(const JSONArray& value);
- tolua_outside void JSONValueSetObject @ SetObject(const JSONObject& value);
- void SetVariant(const Variant& value);
- void SetVariantMap(const VariantMap& value);
- JSONValueType GetValueType() const;
- JSONNumberType GetNumberType() const;
- String GetValueTypeName() const;
- String GetNumberTypeName() const;
- bool IsNull() const;
- bool IsBool() const;
- bool IsNumber() const;
- bool IsString() const;
- bool IsArray() const;
- bool IsObject() const;
- bool GetBool() const;
- int GetInt() const;
- unsigned GetUInt() const;
- float GetFloat() const;
- double GetDouble() const;
- const String GetString() const;
- const JSONArray& GetArray() const;
- const JSONObject& GetObject() const;
- Variant GetVariant() const;
- VariantMap GetVariantMap() const;
- JSONValue& operator [](unsigned index);
- const JSONValue& operator [](unsigned index) const;
- void Push(const JSONValue& value);
- void Pop();
- void Insert(unsigned pos, const JSONValue& value);
- void Erase(unsigned pos, unsigned length = 1);
- void Resize(unsigned newSize);
- unsigned Size() const;
- // JSONValue& operator [](const String key);
- // const JSONValue& operator [](const String key) const;
- void Set(const String key, const JSONValue& value);
- const JSONValue& Get(const String key) const;
- bool Erase(const String key);
- bool Contains(const String key) const;
- void Clear();
- static const JSONValue EMPTY;
- static const JSONArray emptyArray;
- static const JSONObject emptyObject;
- tolua_readonly tolua_property__is_set bool null;
- tolua_readonly tolua_property__get_set JSONValueType valueType;
- tolua_readonly tolua_property__get_set JSONNumberType numberType;
- tolua_readonly tolua_property__get_set String valueTypeName;
- tolua_readonly tolua_property__get_set String numberTypeName;
- };
- ${
- static void JSONValueSetBool(JSONValue* jsonValue, bool value)
- {
- (*jsonValue) = value;
- }
- static void JSONValueSetInt(JSONValue* jsonValue, int value)
- {
- (*jsonValue) = value;
- }
- static void JSONValueSetUint(JSONValue* jsonValue, unsigned value)
- {
- (*jsonValue) = value;
- }
- static void JSONValueSetFloat(JSONValue* jsonValue, float value)
- {
- (*jsonValue) = value;
- }
- static void JSONValueSetDouble(JSONValue* jsonValue, double value)
- {
- (*jsonValue) = value;
- }
- static void JSONValueSetString(JSONValue* jsonValue, const String& value)
- {
- (*jsonValue) = value;
- }
- static void JSONValueSetArray(JSONValue* jsonValue, const JSONArray& value)
- {
- (*jsonValue) = value;
- }
- static void JSONValueSetObject(JSONValue* jsonValue, const JSONObject& value)
- {
- (*jsonValue) = value;
- }
- #define TOLUA_DISABLE_tolua_ResourceLuaAPI_JSONValue_SetVariant00
- static int tolua_ResourceLuaAPI_JSONValue_SetVariant00(lua_State* tolua_S)
- {
- #ifndef TOLUA_RELEASE
- tolua_Error tolua_err;
- if (
- !tolua_isusertype(tolua_S,1,"JSONValue",0,&tolua_err) ||
- (tolua_isvaluenil(tolua_S,2,&tolua_err) || !tolua_isusertype(tolua_S,2,"const Variant",0,&tolua_err)) ||
- !tolua_isnoobj(tolua_S,3,&tolua_err)
- )
- goto tolua_lerror;
- else
- #endif
- {
- JSONValue* self = (JSONValue*) tolua_tousertype(tolua_S,1,0);
- const Variant* value = ((const Variant*) tolua_tousertype(tolua_S,2,0));
- #ifndef TOLUA_RELEASE
- if (!self) tolua_error(tolua_S,"invalid 'self' in function 'SetVariant'", NULL);
- #endif
- {
- self->SetVariant(*value, GetContext(tolua_S));
- }
- }
- return 0;
- #ifndef TOLUA_RELEASE
- tolua_lerror:
- tolua_error(tolua_S,"#ferror in function 'SetVariant'.",&tolua_err);
- return 0;
- #endif
- }
- #define TOLUA_DISABLE_tolua_ResourceLuaAPI_JSONValue_SetVariantMap00
- static int tolua_ResourceLuaAPI_JSONValue_SetVariantMap00(lua_State* tolua_S)
- {
- #ifndef TOLUA_RELEASE
- tolua_Error tolua_err;
- if (
- !tolua_isusertype(tolua_S,1,"JSONValue",0,&tolua_err) ||
- (tolua_isvaluenil(tolua_S,2,&tolua_err) || !tolua_isusertype(tolua_S,2,"const VariantMap",0,&tolua_err)) ||
- !tolua_isnoobj(tolua_S,3,&tolua_err)
- )
- goto tolua_lerror;
- else
- #endif
- {
- JSONValue* self = (JSONValue*) tolua_tousertype(tolua_S,1,0);
- const VariantMap* value = ((const VariantMap*) tolua_tousertype(tolua_S,2,0));
- #ifndef TOLUA_RELEASE
- if (!self) tolua_error(tolua_S,"invalid 'self' in function 'SetVariantMap'", NULL);
- #endif
- {
- self->SetVariantMap(*value, GetContext(tolua_S));
- }
- }
- return 0;
- #ifndef TOLUA_RELEASE
- tolua_lerror:
- tolua_error(tolua_S,"#ferror in function 'SetVariantMap'.",&tolua_err);
- return 0;
- #endif
- }
- $}
|