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

Last change on this file since 71 was 71, checked in by Marek Kurdej, 11 years ago

Added: more documentation.
doc/doxyfile.in: turned on BUILTIN_STL_SUPPORT in Doxygen.
Added: LICENSE-header.txt to be included in all source files.

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