Browse Source

JSONFile
- SetRoot
+ GetRoot
JSONValue
Rename GetUint to GetUInt
- GetType
+ GetValueType GetNumberType
+ SetVariantXXX GetVariantXXX

aster2013 10 years ago
parent
commit
b27d32a134

+ 0 - 2
Source/Urho3D/LuaScript/pkgs/Resource/JSONFile.pkg

@@ -3,10 +3,8 @@ $#include "Resource/JSONFile.h"
 class JSONFile : Resource
 {
     JSONFile();
-    // JSONFile(const JSONValue& value);
     ~JSONFile();
 
-    void SetRoot(const JSONValue& root);
     const JSONValue& GetRoot() const;
 
     tolua_outside bool JSONFileSave @ Save(const String fileName, const String indentation = "\t") const;

+ 2 - 3
Source/Urho3D/LuaScript/pkgs/Resource/JSONValue.pkg

@@ -21,7 +21,6 @@ class JSONValue
     JSONValue(const JSONValue& value);
     ~JSONValue();
 
-    void SetType(JSONValueType valueType);
     tolua_outside void JSONValueSetBool @ SetBool(bool value);
     tolua_outside void JSONValueSetInt @ SetInt(int value);
     tolua_outside void JSONValueSetUint @ SetUint(unsigned value);
@@ -31,7 +30,7 @@ class JSONValue
     tolua_outside void JSONValueSetArray @ SetArray(const JSONArray& value);
     tolua_outside void JSONValueSetObject @ SetObject(const JSONObject& value);
 
-    JSONValueType GetType() const;
+    JSONValueType GetValueType() const;
     bool IsNull() const;
     bool IsBool() const;
     bool IsNumber() const;
@@ -41,7 +40,7 @@ class JSONValue
 
     bool GetBool() const;
     int GetInt() const;
-    unsigned GetUint() const;
+    unsigned GetUInt() const;
     float GetFloat() const;
     double GetDouble() const;
     const String GetString() const;

+ 25 - 13
Source/Urho3D/Resource/JSONFile.cpp

@@ -43,16 +43,9 @@ namespace Urho3D
 
 JSONFile::JSONFile(Context* context) :
     Resource(context)
-    // , document_(new Document())
 {
 }
 
-JSONFile::JSONFile(Context* context, const JSONValue& value) :
-    Resource(context)
-{
-    SetRoot(value);
-}
-
 JSONFile::~JSONFile()
 {
 }
@@ -68,6 +61,7 @@ static void ToJSONValue(JSONValue& jsonValue, const rapidjson::Value& rapidjsonV
     switch (rapidjsonValue.GetType())
     {
     case kNullType:
+        // Reset to null type
         jsonValue.SetType(JSON_NULL);
         break;
 
@@ -80,7 +74,12 @@ static void ToJSONValue(JSONValue& jsonValue, const rapidjson::Value& rapidjsonV
         break;
 
     case kNumberType:
-        jsonValue = rapidjsonValue.GetDouble();
+        if (rapidjsonValue.IsInt())
+            jsonValue = rapidjsonValue.GetInt();
+        else if (rapidjsonValue.IsUint())
+            jsonValue = rapidjsonValue.GetUint();
+        else
+            jsonValue = rapidjsonValue.GetDouble();
         break;
 
     case kStringType:
@@ -89,9 +88,7 @@ static void ToJSONValue(JSONValue& jsonValue, const rapidjson::Value& rapidjsonV
 
     case kArrayType:
         {
-            // JSON value will convert to array type
             jsonValue.Resize(rapidjsonValue.Size());
-
             for (unsigned i = 0; i < rapidjsonValue.Size(); ++i)
             {
                 ToJSONValue(jsonValue[i], rapidjsonValue[i]);
@@ -101,7 +98,7 @@ static void ToJSONValue(JSONValue& jsonValue, const rapidjson::Value& rapidjsonV
 
     case kObjectType:
         {
-            // JSON value will convert to object type
+            jsonValue.SetType(JSON_OBJECT);
             for (rapidjson::Value::ConstMemberIterator i = rapidjsonValue.MemberBegin(); i != rapidjsonValue.MemberEnd(); ++i)
             {
                 JSONValue& value = jsonValue[String(i->name.GetString())];
@@ -145,7 +142,7 @@ bool JSONFile::BeginLoad(Deserializer& source)
 
 static void ToRapidjsonValue(rapidjson::Value& rapidjsonValue, const JSONValue& jsonValue, rapidjson::MemoryPoolAllocator<>& allocator)
 {
-    switch (jsonValue.GetType())
+    switch (jsonValue.GetValueType())
     {
     case JSON_NULL:
         rapidjsonValue.SetNull();
@@ -156,7 +153,22 @@ static void ToRapidjsonValue(rapidjson::Value& rapidjsonValue, const JSONValue&
         break;
 
     case JSON_NUMBER:
-        rapidjsonValue.SetDouble(jsonValue.GetDouble());
+        {
+            switch (jsonValue.GetNumberType())
+            {
+            case JSONNumberType::JSONNT_INT:
+                rapidjsonValue.SetInt(jsonValue.GetInt());
+                break;
+
+            case JSONNumberType::JSONNT_UINT:
+                rapidjsonValue.SetUint(jsonValue.GetUInt());
+                break;
+
+            default:
+                rapidjsonValue.SetDouble(jsonValue.GetDouble());
+                break;
+            }
+        }
         break;
 
     case JSON_STRING:

+ 2 - 4
Source/Urho3D/Resource/JSONFile.h

@@ -36,8 +36,6 @@ class URHO3D_API JSONFile : public Resource
 public:
     /// Construct.
     JSONFile(Context* context);
-    /// Construct with a JSON value.
-    JSONFile(Context* context, const JSONValue& value);
     /// Destruct.
     virtual ~JSONFile();
     /// Register object factory.
@@ -50,8 +48,8 @@ public:
     /// Save resource with user-defined indentation, only the first character (if any) of the string is used and the length of the string defines the character count. Return true if successful.
     bool Save(Serializer& dest, const String& indendation) const;
 
-    /// Set root value.
-    void SetRoot(const JSONValue& root) { root_ = root; }
+    /// Return root value.
+    JSONValue& GetRoot() { return root_; }
     /// Return root value.
     const JSONValue& GetRoot() const { return root_; }
 

+ 305 - 64
Source/Urho3D/Resource/JSONValue.cpp

@@ -35,50 +35,6 @@ const JSONValue JSONValue::EMPTY;
 const JSONArray JSONValue::emptyArray;
 const JSONObject JSONValue::emptyObject;
 
-void JSONValue::SetType(JSONValueType valueType)
-{
-    if (valueType == valueType_)
-        return;
-
-    switch (valueType_)
-    {
-    case JSON_STRING:
-        delete stringValue_;
-        break;
-
-    case JSON_ARRAY:
-        delete arrayValue_;
-        break;
-
-    case JSON_OBJECT:
-        delete objectValue_;
-        break;
-
-    default:
-        break;
-    }
-
-    valueType_ = valueType;
-
-    switch (valueType_)
-    {
-    case JSON_STRING:
-        stringValue_ = new String();
-        break;
-
-    case JSON_ARRAY:
-        arrayValue_ = new JSONArray();
-        break;
-
-    case JSON_OBJECT:
-        objectValue_ = new JSONObject();
-        break;
-
-    default:
-        break;
-    }
-}
-
 JSONValue& JSONValue::operator =(bool rhs)
 {
     SetType(JSON_BOOL);
@@ -89,15 +45,15 @@ JSONValue& JSONValue::operator =(bool rhs)
 
 JSONValue& JSONValue::operator =(int rhs)
 {
-    SetType(JSON_NUMBER);
-    numberValue_ = rhs;
+    SetType(JSON_NUMBER, JSONNT_INT);
+    numberValue_ = rhs;    
 
     return *this;
 }
 
 JSONValue& JSONValue::operator =(unsigned rhs)
 {
-    SetType(JSON_NUMBER);
+    SetType(JSON_NUMBER, JSONNT_UINT);
     numberValue_ = rhs;
 
     return *this;
@@ -105,7 +61,7 @@ JSONValue& JSONValue::operator =(unsigned rhs)
 
 JSONValue& JSONValue::operator =(float rhs)
 {
-    SetType(JSON_NUMBER);
+    SetType(JSON_NUMBER, JSONNT_FLOAT_DOUBLE);
     numberValue_ = rhs;
 
     return *this;
@@ -113,7 +69,7 @@ JSONValue& JSONValue::operator =(float rhs)
 
 JSONValue& JSONValue::operator =(double rhs)
 {
-    SetType(JSON_NUMBER);
+    SetType(JSON_NUMBER, JSONNT_FLOAT_DOUBLE);
     numberValue_ = rhs;
 
     return *this;
@@ -156,9 +112,9 @@ JSONValue& JSONValue::operator =(const JSONValue& rhs)
     if (this == &rhs)
         return *this;
 
-    SetType(rhs.valueType_);
+    SetType(rhs.GetValueType(), rhs.GetNumberType());
 
-    switch (valueType_)
+    switch (GetValueType())
     {
     case JSON_BOOL:
         boolValue_ = rhs.boolValue_;
@@ -186,6 +142,16 @@ JSONValue& JSONValue::operator =(const JSONValue& rhs)
     return *this;
 }
 
+JSONValueType JSONValue::GetValueType() const
+{
+    return (JSONValueType)(type_ >> 16);
+}
+
+JSONNumberType JSONValue::GetNumberType() const
+{
+    return (JSONNumberType)(type_ & 0xffff);
+}
+
 JSONValue& JSONValue::operator [](unsigned index)
 {
     // Convert to array type
@@ -196,7 +162,7 @@ JSONValue& JSONValue::operator [](unsigned index)
 
 const JSONValue& JSONValue::operator [](unsigned index) const
 {
-    if (valueType_ != JSON_ARRAY)
+    if (GetValueType() != JSON_ARRAY)
         return EMPTY;
 
     return (*arrayValue_)[index];
@@ -212,7 +178,7 @@ void JSONValue::Push(const JSONValue& value)
 
 void JSONValue::Pop()
 {
-    if (valueType_ != JSON_ARRAY)
+    if (GetValueType() != JSON_ARRAY)
         return;
 
     arrayValue_->Pop();
@@ -220,7 +186,7 @@ void JSONValue::Pop()
 
 void JSONValue::Insert(unsigned pos, const JSONValue& value)
 {
-    if (valueType_ != JSON_ARRAY)
+    if (GetValueType() != JSON_ARRAY)
         return;
 
     arrayValue_->Insert(pos, value);
@@ -228,7 +194,7 @@ void JSONValue::Insert(unsigned pos, const JSONValue& value)
 
 void JSONValue::Erase(unsigned pos, unsigned length)
 {
-    if (valueType_ != JSON_ARRAY)
+    if (GetValueType() != JSON_ARRAY)
         return;
 
     arrayValue_->Erase(pos, length);
@@ -244,7 +210,7 @@ void JSONValue::Resize(unsigned newSize)
 
 unsigned JSONValue::Size() const
 {
-    if (valueType_ == JSON_ARRAY)
+    if (GetValueType() == JSON_ARRAY)
         return arrayValue_->Size();
 
     return 0;
@@ -260,7 +226,7 @@ JSONValue& JSONValue::operator [](const String& key)
 
 const JSONValue& JSONValue::operator [](const String& key) const
 {
-    if (valueType_ != JSON_OBJECT)
+    if (GetValueType() != JSON_OBJECT)
         return EMPTY;
 
     return (*objectValue_)[key];
@@ -276,7 +242,7 @@ void JSONValue::Set(const String& key, const JSONValue& value)
 
 const JSONValue& JSONValue::Get(const String& key) const
 {
-    if (valueType_ != JSON_OBJECT)
+    if (GetValueType() != JSON_OBJECT)
         return EMPTY;
 
     JSONObject::ConstIterator i = objectValue_->Find(key);
@@ -288,7 +254,7 @@ const JSONValue& JSONValue::Get(const String& key) const
 
 bool JSONValue::Erase(const String& key)
 {
-    if (valueType_ != JSON_OBJECT)
+    if (GetValueType() != JSON_OBJECT)
         return false;
 
     return objectValue_->Erase(key);
@@ -296,7 +262,7 @@ bool JSONValue::Erase(const String& key)
 
 bool JSONValue::Contains(const String& key) const
 {
-    if  (valueType_ != JSON_OBJECT)
+    if  (GetValueType() != JSON_OBJECT)
         return false;
 
     return objectValue_->Contains(key);
@@ -312,7 +278,7 @@ JSONObjectIterator JSONValue::Begin()
 
 ConstJSONObjectIterator JSONValue::Begin() const
 {
-    if (valueType_ != JSON_OBJECT)
+    if (GetValueType() != JSON_OBJECT)
         return emptyObject.Begin();
 
     return objectValue_->Begin();
@@ -328,7 +294,7 @@ JSONObjectIterator JSONValue::End()
 
 ConstJSONObjectIterator JSONValue::End() const
 {
-    if (valueType_ != JSON_OBJECT)
+    if (GetValueType() != JSON_OBJECT)
         return emptyObject.End();
 
     return objectValue_->End();
@@ -336,10 +302,285 @@ ConstJSONObjectIterator JSONValue::End() const
 
 void JSONValue::Clear()
 {
-    if (valueType_ == JSON_ARRAY)
+    if (GetValueType() == JSON_ARRAY)
         arrayValue_->Clear();
-    else if (valueType_ == JSON_OBJECT)
+    else if (GetValueType() == JSON_OBJECT)
         objectValue_->Clear();
 }
 
+void JSONValue::SetType(JSONValueType valueType, JSONNumberType numberType)
+{
+    int type = (valueType << 16) | numberType;
+    if (type == type_)
+        return;
+
+    switch (GetValueType())
+    {
+    case JSON_STRING:
+        delete stringValue_;
+        break;
+
+    case JSON_ARRAY:
+        delete arrayValue_;
+        break;
+
+    case JSON_OBJECT:
+        delete objectValue_;
+        break;
+
+    default:
+        break;
+    }
+
+    type_ = type;
+
+    switch (GetValueType())
+    {
+    case JSON_STRING:
+        stringValue_ = new String();
+        break;
+
+    case JSON_ARRAY:
+        arrayValue_ = new JSONArray();
+        break;
+
+    case JSON_OBJECT:
+        objectValue_ = new JSONObject();
+        break;
+
+    default:
+        break;
+    }
+}
+
+void JSONValue::SetVariant(const Variant& variant, Context* context)
+{
+    if (!IsNull())
+    {
+        LOGWARNING("JsonValue is not null");
+    }
+
+    (*this)["type"] = variant.GetTypeName();
+    (*this)["value"].SetVariantValue(variant, context);
+}
+
+void JSONValue::GetVariant(Variant& variant) const
+{
+    VariantType type = Variant::GetTypeFromName((*this)["type"].GetString());
+    (*this)["value"].GetVariantValue(variant, type);    
+}
+
+void JSONValue::SetVariantValue(const Variant& variant, Context* context)
+{
+    if (!IsNull())
+    {
+        LOGWARNING("JsonValue is not null");
+    }
+
+    switch (variant.GetType())
+    {
+    case VAR_BOOL:
+        *this = variant.GetBool();
+        return;
+    
+    case VAR_INT:
+        *this = variant.GetInt();
+        return;
+
+    case VAR_FLOAT:
+        *this = variant.GetFloat();
+        return;
+
+    case VAR_DOUBLE:
+        *this = variant.GetDouble();
+        return;
+
+    case VAR_STRING:
+        *this = variant.GetString();
+        return;
+
+    case VAR_VARIANTVECTOR:
+        SetVariantVector(variant.GetVariantVector(), context);
+        return;
+
+    case VAR_VARIANTMAP:
+        SetVariantMap(variant.GetVariantMap(), context);
+        return;
+
+    case VAR_RESOURCEREF:
+        {
+            if (!context)
+            {
+                LOGERROR("Context must not null for ResourceRef");
+                return;
+            }
+
+            const ResourceRef& ref = variant.GetResourceRef();
+            *this = String(context->GetTypeName(ref.type_)) + ";" + ref.name_;
+        }
+        return;
+
+    case VAR_RESOURCEREFLIST:
+        {
+            if (!context)
+            {
+                LOGERROR("Context must not null for ResourceRefList");
+                return;
+            }
+
+            const ResourceRefList& refList = variant.GetResourceRefList();
+            String str(context->GetTypeName(refList.type_));
+            for (unsigned i = 0; i < refList.names_.Size(); ++i)
+            {
+                str += ";";
+                str += refList.names_[i];
+            }
+            *this = str;
+        }
+        return;
+
+    case VAR_STRINGVECTOR:
+        {
+            const StringVector& vector = variant.GetStringVector();
+            Resize(vector.Size());
+            for (unsigned i = 0; i < vector.Size(); ++i)
+                (*this)[i] = vector[i];
+        }
+        return;
+
+    default:
+        *this = variant.ToString();
+    }
+}
+
+void JSONValue::GetVariantValue(Variant& variant, VariantType type) const
+{
+    switch (type)
+    {
+    case VAR_BOOL:
+        variant = GetBool();
+        return;
+
+    case VAR_INT:
+        variant = GetInt();
+        return;
+
+    case VAR_FLOAT:
+        variant = GetFloat();
+        return;
+
+    case VAR_DOUBLE:
+        variant = GetDouble();
+        return;
+
+    case VAR_STRING:
+        variant = GetString();
+        return;
+
+    case VAR_VARIANTVECTOR:
+        {
+            VariantVector vector;
+            GetVariantVector(vector);
+            variant = vector;
+        }
+        return;
+
+    case VAR_VARIANTMAP:
+        {
+            VariantMap map;
+            GetVariantMap(map);
+            variant = map;
+        }
+        return;
+
+    case VAR_RESOURCEREF:
+        {
+            ResourceRef ref;
+            Vector<String> values = GetString().Split(';');
+            if (values.Size() == 2)
+            {
+                ref.type_ = values[0];
+                ref.name_ = values[1];
+            }
+            variant = ref;
+        }
+        return;
+
+    case VAR_RESOURCEREFLIST:
+        {
+            ResourceRefList refList;
+            Vector<String> values = GetString().Split(';');
+            if (values.Size() >= 1)
+            {
+                refList.type_ = values[0];
+                refList.names_.Resize(values.Size() - 1);
+                for (unsigned i = 1; i < values.Size(); ++i)
+                    refList.names_[i - 1] = values[i];
+            }
+            variant = refList;
+        }
+        return;
+
+    case VAR_STRINGVECTOR:
+        {
+            StringVector vector;
+            for (unsigned i = 0; i < Size(); ++i)
+                vector.Push((*this)[i].GetString());
+            variant = vector;
+        }
+        return;
+
+    default:
+        variant.FromString(type, GetString());
+        return;
+    }
+}
+
+void JSONValue::SetVariantMap(const VariantMap& variantMap, Context* context)
+{
+    SetType(JSON_OBJECT);
+    for (VariantMap::ConstIterator i = variantMap.Begin(); i != variantMap.End(); ++i)
+        (*this)[i->first_.ToString()].SetVariant(i->second_);
+}
+
+void JSONValue::GetVariantMap(VariantMap& variantMap) const
+{
+    if (!IsObject())
+    {
+        LOGERROR("JSONValue is not a object");
+        return;
+    }
+
+    for (ConstJSONObjectIterator i = Begin(); i != End(); ++i)
+    {
+        StringHash key(ToUInt(i->first_));
+        Variant variant;
+        i->second_.GetVariant(variant);
+        variantMap[key] = variant;
+    }
+}
+
+void JSONValue::SetVariantVector(const VariantVector& variantVector, Context* context)
+{
+    SetType(JSON_ARRAY);
+    for (unsigned i = 0; i < variantVector.Size(); ++i)
+        (*this)[i].SetVariant(variantVector[i]);
+}
+
+void JSONValue::GetVariantVector(VariantVector& variantVector) const
+{
+    if (!IsArray())
+    {
+        LOGERROR("JSONValue is not a array");
+        return;
+    }
+
+    for (unsigned i = 0; i < Size(); ++i)
+    {
+        Variant variant;
+        (*this)[i].GetVariant(variant);
+        variantVector.Push(variant);
+    }
+}
+
 }

+ 48 - 25
Source/Urho3D/Resource/JSONValue.h

@@ -42,6 +42,19 @@ enum JSONValueType
     JSON_OBJECT,
 };
 
+/// JSON number type.
+enum JSONNumberType
+{
+    /// Not a number.
+    JSONNT_NAN = 0,
+    /// Integer.
+    JSONNT_INT,
+    /// Unsigned integer.
+    JSONNT_UINT,
+    /// Float or double.
+    JSONNT_FLOAT_DOUBLE,
+};
+
 class JSONValue;
 
 /// JSON array type.
@@ -59,66 +72,66 @@ class URHO3D_API JSONValue
 public:
     /// Construct null value.
     JSONValue() : 
-        valueType_(JSON_NULL)
+        type_(0)
     {
     }
     /// Construct with a boolean.
     JSONValue(bool value) :
-        valueType_(JSON_NULL)
+        type_(0)
     {
         *this = value;
     }
     /// Construct with a integer.
     JSONValue(int value) :
-        valueType_(JSON_NULL)
+        type_(0)
     {
         *this = value;
     }
     /// Construct with a unsigned integer.
     JSONValue(unsigned value) :
-        valueType_(JSON_NULL)
+        type_(0)
     {
         *this = value;
     }
     /// Construct with a float.
     JSONValue(float value) :
-        valueType_(JSON_NULL)
+        type_(0)
     {
         *this = value;
     }
     /// Construct with a double.
     JSONValue(double value) :
-        valueType_(JSON_NULL)
+        type_(0)
     {
         *this = value;
     }
     /// Construct with a string.
     JSONValue(const String& value) :
-        valueType_(JSON_NULL)
+        type_(0)
     {
         *this = value;
     }
     /// Construct with a C string.
     JSONValue(const char* value) :
-        valueType_(JSON_NULL)
+        type_(0)
     {
         *this = value;
     }
     /// Construct with a JSON array.
     JSONValue(const JSONArray& value) :
-        valueType_(JSON_NULL)
+        type_(0)
     {
         *this = value;
     }
     /// Construct with a JSON object.
     JSONValue(const JSONObject& value) :
-        valueType_(JSON_NULL)
+        type_(0)
     {
         *this = value;
     }    
     /// Copy-construct from another JSON value.
     JSONValue(const JSONValue& value) :
-        valueType_(JSON_NULL)
+        type_(0)
     {
         *this = value;
     }
@@ -128,8 +141,6 @@ public:
         SetType(JSON_NULL);
     }
 
-    /// Set value type.
-    void SetType(JSONValueType valueType);
     /// Assign from a boolean.
     JSONValue& operator =(bool rhs);
     /// Assign from an integer.
@@ -152,26 +163,28 @@ public:
     JSONValue& operator =(const JSONValue& rhs);
 
     /// Return value type.
-    JSONValueType GetType() const { return valueType_; }
+    JSONValueType GetValueType() const;
+    /// Return number type.
+    JSONNumberType GetNumberType() const;
     /// Check is null.
-    bool IsNull() const { return valueType_ == JSON_NULL; }
+    bool IsNull() const { return GetValueType() == JSON_NULL; }
     /// Check is boolean.
-    bool IsBool() const { return valueType_ == JSON_BOOL; }
+    bool IsBool() const { return GetValueType() == JSON_BOOL; }
     /// Check is number.
-    bool IsNumber() const { return valueType_ == JSON_NUMBER; }
+    bool IsNumber() const { return GetValueType() == JSON_NUMBER; }
     /// Check is string.
-    bool IsString() const { return valueType_ == JSON_STRING; }
+    bool IsString() const { return GetValueType() == JSON_STRING; }
     /// Check is array.
-    bool IsArray() const { return valueType_ == JSON_ARRAY; }
+    bool IsArray() const { return GetValueType() == JSON_ARRAY; }
     /// Check is object.
-    bool IsObject() const { return valueType_ == JSON_OBJECT; }
+    bool IsObject() const { return GetValueType() == JSON_OBJECT; }
 
     /// Return boolean value.
     bool GetBool() const { return IsBool() ? boolValue_ : false;}
     /// Return integer value.
     int GetInt() const { return IsNumber() ? (int)numberValue_ : 0; }
     /// Return unsigned integer value.
-    unsigned GetUint() const { return IsNumber() ? (unsigned)numberValue_ : 0; }
+    unsigned GetUInt() const { return IsNumber() ? (unsigned)numberValue_ : 0; }
     /// Return float value.
     float GetFloat() const { return IsNumber() ? (float)numberValue_ : 0.0f; }
     /// Return double value.
@@ -227,7 +240,18 @@ public:
 
     /// Clear array or object.
     void Clear();
-    
+
+    /// Internal functions.
+    void SetType(JSONValueType valueType, JSONNumberType numberType = JSONNT_NAN);
+    void SetVariant(const Variant& variant, Context* context = 0);
+    void GetVariant(Variant& variant) const;
+    void SetVariantValue(const Variant& variant, Context* context = 0);
+    void GetVariantValue(Variant& variant, VariantType type) const;
+    void SetVariantMap(const VariantMap& variantMap, Context* context = 0);
+    void GetVariantMap(VariantMap& variantMap) const;
+    void SetVariantVector(const VariantVector& variantVector, Context* context = 0);
+    void GetVariantVector(VariantVector& variantVector) const;
+
     /// Empty JSON value.
     static const JSONValue EMPTY;
     /// Empty JSON array.
@@ -236,9 +260,8 @@ public:
     static const JSONObject emptyObject;
 
 private:
-    /// Value type.
-    JSONValueType valueType_;
-    /// Values.
+    /// type.
+    unsigned type_;
     union
     {
         /// Boolean value.

+ 3 - 4
Source/Urho3D/Script/ResourceAPI.cpp

@@ -318,7 +318,7 @@ static void RegisterJSONValue(asIScriptEngine* engine)
     engine->RegisterObjectMethod("JSONValue", "JSONValue& opAssign(const String&in)", asMETHODPR(JSONValue, operator =, (const String&), JSONValue&), asCALL_THISCALL);
     engine->RegisterObjectMethod("JSONValue", "JSONValue& opAssign(const JSONValue&in)", asMETHODPR(JSONValue, operator =, (const JSONValue&), JSONValue&), asCALL_THISCALL);
 
-    engine->RegisterObjectMethod("JSONValue", "JSONValueType get_type() const", asMETHOD(JSONValue, GetType), asCALL_THISCALL);
+    engine->RegisterObjectMethod("JSONValue", "JSONValueType get_valueType() const", asMETHOD(JSONValue, GetValueType), asCALL_THISCALL);
     engine->RegisterObjectMethod("JSONValue", "bool get_isNull() const", asMETHOD(JSONValue, IsNull), asCALL_THISCALL);
     engine->RegisterObjectMethod("JSONValue", "bool get_isBool() const", asMETHOD(JSONValue, IsBool), asCALL_THISCALL);
     engine->RegisterObjectMethod("JSONValue", "bool get_isNumber() const", asMETHOD(JSONValue, IsNumber), asCALL_THISCALL);
@@ -328,7 +328,7 @@ static void RegisterJSONValue(asIScriptEngine* engine)
 
     engine->RegisterObjectMethod("JSONValue", "bool GetBool() const", asMETHOD(JSONValue, GetBool), asCALL_THISCALL);
     engine->RegisterObjectMethod("JSONValue", "int GetInt() const", asMETHOD(JSONValue, GetInt), asCALL_THISCALL);
-    engine->RegisterObjectMethod("JSONValue", "uint GetUint() const", asMETHOD(JSONValue, GetUint), asCALL_THISCALL);
+    engine->RegisterObjectMethod("JSONValue", "uint GetUInt() const", asMETHOD(JSONValue, GetUInt), asCALL_THISCALL);
     engine->RegisterObjectMethod("JSONValue", "float GetFloat() const", asMETHOD(JSONValue, GetFloat), asCALL_THISCALL);
     engine->RegisterObjectMethod("JSONValue", "double GetDouble() const", asMETHOD(JSONValue, GetDouble), asCALL_THISCALL);
     engine->RegisterObjectMethod("JSONValue", "const String& GetString() const", asMETHOD(JSONValue, GetString), asCALL_THISCALL);
@@ -360,8 +360,7 @@ static bool JSONFileSave(File* file, const String& indendation, JSONFile* ptr)
 static void RegisterJSONFile(asIScriptEngine* engine)
 {
     RegisterResource<JSONFile>(engine, "JSONFile");
-    engine->RegisterObjectMethod("JSONFile", "void SetRoot(const JSONValue&in)", asMETHOD(JSONFile, SetRoot), asCALL_THISCALL);
-    engine->RegisterObjectMethod("JSONFile", "const JSONValue& GetRoot() const", asMETHOD(JSONFile, GetRoot), asCALL_THISCALL);
+    engine->RegisterObjectMethod("JSONFile", "const JSONValue& GetRoot() const", asMETHODPR(JSONFile, GetRoot, () const, const JSONValue&), asCALL_THISCALL);
     engine->RegisterObjectMethod("JSONFile", "bool Save(File@+, const String&in) const", asFUNCTION(JSONFileSave), asCALL_CDECL_OBJLAST);
 }