TSimComponentWrap.h
Go to the documentation of this file.
1 #ifndef icomp_TSimComponentWrap_included
2 #define icomp_TSimComponentWrap_included
3 
4 
5 // ACF includes
6 #include <istd/CClassInfo.h>
8 #include <icomp/TComponentWrap.h>
10 
11 
12 namespace icomp
13 {
14 
15 
22 template <class Base>
24  public TComponentWrap<Base>,
26  virtual public ICompositeComponent
27 {
28 public:
31 
33 
37  void InitComponent();
38 
39  // reimplemented (icomp::IComponentContext)
40  virtual const QByteArray& GetContextId() const;
41 
42  // reimplemented (icomp::ICompositeComponent)
43  virtual IComponent* GetSubcomponent(const QByteArray& componentId) const;
44  virtual const IComponentContext* GetSubcomponentContext(const QByteArray& componentId) const;
45  virtual IComponent* CreateSubcomponent(const QByteArray& componentId) const;
46  virtual void OnSubcomponentDeleted(const IComponent* subcomponentPtr);
47 
48  // reimplemented (icomp::IComponent)
49  virtual const ICompositeComponent* GetParentComponent(bool ownerOnly = false) const;
50 };
51 
52 
53 // public methods
54 
55 template <class Base>
57 : BaseClass(),
58  BaseClass2(&BaseClass::GetComponentStaticInfo())
59 {
60 }
61 
62 
63 template <class Base>
65 {
66  SetComponentContext(this, NULL, false);
67 }
68 
69 
70 // reimplemented (icomp::IComponentContext)
71 
72 template <class Base>
73 const QByteArray& TSimComponentWrap<Base>::GetContextId() const
74 {
75  static QByteArray id = istd::CClassInfo::GetName<Base>();
76 
77  return id;
78 }
79 
80 
81 // reimplemented (icomp::ICompositeComponent)
82 
83 template <class Base>
84 IComponent* TSimComponentWrap<Base>::GetSubcomponent(const QByteArray& componentId) const
85 {
86  BaseClass2::ComponentsMap::ConstIterator iter = BaseClass2::m_componentsMap.constFind(componentId);
87 
88  if (iter != BaseClass2::m_componentsMap.constEnd()){
89  return iter.value();
90  }
91 
92  return NULL;
93 }
94 
95 
96 template <class Base>
97 const IComponentContext* TSimComponentWrap<Base>::GetSubcomponentContext(const QByteArray& /*componentId*/) const
98 {
99  return NULL;
100 }
101 
102 
103 template <class Base>
104 IComponent* TSimComponentWrap<Base>::CreateSubcomponent(const QByteArray& componentId) const
105 {
106  FactoriesMap::ConstIterator iter = m_factoriesMap.constFind(componentId);
107  if (iter != m_factoriesMap.constEnd()){
108  Q_ASSERT(iter.value() != NULL);
109 
110  return iter.value()->CreateInstance();
111  }
112 
113  return NULL;
114 }
115 
116 
117 template <class Base>
119 {
120  qFatal("Simulated component cannot have sub-components");
121 }
122 
123 
124 // reimplemented (icomp::IComponent)
125 
126 template <class Base>
128 {
129  if (ownerOnly){
130  return NULL;
131  }
132  else{
133  return const_cast<TSimComponentWrap<Base>* >(this);
134  }
135 }
136 
137 
138 } // namespace icomp
139 
140 
141 #endif // !icomp_TSimComponentWrap_included
142 
143 
virtual const ICompositeComponent * GetParentComponent(bool ownerOnly=false) const
Get parent of this component.
virtual void OnSubcomponentDeleted(const IComponent *subcomponentPtr)
Called if subcomponent is removed from memory.
virtual const IComponentContext * GetSubcomponentContext(const QByteArray &componentId) const
Get access to context of subcomponent using its ID.
Main component interface.
Definition: IComponent.h:31
Wrapper of end component implementation used to correct control of component life-cycle.
Provide session context of component.
virtual const QByteArray & GetContextId() const
Get ID of this component in the context tree.
virtual IComponent * CreateSubcomponent(const QByteArray &componentId) const
Create instance of subcomponent using its ID.
Simulation wrapper of component.
void InitComponent()
Initialilze component after setting all its attributes and references.
#define NULL
Definition: istd.h:64
virtual IComponent * GetSubcomponent(const QByteArray &componentId) const
Get access to subcomponent using its ID.
CSimComponentContextBase BaseClass2
TComponentWrap< Base > BaseClass
Composite component interface.

© 2007-2017 Witold Gantzke and Kirill Lepskiy