/** * * Distributed under the UTC Heudiascy Pacpus License, Version 1.0. * Copyright (c) UTC Heudiasyc 2010 - 2013. All rights reserved. * * See the LICENSE file for more information or a copy at: * http://www.hds.utc.fr/~kurdejma/LICENSE_1_0.txt * */ #ifndef COMPONENTFACTORY_H #define COMPONENTFACTORY_H #include #include "ComponentFactoryBase.h" #include #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 { /** ComponentFactory * @brief Use it to interface your components with the application. * * @example * REGISTER_COMPONENT("DummyComponent", DummyComponent); */ template class ComponentFactory : public ComponentFactoryBase { public: /** Ctor of ComponentFactory, initialize the factory of the components of type @em T. * @param type Name of the type of the components. */ ComponentFactory(const QString& type); /** Dtor of ComponentFactory. */ virtual ~ComponentFactory(); /** Get the name of the type of the components. * @return Name of the type of the components. */ const QString& getType() const; protected: virtual ComponentBase* instantiateComponent(const QString& name); private: QString mType; }; template ComponentFactory::ComponentFactory(const QString& type) : mType(type) { assert(!type.isEmpty()); addFactory(this, mType); } template ComponentFactory::~ComponentFactory() { } template const QString& ComponentFactory::getType() const { return mType; } template ComponentBase* ComponentFactory::instantiateComponent(const QString& name) { return new T(name); } } #endif // COMPONENTFACTORY_H