Changeset 288 in pacpusframework for trunk/include/Pacpus/kernel/ComponentFactory.h
- Timestamp:
- 03/26/14 21:27:30 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/Pacpus/kernel/ComponentFactory.h
r89 r288 16 16 #define DEF_PACPUS_COMPONENTFACTORY_H 17 17 18 #include <cassert> 19 20 //#include <boost/static_assert.hpp> 21 //#include <boost/type_traits/is_base_of.hpp> 18 #include <boost/assert.hpp> 19 #include <boost/static_assert.hpp> 20 #include <boost/type_traits/is_base_of.hpp> 22 21 23 22 #include <Pacpus/kernel/ComponentFactoryBase.h> … … 37 36 static pacpus::ComponentFactory<className> sFactory(factoryName) 38 37 39 namespace pacpus { 38 #define PACPUS_REGISTER_COMPONENT(Class) \ 39 static pacpus::ComponentFactory<Class> sFactory(#Class) 40 41 namespace pacpus 42 { 40 43 41 44 /// Use it to interface your components with the application. … … 47 50 : public ComponentFactoryBase 48 51 { 49 //static_assert(,"T must inherit from ComponentBase")50 // BOOST_STATIC_ASSERT_MSG((boost::is_base_of<ComponentBase, T>::value), "T must inherit from ComponentBase"); 52 BOOST_STATIC_ASSERT_MSG((boost::is_base_of<ComponentBase, T>::value), "component T must inherit from ComponentBase"); 53 51 54 public: 52 55 /** Ctor of ComponentFactory, initialize the factory of the components of type @em T. 53 56 * @param type Name of the type of the components. 54 57 */ 55 ComponentFactory( const QString& type);58 ComponentFactory(QString const& type); 56 59 57 60 /** Dtor of ComponentFactory. */ … … 61 64 * @return Name of the type of the components. 62 65 */ 63 const QString& getType() const;66 QString const& getType() const; 64 67 65 68 protected: 66 virtual Component Base* instantiateComponent(const QString& name);67 69 virtual ComponentSharedPointer instantiateComponent(QString const& name); 70 68 71 private: 69 72 QString mType; … … 71 74 72 75 template <typename T> 73 ComponentFactory<T>::ComponentFactory( const QString& type)74 : mType(type)76 ComponentFactory<T>::ComponentFactory(QString const& type) 77 : mType(type) 75 78 { 76 assert(!type.isEmpty());79 BOOST_ASSERT(!type.isEmpty()); 77 80 addFactory(this, mType); 78 81 } … … 84 87 85 88 template <typename T> 86 const QString& ComponentFactory<T>::getType() const89 QString const& ComponentFactory<T>::getType() const 87 90 { 88 91 return mType; … … 90 93 91 94 template<typename T> 92 Component Base* ComponentFactory<T>::instantiateComponent(const QString& name)95 ComponentSharedPointer ComponentFactory<T>::instantiateComponent(QString const& name) 93 96 { 94 return new T(name);97 return ComponentSharedPointer(new T(name)); 95 98 } 96 99 97 } // pacpus100 } // namespace pacpus 98 101 99 102 #endif // DEF_PACPUS_DBITEEXCEPTION_H
Note:
See TracChangeset
for help on using the changeset viewer.