TSimComponentsFactory.h
Go to the documentation of this file.
1 #ifndef icomp_TSimComponentsFactory_included
2 #define icomp_TSimComponentsFactory_included
3 
4 
5 // ACF includes
6 #include <istd/TIFactory.h>
7 #include <istd/CClassInfo.h>
8 
9 #include <icomp/IComponent.h>
10 #include <icomp/TComponentWrap.h>
12 
13 
14 namespace icomp
15 {
16 
17 
24 template <class Base>
25 class TSimComponentsFactory: public TSimComponentWrap<Base>, public istd::TIFactory<icomp::IComponent>
26 {
27 public:
29 
31 
32  // reimplemented (istd::IFactoryInfo)
34 
35  // reimplemented (istd::TIFactory<icomp::IComponent>)
36  virtual icomp::IComponent* CreateInstance(const QByteArray& keyId = "") const;
37 
38  // reimplemented (icomp::ICompositeComponent)
39  virtual IComponent* CreateSubcomponent(const QByteArray& componentId) const;
40 
41 private:
42  KeyList m_factoryKeys;
43 };
44 
45 
46 // public methods
47 
48 template <class Base>
50 {
51  m_factoryKeys.insert(istd::CClassInfo::GetName<Base>());
52 }
53 
54 
55 // reimplemented (istd::IFactoryInfo)
56 
57 template <class Base>
59 {
60  return m_factoryKeys;
61 }
62 
63 
64 // reimplemented (istd::TIFactory<icomp::IComponent>)
65 
66 template <class Base>
68 {
69  if (keyId.isEmpty() || m_factoryKeys.contains(keyId)){
71  if (retVal != NULL){
72  retVal->SetComponentContext(this, this, false);
73  return retVal;
74  }
75  }
76 
77  return NULL;
78 }
79 
80 
81 // reimplemented (icomp::ICompositeComponent)
82 
83 template <class Base>
84 IComponent* TSimComponentsFactory<Base>::CreateSubcomponent(const QByteArray& componentId) const
85 {
86  IComponent* componentPtr = BaseClass::CreateSubcomponent(componentId);
87  if (componentPtr != NULL){
88  return componentPtr;
89  }
90 
91  return CreateInstance(componentId);
92 }
93 
94 
95 } // namespace icomp
96 
97 
98 #endif // !icomp_TSimComponentsFactory_included
99 
100 
QSet< QByteArray > KeyList
Definition: IFactoryInfo.h:23
virtual istd::IFactoryInfo::KeyList GetFactoryKeys() const
Returns all posible keys for this factory.
Main component interface.
Definition: IComponent.h:31
TSimComponentWrap< Base > BaseClass
Simulation wrapper of component.
Generic interface for a factory.
Definition: TIFactory.h:17
Simulation wrapper of component.
virtual void SetComponentContext(const icomp::IComponentContext *contextPtr, const ICompositeComponent *parentPtr, bool isParentOwner)=0
Set component context of this component.
virtual IComponent * CreateSubcomponent(const QByteArray &componentId) const
Create instance of subcomponent using its ID.
#define NULL
Definition: istd.h:64
virtual icomp::IComponent * CreateInstance(const QByteArray &keyId="") const
Create an instance of the object, mapped to the keyId keyId.

© 2007-2017 Witold Gantzke and Kirill Lepskiy