Ver Fonte

Add template version of Context::RegisterSubsystem.

Eugene Kozlov há 8 anos atrás
pai
commit
90f4cf8b8d
1 ficheiros alterados com 10 adições e 1 exclusões
  1. 10 1
      Source/Urho3D/Core/Context.h

+ 10 - 1
Source/Urho3D/Core/Context.h

@@ -113,6 +113,8 @@ public:
     template <class T> void RegisterFactory();
     template <class T> void RegisterFactory();
     /// Template version of registering an object factory with category.
     /// Template version of registering an object factory with category.
     template <class T> void RegisterFactory(const char* category);
     template <class T> void RegisterFactory(const char* category);
+    /// Template version of registering subsystem.
+    template <class T> T* RegisterSubsystem();
     /// Template version of removing a subsystem.
     /// Template version of removing a subsystem.
     template <class T> void RemoveSubsystem();
     template <class T> void RemoveSubsystem();
     /// Template version of registering an object attribute.
     /// Template version of registering an object attribute.
@@ -128,7 +130,7 @@ public:
     Object* GetSubsystem(StringHash type) const;
     Object* GetSubsystem(StringHash type) const;
 
 
     /// Return global variable based on key
     /// Return global variable based on key
-    const Variant& GetGlobalVar(StringHash key) const ;
+    const Variant& GetGlobalVar(StringHash key) const;
 
 
     /// Return all global variables.
     /// Return all global variables.
     const VariantMap& GetGlobalVars() const { return globalVars_; }
     const VariantMap& GetGlobalVars() const { return globalVars_; }
@@ -247,6 +249,13 @@ template <class T> void Context::RegisterFactory(const char* category)
     RegisterFactory(new ObjectFactoryImpl<T>(this), category);
     RegisterFactory(new ObjectFactoryImpl<T>(this), category);
 }
 }
 
 
+template <class T> T* Context::RegisterSubsystem()
+{
+    T* subsystem = new T(this);
+    RegisterSubsystem(subsystem);
+    return subsystem;
+}
+
 template <class T> void Context::RemoveSubsystem() { RemoveSubsystem(T::GetTypeStatic()); }
 template <class T> void Context::RemoveSubsystem() { RemoveSubsystem(T::GetTypeStatic()); }
 
 
 template <class T> AttributeHandle Context::RegisterAttribute(const AttributeInfo& attr) { return RegisterAttribute(T::GetTypeStatic(), attr); }
 template <class T> AttributeHandle Context::RegisterAttribute(const AttributeInfo& attr) { return RegisterAttribute(T::GetTypeStatic(), attr); }