// ******************************************************************** // created: 2006/02/14 - 15:39 // filename: ComponentFactory.h // // author: Gerald Dherbomez // // purpose: Template class ComponentFactory. // Use it to interface your components with the application // ********************************************************************* #ifndef COMPONENTFACTORY_H #define COMPONENTFACTORY_H #include "ComponentFactoryBase.h" #include /** Register a component to the factory. * @className Name of the class, without the quotes. * @factoryName Name of the class in the factory. */ #define REGISTER_COMPONENT(className, factoryName) \ static pacpus::ComponentFactory sFactory(factoryName) namespace pacpus { template class ComponentFactory : public ComponentFactoryBase { public: ComponentFactory(QString type); virtual ~ComponentFactory(); const QString & getType() const; protected: virtual ComponentBase * instantiateComponent(const QString & name); private: QString mType; }; //////////////////////////////////////////////////////////////////////////////// template ComponentFactory::ComponentFactory(QString type) : mType(type) { addFactory(this, mType); } template ComponentFactory::~ComponentFactory() { } template const QString & ComponentFactory::getType() const { return mType; } template ComponentBase * ComponentFactory::instantiateComponent(const QString & name) { T * component = new T(name); return component; } } // namespace pacpus #endif // COMPONENTFACTORY_H