Browse Source

Rename enum and function names in JSONValue.

aster2013 11 years ago
parent
commit
6d3ad57bc8

+ 3 - 3
Source/Engine/Resource/JSONFile.cpp

@@ -98,7 +98,7 @@ bool JSONFile::Save(Serializer& dest) const
 
 
 JSONValue JSONFile::CreateRoot(JSONValueType valueType)
 JSONValue JSONFile::CreateRoot(JSONValueType valueType)
 {
 {
-    if (valueType == JVT_OBJECT)
+    if (valueType == JSON_OBJECT)
         document_->SetObject();
         document_->SetObject();
     else
     else
         document_->SetArray();
         document_->SetArray();
@@ -111,8 +111,8 @@ JSONValue JSONFile::GetRoot(JSONValueType valueType)
     if (!document_)
     if (!document_)
         return JSONValue::EMPTY;
         return JSONValue::EMPTY;
 
 
-    if ((valueType == JVT_OBJECT && document_->GetType() != kObjectType) ||
-        (valueType == JVT_ARRAY && document_->GetType() != kArrayType))
+    if ((valueType == JSON_OBJECT && document_->GetType() != kObjectType) ||
+        (valueType == JSON_ARRAY && document_->GetType() != kArrayType))
     {
     {
         LOGERROR("Invalid root value type");
         LOGERROR("Invalid root value type");
         return JSONValue::EMPTY;
         return JSONValue::EMPTY;

+ 2 - 2
Source/Engine/Resource/JSONFile.h

@@ -53,9 +53,9 @@ public:
     virtual bool Save(Serializer& dest) const;
     virtual bool Save(Serializer& dest) const;
 
 
     /// Clear the document and create a root value, default is object type.
     /// Clear the document and create a root value, default is object type.
-    JSONValue CreateRoot(JSONValueType valueType = JVT_OBJECT);
+    JSONValue CreateRoot(JSONValueType valueType = JSON_OBJECT);
     /// Return the root value with specific value type, Return null value if not found.
     /// Return the root value with specific value type, Return null value if not found.
-    JSONValue GetRoot(JSONValueType valueType = JVT_UNKNOWN);
+    JSONValue GetRoot(JSONValueType valueType = JSON_ANY);
 
 
     /// Return rapidjson document.
     /// Return rapidjson document.
     rapidjson::Document* GetDocument() const { return document_; }
     rapidjson::Document* GetDocument() const { return document_; }

+ 55 - 55
Source/Engine/Resource/JSONValue.cpp

@@ -38,9 +38,9 @@ const JSONValue JSONValue::EMPTY;
 
 
 static rapidjson::Type ToRapidJsonType(JSONValueType valueType)
 static rapidjson::Type ToRapidJsonType(JSONValueType valueType)
 {
 {
-    if (valueType == JVT_OBJECT)
+    if (valueType == JSON_OBJECT)
         return kObjectType;
         return kObjectType;
-    else if (valueType == JVT_ARRAY)
+    else if (valueType == JSON_ARRAY)
         return kArrayType;
         return kArrayType;
     return kNullType;
     return kNullType;
 }
 }
@@ -96,9 +96,9 @@ JSONValue JSONValue::CreateChild(const String& name, JSONValueType valueType)
         return JSONValue::EMPTY;
         return JSONValue::EMPTY;
 
 
     Value jsonValue;
     Value jsonValue;
-    if (valueType == JVT_OBJECT)
+    if (valueType == JSON_OBJECT)
         jsonValue.SetObject();
         jsonValue.SetObject();
-    else if (valueType == JVT_ARRAY)
+    else if (valueType == JSON_ARRAY)
         jsonValue.SetArray();
         jsonValue.SetArray();
 
 
     AddMember(name, jsonValue);
     AddMember(name, jsonValue);
@@ -114,7 +114,7 @@ JSONValue JSONValue::GetChild(const String& name, JSONValueType valueType) const
         return JSONValue::EMPTY;
         return JSONValue::EMPTY;
 
 
     Value& value = GetMember(name);
     Value& value = GetMember(name);
-    if (valueType != JVT_UNKNOWN && value.GetType() != ToRapidJsonType(valueType))
+    if (valueType != JSON_ANY && value.GetType() != ToRapidJsonType(valueType))
         return JSONValue::EMPTY;
         return JSONValue::EMPTY;
 
 
     return JSONValue(file_, &value);
     return JSONValue(file_, &value);
@@ -242,7 +242,7 @@ void JSONValue::SetMatrix4(const String& name, const Matrix4& value)
 void JSONValue::SetVariant(const String& name, const Variant& value)
 void JSONValue::SetVariant(const String& name, const Variant& value)
 {
 {
     // Create child object for variant
     // Create child object for variant
-    JSONValue child = CreateChild(name, JVT_OBJECT);
+    JSONValue child = CreateChild(name, JSON_OBJECT);
     // Set type
     // Set type
     child.SetString("type", value.GetTypeName());
     child.SetString("type", value.GetTypeName());
     // Set value
     // Set value
@@ -409,7 +409,7 @@ Matrix4 JSONValue::GetMatrix4(const String& name) const
 Variant JSONValue::GetVariant(const String& name) const
 Variant JSONValue::GetVariant(const String& name) const
 {
 {
     // Get child for variant
     // Get child for variant
-    JSONValue child = GetChild(name, JVT_OBJECT);
+    JSONValue child = GetChild(name, JSON_OBJECT);
     if (child.IsNull())
     if (child.IsNull())
         return Variant::EMPTY;
         return Variant::EMPTY;
 
 
@@ -453,95 +453,95 @@ JSONValue JSONValue::GetChild(unsigned index, JSONValueType valueType) const
         return JSONValue::EMPTY;
         return JSONValue::EMPTY;
 
 
     const Value& value = (*value_)[(SizeType)index];
     const Value& value = (*value_)[(SizeType)index];
-    if (valueType != JVT_UNKNOWN && value.GetType() != ToRapidJsonType(valueType))
+    if (valueType != JSON_ANY && value.GetType() != ToRapidJsonType(valueType))
         return JSONValue::EMPTY;
         return JSONValue::EMPTY;
 
 
     return JSONValue(file_, (Value*)&value);
     return JSONValue(file_, (Value*)&value);
 }
 }
 
 
-void JSONValue::PushInt(int value)
+void JSONValue::AddInt(int value)
 {
 {
     Value jsonValue;
     Value jsonValue;
     jsonValue.SetInt(value);
     jsonValue.SetInt(value);
-    PushMember(jsonValue);
+    AddMember(jsonValue);
 }
 }
 
 
-void JSONValue::PushBool(bool value)
+void JSONValue::AddBool(bool value)
 {
 {
     Value jsonValue;
     Value jsonValue;
     jsonValue.SetBool(value);
     jsonValue.SetBool(value);
-    PushMember(jsonValue);
+    AddMember(jsonValue);
 }
 }
 
 
-void JSONValue::PushFloat(float value)
+void JSONValue::AddFloat(float value)
 {
 {
     Value jsonValue;
     Value jsonValue;
     jsonValue.SetDouble((double)value);
     jsonValue.SetDouble((double)value);
-    PushMember(jsonValue);
+    AddMember(jsonValue);
 }
 }
 
 
-void JSONValue::PushVector2(const Vector2& value)
+void JSONValue::AddVector2(const Vector2& value)
 {
 {
-    PushString(value.ToString());
+    AddString(value.ToString());
 }
 }
 
 
-void JSONValue::PushVector3(const Vector3& value)
+void JSONValue::AddVector3(const Vector3& value)
 {
 {
-    PushString(value.ToString());
+    AddString(value.ToString());
 }
 }
 
 
-void JSONValue::PushVector4(const Vector4& value)
+void JSONValue::AddVector4(const Vector4& value)
 {
 {
-    PushString(value.ToString());
+    AddString(value.ToString());
 }
 }
 
 
-void JSONValue::PushVectorVariant(const Variant& value)
+void JSONValue::AddVectorVariant(const Variant& value)
 {
 {
     VariantType type = value.GetType();
     VariantType type = value.GetType();
     if (type == VAR_FLOAT || type == VAR_VECTOR2 || type == VAR_VECTOR3 || type == VAR_VECTOR4 || type == VAR_MATRIX3 ||
     if (type == VAR_FLOAT || type == VAR_VECTOR2 || type == VAR_VECTOR3 || type == VAR_VECTOR4 || type == VAR_MATRIX3 ||
         type == VAR_MATRIX3X4 || type == VAR_MATRIX4)
         type == VAR_MATRIX3X4 || type == VAR_MATRIX4)
-        PushString(value.ToString());
+        AddString(value.ToString());
 }
 }
 
 
-void JSONValue::PushQuaternion(const Quaternion& value)
+void JSONValue::AddQuaternion(const Quaternion& value)
 {
 {
-    PushString(value.ToString());
+    AddString(value.ToString());
 }
 }
 
 
-void JSONValue::PushColor(const Color& value)
+void JSONValue::AddColor(const Color& value)
 {
 {
-    PushString(value.ToString());
+    AddString(value.ToString());
 }
 }
 
 
-void JSONValue::PushString(const String& value)
+void JSONValue::AddString(const String& value)
 {
 {
     Value jsonValue;
     Value jsonValue;
     jsonValue.SetString(value.CString(), value.Length(), file_->GetDocument()->GetAllocator());
     jsonValue.SetString(value.CString(), value.Length(), file_->GetDocument()->GetAllocator());
-    PushMember(jsonValue);
+    AddMember(jsonValue);
 }
 }
 
 
-void JSONValue::PushBuffer(const PODVector<unsigned char>& value)
+void JSONValue::AddBuffer(const PODVector<unsigned char>& value)
 {
 {
     if (!value.Size())
     if (!value.Size())
-        PushString(String::EMPTY);
+        AddString(String::EMPTY);
     else
     else
-        PushBuffer(&value[0], value.Size());
+        AddBuffer(&value[0], value.Size());
 }
 }
 
 
-void JSONValue::PushBuffer(const void* data, unsigned size)
+void JSONValue::AddBuffer(const void* data, unsigned size)
 {
 {
     String dataStr;
     String dataStr;
     BufferToString(dataStr, data, size);
     BufferToString(dataStr, data, size);
-    PushString(dataStr);
+    AddString(dataStr);
 }
 }
 
 
-void JSONValue::PushResourceRef(const ResourceRef& value)
+void JSONValue::AddResourceRef(const ResourceRef& value)
 {
 {
     Context* context = file_->GetContext();
     Context* context = file_->GetContext();
-    PushString(String(context->GetTypeName(value.type_)) + ";" + value.name_);
+    AddString(String(context->GetTypeName(value.type_)) + ";" + value.name_);
 }
 }
 
 
-void JSONValue::PushResourceRefList(const ResourceRefList& value)
+void JSONValue::AddResourceRefList(const ResourceRefList& value)
 {
 {
     Context* context = file_->GetContext();
     Context* context = file_->GetContext();
     String str(context->GetTypeName(value.type_));
     String str(context->GetTypeName(value.type_));
@@ -550,54 +550,54 @@ void JSONValue::PushResourceRefList(const ResourceRefList& value)
         str += ";";
         str += ";";
         str += value.names_[i];
         str += value.names_[i];
     }
     }
-    PushString(str);
+    AddString(str);
 }
 }
 
 
-void JSONValue::PushIntRect(const IntRect& value)
+void JSONValue::AddIntRect(const IntRect& value)
 {
 {
-    PushString(value.ToString());
+    AddString(value.ToString());
 }
 }
 
 
-void JSONValue::PushIntVector2(const IntVector2& value)
+void JSONValue::AddIntVector2(const IntVector2& value)
 {
 {
-    PushString(value.ToString());
+    AddString(value.ToString());
 }
 }
 
 
-void JSONValue::PushMatrix3(const Matrix3& value)
+void JSONValue::AddMatrix3(const Matrix3& value)
 {
 {
-    PushString(value.ToString());
+    AddString(value.ToString());
 }
 }
 
 
-void JSONValue::PushMatrix3x4(const Matrix3x4& value)
+void JSONValue::AddMatrix3x4(const Matrix3x4& value)
 {
 {
-    PushString(value.ToString());
+    AddString(value.ToString());
 }
 }
 
 
-void JSONValue::PushMatrix4(const Matrix4& value)
+void JSONValue::AddMatrix4(const Matrix4& value)
 {
 {
-    PushString(value.ToString());
+    AddString(value.ToString());
 }
 }
 
 
-void JSONValue::PushVariant(const Variant& value)
+void JSONValue::AddVariant(const Variant& value)
 {
 {
     // Create child object for variant
     // Create child object for variant
-    JSONValue child = CreateChild(JVT_OBJECT);
+    JSONValue child = CreateChild(JSON_OBJECT);
     // Set type
     // Set type
     child.SetString("type", value.GetTypeName());
     child.SetString("type", value.GetTypeName());
     // Set value
     // Set value
     child.SetVariantValue("value", value);
     child.SetVariantValue("value", value);
 }
 }
 
 
-void JSONValue::PushVariantValue(const Variant& value)
+void JSONValue::AddVariantValue(const Variant& value)
 {
 {
     switch (value.GetType())
     switch (value.GetType())
     {
     {
     case VAR_RESOURCEREF:
     case VAR_RESOURCEREF:
-        PushResourceRef(value.GetResourceRef());
+        AddResourceRef(value.GetResourceRef());
         break;
         break;
 
 
     case VAR_RESOURCEREFLIST:
     case VAR_RESOURCEREFLIST:
-        PushResourceRefList(value.GetResourceRefList());
+        AddResourceRefList(value.GetResourceRefList());
         break;
         break;
 
 
     case VAR_VARIANTVECTOR:
     case VAR_VARIANTVECTOR:
@@ -606,7 +606,7 @@ void JSONValue::PushVariantValue(const Variant& value)
         break;
         break;
 
 
     default:
     default:
-        PushString(value.ToString());
+        AddString(value.ToString());
     }
     }
 }
 }
 
 
@@ -755,7 +755,7 @@ Matrix4 JSONValue::GetMatrix4(unsigned index) const
 Variant JSONValue::GetVariant(unsigned index) const
 Variant JSONValue::GetVariant(unsigned index) const
 {
 {
     // Get child for variant
     // Get child for variant
-    JSONValue child = GetChild(index, JVT_OBJECT);
+    JSONValue child = GetChild(index, JSON_OBJECT);
     if (child.IsNull())
     if (child.IsNull())
         return Variant::EMPTY;
         return Variant::EMPTY;
 
 
@@ -798,7 +798,7 @@ rapidjson::Value& JSONValue::GetMember(const String& name) const
     return (*value_)[name.CString()];
     return (*value_)[name.CString()];
 }
 }
 
 
-void JSONValue::PushMember(rapidjson::Value& jsonValue)
+void JSONValue::AddMember(rapidjson::Value& jsonValue)
 {
 {
     assert(IsArray());
     assert(IsArray());
 
 

+ 52 - 52
Source/Engine/Resource/JSONValue.h

@@ -44,12 +44,12 @@ class JSONFile;
 /// JSON value type.
 /// JSON value type.
 enum JSONValueType
 enum JSONValueType
 {
 {
+    /// Any type (use type in JSON value).
+    JSON_ANY = 0,
     /// Object type (Hash Map).
     /// Object type (Hash Map).
-    JVT_OBJECT = 0,
+    JSON_OBJECT,
     /// Array type.
     /// Array type.
-    JVT_ARRAY,
-    /// Unknown type.
-    JVT_UNKNOWN,
+    JSON_ARRAY
 };
 };
 
 
 /// JSON value class.
 /// JSON value class.
@@ -77,9 +77,9 @@ public:
 
 
     // JSON object value functions
     // JSON object value functions
     /// Create a child value.
     /// Create a child value.
-    JSONValue CreateChild(const String& name, JSONValueType valueType = JVT_OBJECT);
+    JSONValue CreateChild(const String& name, JSONValueType valueType = JSON_OBJECT);
     /// Return a child value by name. Return null if not exist.
     /// Return a child value by name. Return null if not exist.
-    JSONValue GetChild(const String& name, JSONValueType valueType = JVT_UNKNOWN) const;
+    JSONValue GetChild(const String& name, JSONValueType valueType = JSON_ANY) const;
     /// Set int.
     /// Set int.
     void SetInt(const String& name, int value);
     void SetInt(const String& name, int value);
     /// Set bool.
     /// Set bool.
@@ -172,51 +172,51 @@ public:
 
 
     // JSON array value functions
     // JSON array value functions
     /// Create a child value in array.
     /// Create a child value in array.
-    JSONValue CreateChild(JSONValueType valueType = JVT_OBJECT);
+    JSONValue CreateChild(JSONValueType valueType = JSON_OBJECT);
     /// Remove a child value in array. Return null if not exist.
     /// Remove a child value in array. Return null if not exist.
-    JSONValue GetChild(unsigned index, JSONValueType valueType = JVT_UNKNOWN) const;
-    /// Push int.
-    void PushInt(int value);
-    /// Push bool.
-    void PushBool(bool value);
-    /// Push float.
-    void PushFloat(float value);
-    /// Push vector2.
-    void PushVector2(const Vector2& value);
-    /// Push vector3.
-    void PushVector3(const Vector3& value);
-    /// Push vector4.
-    void PushVector4(const Vector4& value);
-    /// Push vector variant.
-    void PushVectorVariant(const Variant& value);
-    /// Push quaternion.
-    void PushQuaternion(const Quaternion& value);
-    /// Push color.
-    void PushColor(const Color& value);
-    /// Push string.
-    void PushString(const String& value);
-    /// Push buffer.
-    void PushBuffer(const PODVector<unsigned char>& value);
-    /// Push buffer.
-    void PushBuffer(const void* data, unsigned size);
-    /// Push resource ref.
-    void PushResourceRef(const ResourceRef& value);
-    /// Push resource ref list.
-    void PushResourceRefList(const ResourceRefList& value);
-    /// Push int rect.
-    void PushIntRect(const IntRect& value);
-    /// Push int vector2.
-    void PushIntVector2(const IntVector2& value);
-    /// Push matrix3.
-    void PushMatrix3(const Matrix3& value);
-    /// Push matrix3x4.
-    void PushMatrix3x4(const Matrix3x4& value);
-    /// Push matrix4.
-    void PushMatrix4(const Matrix4& value);
-    /// Push variant.
-    void PushVariant(const Variant& value);
-    /// Push variant value.
-    void PushVariantValue(const Variant& value);
+    JSONValue GetChild(unsigned index, JSONValueType valueType = JSON_ANY) const;
+    /// Add int.
+    void AddInt(int value);
+    /// Add bool.
+    void AddBool(bool value);
+    /// Add float.
+    void AddFloat(float value);
+    /// Add vector2.
+    void AddVector2(const Vector2& value);
+    /// Add vector3.
+    void AddVector3(const Vector3& value);
+    /// Add vector4.
+    void AddVector4(const Vector4& value);
+    /// Add vector variant.
+    void AddVectorVariant(const Variant& value);
+    /// Add quaternion.
+    void AddQuaternion(const Quaternion& value);
+    /// Add color.
+    void AddColor(const Color& value);
+    /// Add string.
+    void AddString(const String& value);
+    /// Add buffer.
+    void AddBuffer(const PODVector<unsigned char>& value);
+    /// Add buffer.
+    void AddBuffer(const void* data, unsigned size);
+    /// Add resource ref.
+    void AddResourceRef(const ResourceRef& value);
+    /// Add resource ref list.
+    void AddResourceRefList(const ResourceRefList& value);
+    /// Add int rect.
+    void AddIntRect(const IntRect& value);
+    /// Add int vector2.
+    void AddIntVector2(const IntVector2& value);
+    /// Add matrix3.
+    void AddMatrix3(const Matrix3& value);
+    /// Add matrix3x4.
+    void AddMatrix3x4(const Matrix3x4& value);
+    /// Add matrix4.
+    void AddMatrix4(const Matrix4& value);
+    /// Add variant.
+    void AddVariant(const Variant& value);
+    /// Add variant value.
+    void AddVariantValue(const Variant& value);
     /// Is array type.
     /// Is array type.
     bool IsArray() const;
     bool IsArray() const;
     /// Return array size.
     /// Return array size.
@@ -274,8 +274,8 @@ private:
     void AddMember(const String& name, rapidjson::Value& jsonValue);
     void AddMember(const String& name, rapidjson::Value& jsonValue);
     /// Return JSON value by name for object type.
     /// Return JSON value by name for object type.
     rapidjson::Value& GetMember(const String& name) const;
     rapidjson::Value& GetMember(const String& name) const;
-    /// Push JSON value to array type.
-    void PushMember(rapidjson::Value& jsonValue);
+    /// Add JSON value to array type.
+    void AddMember(rapidjson::Value& jsonValue);
     /// Return JSON value by index for array type.
     /// Return JSON value by index for array type.
     rapidjson::Value&  GetMember(unsigned index) const;
     rapidjson::Value&  GetMember(unsigned index) const;