- Timestamp:
- Jan 8, 2013, 1:47:28 AM (12 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/Pacpus/kernel/ComponentFactory.h
r3 r15 1 / / ********************************************************************2 // created: 2006/02/14 - 15:39 3 // filename: ComponentFactory.h 4 // 5 // author: Gerald Dherbomez 6 // 7 // purpose: Template class ComponentFactory. 8 // Use it to interface your components with the application 9 // ********************************************************************* 1 /** 2 * 3 * Distributed under the UTC Heudiascy Pacpus License, Version 1.0. 4 * Copyright (c) UTC Heudiasyc 2010 - 2013. All rights reserved. 5 * 6 * See the LICENSE file for more information or a copy at: 7 * http://www.hds.utc.fr/~kurdejma/LICENSE_1_0.txt 8 * 9 */ 10 10 11 11 #ifndef COMPONENTFACTORY_H 12 12 #define COMPONENTFACTORY_H 13 13 14 #include <cassert> 15 14 16 #include "ComponentFactoryBase.h" 15 17 18 #include <QtGlobal> 16 19 #include <QString> 17 20 … … 23 26 static pacpus::ComponentFactory<className> sFactory(factoryName) 24 27 25 namespace pacpus { 28 namespace pacpus 29 { 30 /** ComponentFactory 31 * @brief Use it to interface your components with the application. 32 * 33 * @example 34 * REGISTER_COMPONENT("DummyComponent", DummyComponent); 35 */ 36 template <typename T> 37 class ComponentFactory 38 : public ComponentFactoryBase 39 { 40 public: 41 /** Ctor of ComponentFactory, initialize the factory of the components of type @em T. 42 * @param type Name of the type of the components. 43 */ 44 ComponentFactory(const QString& type); 45 46 /** Dtor of ComponentFactory. */ 47 virtual ~ComponentFactory(); 26 48 27 template <typename T> 28 class ComponentFactory 29 : public ComponentFactoryBase 30 { 31 public: 32 ComponentFactory(QString type); 33 virtual ~ComponentFactory(); 49 /** Get the name of the type of the components. 50 * @return Name of the type of the components. 51 */ 52 const QString& getType() const; 34 53 35 const QString & getType() const; 54 protected: 55 virtual ComponentBase* instantiateComponent(const QString& name); 56 57 private: 58 QString mType; 59 }; 36 60 37 protected:38 virtual ComponentBase * instantiateComponent(const QString & name);39 61 40 private: 41 QString mType; 42 }; 62 template <typename T> 63 ComponentFactory<T>::ComponentFactory(const QString& type) 64 : mType(type) 65 { 66 assert(!type.isEmpty()); 67 addFactory(this, mType); 68 } 43 69 44 //////////////////////////////////////////////////////////////////////////////// 45 template <typename T> 46 ComponentFactory<T>::ComponentFactory(QString type) 47 : mType(type) 48 { 49 addFactory(this, mType); 70 template<typename T> 71 ComponentFactory<T>::~ComponentFactory() 72 { 73 } 74 75 template <typename T> 76 const QString& ComponentFactory<T>::getType() const 77 { 78 return mType; 79 } 80 81 template<typename T> 82 ComponentBase* ComponentFactory<T>::instantiateComponent(const QString& name) 83 { 84 return new T(name); 85 } 50 86 } 51 87 52 template<typename T>53 ComponentFactory<T>::~ComponentFactory()54 {55 }56 57 template <typename T>58 const QString & ComponentFactory<T>::getType() const59 {60 return mType;61 }62 63 template<typename T>64 ComponentBase * ComponentFactory<T>::instantiateComponent(const QString & name)65 {66 T * component = new T(name);67 return component;68 }69 70 } // namespace pacpus71 72 88 #endif // COMPONENTFACTORY_H -
trunk/src/PacpusLib/ComponentManager.cpp
r3 r15 1 1 #include "kernel/ComponentManager.h" 2 3 2 #include "kernel/ComponentBase.h" 4 3 #include "kernel/Log.h" 5 4 6 namespace pacpus { 5 using namespace pacpus; 7 6 8 7 DECLARE_STATIC_LOGGER("pacpus.core.ComponentManager"); … … 338 337 return xmlTree_->getAllComponents(); 339 338 } 340 341 } // namespace pacpus
Note:
See TracChangeset
for help on using the changeset viewer.