source: pacpusframework/branches/0.1.x/include/Pacpus/kernel/ComponentFactory.h@ 253

Last change on this file since 253 was 89, checked in by morasjul, 11 years ago

PACPUS 2.0 Beta deployed in new branch

Major changes:
-Add communication interface between components
-Add examples for communications interface (TestComponents)
-Move to Qt5 support

  • Property svn:executable set to *
File size: 2.8 KB
Line 
1// %pacpus:license{
2// This file is part of the PACPUS framework distributed under the
3// CECILL-C License, Version 1.0.
4// %pacpus:license}
5/// @file
6/// @author Gerald Dherbomez <firstname.surname@utc.fr>
7/// @date February, 2006
8/// @version $Id: ComponentFactory.h 76 2013-01-10 17:05:10Z kurdejma $
9/// @copyright Copyright (c) UTC/CNRS Heudiasyc 2006 - 2013. All rights reserved.
10/// @brief Brief description.
11///
12/// Purpose: Template class ComponentFactory.
13/// Use it to interface your components with the application.
14
15#ifndef DEF_PACPUS_COMPONENTFACTORY_H
16#define DEF_PACPUS_COMPONENTFACTORY_H
17
18#include <cassert>
19
20//#include <boost/static_assert.hpp>
21//#include <boost/type_traits/is_base_of.hpp>
22
23#include <Pacpus/kernel/ComponentFactoryBase.h>
24
25#include <QtGlobal>
26#include <QString>
27
28/// @def REGISTER_COMPONENT(className, factoryName)
29/// Registers a component to the factory.
30///
31/// @param className Name of the class, without the quotes.
32/// @param factoryName Name of the class in the factory.
33/// @example
34/// REGISTER_COMPONENT("DummyComponent", DummyComponent);
35/// @see pacpus::ComponentFactory
36#define REGISTER_COMPONENT(className, factoryName) \
37 static pacpus::ComponentFactory<className> sFactory(factoryName)
38
39namespace pacpus {
40
41/// Use it to interface your components with the application.
42///
43/// @tparam T Component class
44/// @see #REGISTER_COMPONENT(className, factoryName)
45template <typename T>
46class ComponentFactory
47 : public ComponentFactoryBase
48{
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");
51public:
52 /** Ctor of ComponentFactory, initialize the factory of the components of type @em T.
53 * @param type Name of the type of the components.
54 */
55 ComponentFactory(const QString& type);
56
57 /** Dtor of ComponentFactory. */
58 virtual ~ComponentFactory();
59
60 /** Get the name of the type of the components.
61 * @return Name of the type of the components.
62 */
63 const QString& getType() const;
64
65protected:
66 virtual ComponentBase* instantiateComponent(const QString& name);
67
68private:
69 QString mType;
70};
71
72template <typename T>
73ComponentFactory<T>::ComponentFactory(const QString& type)
74 : mType(type)
75{
76 assert(!type.isEmpty());
77 addFactory(this, mType);
78}
79
80template<typename T>
81ComponentFactory<T>::~ComponentFactory()
82{
83}
84
85template <typename T>
86const QString& ComponentFactory<T>::getType() const
87{
88 return mType;
89}
90
91template<typename T>
92ComponentBase* ComponentFactory<T>::instantiateComponent(const QString& name)
93{
94 return new T(name);
95}
96
97} // pacpus
98
99#endif // DEF_PACPUS_DBITEEXCEPTION_H
Note: See TracBrowser for help on using the repository browser.