Преглед на файлове

Add get child name for JSON object type.

aster2013 преди 11 години
родител
ревизия
53d641bf6e

+ 1 - 0
Source/Engine/LuaScript/pkgs/Resource/JSONValue.pkg

@@ -38,6 +38,7 @@ class JSONValue
     void SetVariantValue(const String name, const Variant& value);
 
     bool IsObject() const;
+    Vector<String> GetChildNames() const;
     int GetInt(const String name) const;
     bool GetBool(const String name) const;
     float GetFloat(const String name) const;

+ 16 - 0
Source/Engine/Resource/JSONValue.cpp

@@ -276,6 +276,22 @@ bool JSONValue::IsObject() const
     return value_ && value_->IsObject();
 }
 
+Vector<String> JSONValue::GetChildNames() const
+{
+    Vector<String> ret;
+    if (!IsObject())
+        return ret;
+
+    for (Value::ConstMemberIterator i = value_->MemberBegin(); i != value_->MemberEnd(); ++i)
+    {
+        // Only reutrn name for child object and array
+        if (i->value.GetType() == kArrayType || i->value.GetType() == kObjectType)
+            ret.Push(i->name.GetString());
+    }
+
+    return ret;
+}
+
 int JSONValue::GetInt(const String& name) const
 {
     return GetMember(name).GetInt();

+ 2 - 0
Source/Engine/Resource/JSONValue.h

@@ -125,6 +125,8 @@ public:
 
     /// Is object type.
     bool IsObject() const;
+    /// Return child names (only object and array child name).
+    Vector<String> GetChildNames() const;
     /// Return int.
     int GetInt(const String& name) const;
     /// Return bool.

+ 1 - 0
Source/Engine/Script/ResourceAPI.cpp

@@ -201,6 +201,7 @@ static void RegisterJSONValue(asIScriptEngine* engine)
     engine->RegisterObjectMethod("JSONValue", "void SetVariant(const String&in, const Variant&in)", asMETHOD(JSONValue, SetVariant), asCALL_THISCALL);
     engine->RegisterObjectMethod("JSONValue", "void SetVariantValue(const String&in, const Variant&in)", asMETHOD(JSONValue, SetVariantValue), asCALL_THISCALL);
     engine->RegisterObjectMethod("JSONValue", "bool get_isObject() const", asMETHOD(JSONValue, IsObject), asCALL_THISCALL);
+    engine->RegisterObjectMethod("JSONValue", "Vector<String> GetChildNames() const", asMETHOD(JSONValue, GetChildNames), asCALL_THISCALL);
     engine->RegisterObjectMethod("JSONValue", "int GetInt(const String&in) const", asMETHODPR(JSONValue, GetInt, (const String&) const, int), asCALL_THISCALL);
     engine->RegisterObjectMethod("JSONValue", "bool GetBool(const String&in) const", asMETHODPR(JSONValue, GetBool, (const String&) const, bool), asCALL_THISCALL);
     engine->RegisterObjectMethod("JSONValue", "float GetFloat(const String&in) const", asMETHODPR(JSONValue, GetFloat, (const String&) const, float), asCALL_THISCALL);