New feature to allow to register components with different names for same class:...
[anna.git] / include / anna / core / functions.hpp
index b2a24ab..0ceb358 100644 (file)
@@ -620,34 +620,50 @@ struct functions {
   //////////////////////////////////////////////////////////////////////////////////////////////////
 
   /**
-     Pattern to obtain a component instance easily.
+     Pattern to obtain a multi named component instance easily.
      Parameters are usually replaced by the macro C <b>FILE_LOCATION</b>.
 
+     \param className Component class name
      \param fromFile File which called the method
      \param fromLine Line number within the file from where the method is called.
 
      \return Component instance for the class provided at the pattern
-     \warning The class T must define:
-     \code
-         static const char* getClassName () throw ();
-     \endcode
      \see Component
   */
-  template <typename T> static T* component(const char* fromFile, const int fromLine)
+  template <typename T> static T* componentByName(const char *className, const char* fromFile, const int fromLine)
   throw(RuntimeException) {
     ComponentManager &cm = ComponentManager::instantiate();
-    const char *className = T::getClassName();
     T* result = static_cast <T*>(cm.find(className));
 
     if(result == NULL) {
       std::string msg(className);
-      msg += " | Componente no registrado";
+      msg += " | Unregistered component";
       throw RuntimeException(msg, fromFile, fromLine);
     }
 
     return result;
   }
 
+  /**
+     Pattern to obtain a single named component instance easily.
+     Parameters are usually replaced by the macro C <b>FILE_LOCATION</b>.
+
+     \param fromFile File which called the method
+     \param fromLine Line number within the file from where the method is called.
+
+     \return Component instance for the class provided at the pattern
+     \warning T class must implement a method in the form:
+     \code
+         static const char* getClassName () throw ();
+     \endcode
+     \see Component
+  */
+  template <typename T> static T* component(const char* fromFile, const int fromLine)
+  throw(RuntimeException) {
+    return functions::componentByName<T> (T::getClassName(), fromFile, fromLine);
+  }
+
+
   /**
    * Gets exclusive hash for string provided on integer range
    *