Changeset 9667 for code/trunk/src/libraries/core/object/ClassFactory.h
- Timestamp:
- Aug 25, 2013, 9:08:42 PM (12 years ago)
- Location:
- code/trunk
- Files:
-
- 2 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
/code/branches/core6 merged: 9552-9554,9556-9574,9577-9579,9585-9593,9596-9612,9626-9662
- Property svn:mergeinfo changed
-
code/trunk/src/libraries/core/object/ClassFactory.h
r9563 r9667 43 43 44 44 #include "util/Output.h" 45 #include "core/class/Identifier.h"46 45 47 46 namespace orxonox … … 50 49 // ### Factory ### 51 50 // ########################### 52 /// Base-class of ClassFactory.51 /// Base-class of all factories. 53 52 class _CoreExport Factory 54 53 { 55 54 public: 56 virtual ~Factory() {} ;57 virtual OrxonoxClass* fabricate(BaseObject* creator) = 0;55 virtual ~Factory() {} 56 virtual Identifiable* fabricate(Context* context) = 0; 58 57 }; 59 58 … … 61 60 // ### ClassFactory ### 62 61 // ############################### 63 /// The ClassFactory is able to create new objects of a specific class.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)->addFactory(this);77 ClassIdentifier<T>::getIdentifier()->setLoadable(bLoadable);78 }79 80 76 /** 81 77 @brief Creates and returns a new object of class T. 82 78 @return The new object 83 79 */ 84 inline OrxonoxClass* fabricate(BaseObject* creator)80 inline Identifiable* fabricate(Context* context) 85 81 { 86 return static_cast<OrxonoxClass*>(new T(creator)); 82 return static_cast<Identifiable*>(new T()); 83 } 84 }; 85 86 // ############################### 87 // ### ClassFactoryWithContext ### 88 // ############################### 89 /// The ClassFactoryWithContext is able to create new objects of a specific class that require a context as constructor argument 90 template <class T> 91 class ClassFactoryWithContext : public ClassFactory<T> 92 { 93 public: 94 /** 95 @brief Creates and returns a new object of class T. 96 @return The new object 97 */ 98 inline Identifiable* fabricate(Context* context) 99 { 100 return static_cast<Identifiable*>(new T(context)); 87 101 } 88 102 };
Note: See TracChangeset
for help on using the changeset viewer.