/*! @file ClassFactory.h @brief Definition and implementation of the ClassFactory class The ClassFactory is able to create new objects of a specific class. */ #ifndef _ClassFactory_H__ #define _ClassFactory_H__ #include "Identifier.h" namespace orxonox { // ############################### // ### ClassFactory ### // ############################### //! The ClassFactory is able to create new objects of a specific class. template class ClassFactory : public BaseFactory { public: static bool create(const std::string& name); BaseObject* fabricate(); private: ClassFactory() {} // Don't create ClassFactory(const ClassFactory& factory) {} // Don't copy ~ClassFactory() {} // Don't delete static T* createNewObject(); }; /** @brief Adds the ClassFactory to the Identifier of the same type and the Identifier to the Factory. @return Always true (this is needed because the compiler only allows assignments before main()) */ template bool ClassFactory::create(const std::string& name) { ClassIdentifier::getIdentifier()->addFactory(new ClassFactory); Factory::add(name, ClassIdentifier::getIdentifier()); return true; } /** @brief Creates and returns a new object of class T. @return The new object */ template BaseObject* ClassFactory::fabricate() { return ClassFactory::createNewObject(); } /** @brief Creates and returns a new object of class T; this is a wrapper for the new operator. @return The new object */ template T* ClassFactory::createNewObject() { return new T; } } #endif