Changeset 9637 for code/branches/core6/src
- Timestamp:
- Aug 11, 2013, 4:23:41 PM (11 years ago)
- Location:
- code/branches/core6/src/libraries/core
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core6/src/libraries/core/CoreIncludes.h
r9635 r9637 117 117 */ 118 118 #define CreateFactory(ClassName) \ 119 RegisterFactory(ClassName, new orxonox::ClassFactoryWithContext<ClassName>( #ClassName, true))119 RegisterFactory(ClassName, new orxonox::ClassFactoryWithContext<ClassName>(), true) 120 120 121 121 /** … … 124 124 */ 125 125 #define CreateUnloadableFactory(ClassName) \ 126 RegisterFactory(ClassName, new orxonox::ClassFactoryWithContext<ClassName>( #ClassName, false))126 RegisterFactory(ClassName, new orxonox::ClassFactoryWithContext<ClassName>(), false) 127 127 128 128 /** … … 130 130 @param ClassName The name of the class 131 131 */ 132 #define RegisterFactory(ClassName, FactoryInstance ) \133 Factory* _##ClassName##Factory = FactoryInstance132 #define RegisterFactory(ClassName, FactoryInstance, bLoadable) \ 133 Identifier* _##ClassName##Identifier = orxonox::registerClass<ClassName>(#ClassName, FactoryInstance, bLoadable) 134 134 135 135 /** … … 143 143 namespace orxonox 144 144 { 145 /** 146 * @brief Overload of registerClass() which determines T implicitly by the template argument of the ClassFactory. 147 */ 148 template <class T> 149 inline Identifier* registerClass(const std::string& name, ClassFactory<T>* factory, bool bLoadable = true) 150 { 151 return registerClass<T>(name, static_cast<Factory*>(factory), bLoadable); 152 } 153 154 /** 155 * @brief Registers a class in the framework. 156 * @param name The name of the class 157 * @param factory The factory which is able to create new instances of this class 158 * @param bLoadable Whether the class is allowed to be loaded through XML 159 */ 160 template <class T> 161 inline Identifier* registerClass(const std::string& name, Factory* factory, bool bLoadable = true) 162 { 163 orxout(verbose, context::misc::factory) << "Create entry for " << name << " in Factory." << endl; 164 Identifier* identifier = ClassIdentifier<T>::getIdentifier(name); 165 identifier->setFactory(factory); 166 identifier->setLoadable(bLoadable); 167 return identifier; 168 } 169 145 170 /** 146 171 @brief Returns the Identifier with a given name. -
code/branches/core6/src/libraries/core/object/ClassFactory.h
r9635 r9637 43 43 44 44 #include "util/Output.h" 45 #include "core/class/Identifier.h"46 45 47 46 namespace orxonox … … 54 53 { 55 54 public: 56 virtual ~Factory() {} ;55 virtual ~Factory() {} 57 56 virtual Identifiable* fabricate(Context* context) = 0; 58 57 }; … … 61 60 // ### ClassFactory ### 62 61 // ############################### 63 /// The ClassFactory is able to create new objects of a specific class that require no constructor arguments.62 /// The ClassFactory is the base-class of all class-spezific factories 64 63 template <class T> 65 64 class ClassFactory : public Factory 66 65 { 66 }; 67 68 // ############################### 69 // ### ClassFactoryNoArgs ### 70 // ############################### 71 /// The ClassFactoryNoArgs is able to create new objects of a specific class that require no constructor arguments. 72 template <class T> 73 class ClassFactoryNoArgs : public ClassFactory<T> 74 { 67 75 public: 68 /**69 @brief Constructor: Adds the ClassFactory to the Identifier of the same type.70 @param name The name of the class71 @param bLoadable True if the class can be loaded through XML72 */73 ClassFactory(const std::string& name, bool bLoadable = true)74 {75 orxout(verbose, context::misc::factory) << "Create entry for " << name << " in Factory." << endl;76 ClassIdentifier<T>::getIdentifier(name)->setFactory(this);77 ClassIdentifier<T>::getIdentifier()->setLoadable(bLoadable);78 }79 80 76 /** 81 77 @brief Creates and returns a new object of class T. … … 93 89 /// The ClassFactoryWithContext is able to create new objects of a specific class that require a context as constructor argument 94 90 template <class T> 95 class ClassFactoryWithContext : public Factory91 class ClassFactoryWithContext : public ClassFactory<T> 96 92 { 97 93 public: 98 /**99 @brief Constructor: Adds the ClassFactory to the Identifier of the same type.100 @param name The name of the class101 @param bLoadable True if the class can be loaded through XML102 */103 ClassFactoryWithContext(const std::string& name, bool bLoadable = true)104 {105 orxout(verbose, context::misc::factory) << "Create entry for " << name << " in Factory." << endl;106 ClassIdentifier<T>::getIdentifier(name)->setFactory(this);107 ClassIdentifier<T>::getIdentifier()->setLoadable(bLoadable);108 }109 110 94 /** 111 95 @brief Creates and returns a new object of class T.
Note: See TracChangeset
for help on using the changeset viewer.