Explorar el Código

Minor refactor, add comment to type info.

aster2013 hace 10 años
padre
commit
a1105f7d38
Se han modificado 3 ficheros con 35 adiciones y 31 borrados
  1. 21 10
      Source/Urho3D/Core/Object.cpp
  2. 13 20
      Source/Urho3D/Core/Object.h
  3. 1 1
      Source/Urho3D/UI/UIElement.h

+ 21 - 10
Source/Urho3D/Core/Object.cpp

@@ -32,29 +32,40 @@
 namespace Urho3D
 {
 
-bool TypeInfo::IsTypeOf(StringHash theType) const
+TypeInfo::TypeInfo(const char* typeName, const TypeInfo* baseTypeInfo) :
+	type_(typeName),
+	typeName_(typeName),
+	baseTypeInfo_(baseTypeInfo)
 {
-    const TypeInfo* typeInfo = this;
-    while (typeInfo)
+}
+
+TypeInfo::~TypeInfo()
+{
+}
+
+bool TypeInfo::IsTypeOf(StringHash type) const
+{
+    const TypeInfo* current = this;
+    while (current)
     {
-        if (typeInfo->GetType() == theType)
+        if (current->GetType() == type)
             return true;
 
-        typeInfo = typeInfo->GetBaseTypeInfo();
+        current = current->GetBaseTypeInfo();
     }
 
     return false;
 }
 
-bool TypeInfo::IsTypeOf(const TypeInfo* theTypeInfo) const
+bool TypeInfo::IsTypeOf(const TypeInfo* typeInfo) const
 {
-    const TypeInfo* typeInfo = this;
-    while (typeInfo)
+    const TypeInfo* current = this;
+    while (current)
     {
-        if (typeInfo == theTypeInfo)
+        if (current == typeInfo)
             return true;
 
-        typeInfo = typeInfo->GetBaseTypeInfo();
+        current = current->GetBaseTypeInfo();
     }
 
     return false;

+ 13 - 20
Source/Urho3D/Core/Object.h

@@ -36,22 +36,15 @@ class URHO3D_API TypeInfo
 {
 public:
     /// Construct.
-    TypeInfo(const char* typeName, const TypeInfo* baseTypeInfo) :
-        type_(typeName),
-        typeName_(typeName),
-        baseTypeInfo_(baseTypeInfo)
-    {
-    }
+    TypeInfo(const char* typeName, const TypeInfo* baseTypeInfo);
     /// Destruct.
-    ~TypeInfo()
-    {
-    }
+    ~TypeInfo();
 
-    /// Return is type of.
-    bool IsTypeOf(StringHash theType) const;
-    /// Return is type of.
-    bool IsTypeOf(const TypeInfo* theTypeInfo) const;
-    /// Return is type of.
+	/// Check current type is type of specified type.
+    bool IsTypeOf(StringHash type) const;
+	/// Check current type is type of specified type.
+    bool IsTypeOf(const TypeInfo* typeInfo) const;
+	/// Check current type is type of specified class type.
     template<typename T> bool IsTypeOf() const { return IsTypeOf(T::GetTypeInfoStatic()); }
     
     /// Return type.
@@ -103,17 +96,17 @@ public:
 
     /// Return type info static.
     static const TypeInfo* GetTypeInfoStatic() { return 0; }
-    /// Check current type is type of.
+	/// Check current type is type of specified type.
     static bool IsTypeOf(StringHash type);
-    /// Check current type is type of.
+	/// Check current type is type of specified type.
     static bool IsTypeOf(const TypeInfo* typeInfo);
-    /// Check current type is type of T.
+	/// Check current type is type of specified class.
     template<typename T> static bool IsTypeOf() { return IsTypeOf(T::GetTypeInfoStatic()); }
-    /// Check current instance is type of.
+    /// Check current instance is type of specified type.
     bool IsInstanceOf(StringHash type) const;
-    /// Check current instance is type of.
+	/// Check current instance is type of specified type.
     bool IsInstanceOf(const TypeInfo* typeInfo) const;
-    /// Check current instance is type of T.
+	/// Check current instance is type of specified class.
     template<typename T> bool IsInstanceOf() const { return IsInstanceOf(T::GetTypeInfoStatic()); }
 
     /// Subscribe to an event that can be sent by any sender.

+ 1 - 1
Source/Urho3D/UI/UIElement.h

@@ -708,7 +708,7 @@ private:
 
 template <class T> T* UIElement::CreateChild(const String& name, unsigned index)
 {
-    return static_cast<T*>(CreateChild(T::GetTypeInfoStatic()->GetType(), name, index));
+	return static_cast<T*>(CreateChild(T::GetTypeStatic(), name, index));
 }
 
 }