source: pacpusframework/trunk/include/Pacpus/kernel/ComponentFactory.h@ 12

Last change on this file since 12 was 3, checked in by sgosseli, 12 years ago
  • Add the existing Pacpus files from pacpusdev and pacpuscore.
  • Provide a clean build system based on multiple CMake files.
File size: 1.6 KB
Line 
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// *********************************************************************
10
11#ifndef COMPONENTFACTORY_H
12#define COMPONENTFACTORY_H
13
14#include "ComponentFactoryBase.h"
15
16#include <QString>
17
18/** Register a component to the factory.
19 * @className Name of the class, without the quotes.
20 * @factoryName Name of the class in the factory.
21 */
22#define REGISTER_COMPONENT(className, factoryName) \
23 static pacpus::ComponentFactory<className> sFactory(factoryName)
24
25namespace pacpus {
26
27template <typename T>
28class ComponentFactory
29 : public ComponentFactoryBase
30{
31public:
32 ComponentFactory(QString type);
33 virtual ~ComponentFactory();
34
35 const QString & getType() const;
36
37protected:
38 virtual ComponentBase * instantiateComponent(const QString & name);
39
40private:
41 QString mType;
42};
43
44////////////////////////////////////////////////////////////////////////////////
45template <typename T>
46ComponentFactory<T>::ComponentFactory(QString type)
47 : mType(type)
48{
49 addFactory(this, mType);
50}
51
52template<typename T>
53ComponentFactory<T>::~ComponentFactory()
54{
55}
56
57template <typename T>
58const QString & ComponentFactory<T>::getType() const
59{
60 return mType;
61}
62
63template<typename T>
64ComponentBase * ComponentFactory<T>::instantiateComponent(const QString & name)
65{
66 T * component = new T(name);
67 return component;
68}
69
70} // namespace pacpus
71
72#endif // COMPONENTFACTORY_H
Note: See TracBrowser for help on using the repository browser.