CComponentBase.h
Go to the documentation of this file.
1 #ifndef icomp_CComponentBase_included
2 #define icomp_CComponentBase_included
3 
4 
5 // ACF includes
6 #include <istd/CClassInfo.h>
7 #include <iattr/TAttribute.h>
9 #include <icomp/IComponent.h>
13 #include <icomp/TAttributeMember.h>
15 #include <icomp/TReferenceMember.h>
17 #include <icomp/TFactoryMember.h>
24 
25 
26 namespace icomp
27 {
28 
29 
37 class CComponentBase: virtual public IComponent
38 {
39 public:
44 
45  // reimplemented (icomp::IComponent)
46  virtual const ICompositeComponent* GetParentComponent(bool ownerOnly = false) const;
47  virtual void* GetInterface(const istd::CClassInfo& interfaceType, const QByteArray& subId = "");
48  virtual const IComponentContext* GetComponentContext() const;
49  virtual void SetComponentContext(
50  const icomp::IComponentContext* contextPtr,
51  const ICompositeComponent* parentPtr,
52  bool isParentOwner);
53 
54 protected:
59  bool IsComponentActive() const;
60 
61  virtual void OnComponentCreated();
62  virtual void OnComponentDestroyed();
63 
64  // abstract methods
69 
70  // static protected methods
71  static const icomp::IRealComponentStaticInfo& InitStaticInfo(IComponent* componentPtr);
72  static QByteArray GetComponentId(const icomp::IComponentContext* componentContextPtr, const QByteArray& contextId = QByteArray());
73 
74 private:
75  Q_DISABLE_COPY(CComponentBase)
76 
77  const IComponentContext* m_contextPtr;
78  const ICompositeComponent* m_parentPtr;
79  bool m_isParentOwner;
80 };
81 
82 
83 // inline protected methods
84 
86 {
87  return (m_contextPtr != NULL);
88 }
89 
90 
91 } // namespace icomp
92 
93 
102 #define I_BEGIN_COMPONENT(ComponentType)\
103  typedef ComponentType CurrentComponentType;\
104  static const icomp::IRealComponentStaticInfo& InitStaticInfo(ComponentType* componentPtr)\
105  {\
106  static icomp::TComponentStaticInfo<ComponentType> staticInfo(&BaseClass::InitStaticInfo(NULL));\
107  static bool isStaticInitialized = false;\
108  if (isStaticInitialized && (componentPtr == NULL)){\
109  return staticInfo;\
110  }\
111  isStaticInitialized = true;\
112  BaseClass::InitStaticInfo(componentPtr);
113 
120 #define I_BEGIN_BASE_COMPONENT(ComponentType)\
121  typedef ComponentType CurrentComponentType;\
122  static const icomp::IRealComponentStaticInfo& InitStaticInfo(ComponentType* componentPtr)\
123  {\
124  static icomp::CBaseComponentStaticInfo staticInfo(&BaseClass::InitStaticInfo(NULL));\
125  static bool isStaticInitialized = false;\
126  if (isStaticInitialized && (componentPtr == NULL)){\
127  return staticInfo;\
128  }\
129  isStaticInitialized = true;\
130  BaseClass::InitStaticInfo(componentPtr);
131 
139 #define I_END_COMPONENT\
140  return staticInfo;\
141  }\
142  virtual const icomp::IRealComponentStaticInfo& GetComponentStaticInfo() const\
143  {\
144  return InitStaticInfo(NULL);\
145  }
146 
153 #define I_REGISTER_INTERFACE(InterfaceType)\
154  {\
155  static icomp::TInterfaceRegistrator<InterfaceType> staticRegistrator(staticInfo);\
156  Q_UNUSED(staticRegistrator);\
157  }
158 
162 #define I_REGISTER_SUBELEMENT(ElementName)\
163  static icomp::TSubelementStaticInfo<CurrentComponentType> subelementInfo_##ElementName(#ElementName, staticInfo);
164 
171 #define I_REGISTER_SUBELEMENT_INTERFACE(ElementName, InterfaceType, extractorFunction)\
172  {\
173  static icomp::SubElementInterfaceRegistrator<InterfaceType, CurrentComponentType> staticRegistrator(\
174  subelementInfo_##ElementName,\
175  extractorFunction);\
176  Q_UNUSED(staticRegistrator);\
177  }
178 
185 #define I_REGISTER_SUBELEMENT_INTERFACE_T(ElementName, InterfaceType, extractorFunction)\
186  {\
187  static icomp::SubElementInterfaceRegistrator<InterfaceType, CurrentComponentType> staticRegistrator(\
188  subelementInfo_##ElementName,\
189  extractorFunction<InterfaceType>);\
190  Q_UNUSED(staticRegistrator);\
191  }
192 
196 #define I_USER_ATTR(attrType, member)\
197  typedef icomp::TAttributeMember< attrType > member##_Type;\
198  typedef icomp::TAttributeMember< attrType >::AttributeType member##_AttrType;\
199  icomp::TAttributeMember< attrType > member
200 
212 #define I_ATTR(attrType, member)\
213  I_USER_ATTR(iattr::TAttribute< attrType >, member)
214 
221 #define I_TEXTATTR(member)\
222  typedef icomp::CTextAttributeMember member##_Type;\
223  typedef icomp::CTextAttributeMember::AttributeType member##_AttrType;\
224  icomp::CTextAttributeMember member
225 
229 #define I_USER_MULTIATTR(attrType, member)\
230  typedef icomp::TMultiAttributeMember< attrType > member##_Type;\
231  typedef icomp::TMultiAttributeMember< attrType >::AttributeType member##_AttrType;\
232  icomp::TMultiAttributeMember< attrType > member
233 
244 #define I_MULTIATTR(attrType, member)\
245  I_USER_MULTIATTR(iattr::TMultiAttribute< attrType >, member)
246 
252 #define I_MULTITEXTATTR(member)\
253  typedef icomp::CMultiTextAttributeMember member##_Type;\
254  typedef icomp::CMultiTextAttributeMember::AttributeType member##_AttrType;\
255  icomp::CMultiTextAttributeMember member
256 
263 #define I_REF(interfaceType, member)\
264  typedef icomp::TReferenceMember<interfaceType> member##_Type;\
265  typedef icomp::TReferenceMember<interfaceType>::AttributeType member##_AttrType;\
266  icomp::TReferenceMember<interfaceType> member
267 
271 #define I_TREF(interfaceType, member)\
272  typedef icomp::TReferenceMember<interfaceType> member##_Type;\
273  typedef typename icomp::TReferenceMember<interfaceType>::AttributeType member##_AttrType;\
274  icomp::TReferenceMember<interfaceType> member
275 
279 #define I_TMULTIREF(interfaceType, member)\
280  typedef icomp::TMultiReferenceMember<interfaceType> member##_Type;\
281  typedef typename icomp::TMultiReferenceMember<interfaceType>::AttributeType member##_AttrType;\
282  icomp::TMultiReferenceMember<interfaceType> member
283 
284 
290 #define I_MULTIREF(interfaceType, member)\
291  typedef icomp::TMultiReferenceMember<interfaceType> member##_Type;\
292  typedef icomp::TMultiReferenceMember<interfaceType>::AttributeType member##_AttrType;\
293  icomp::TMultiReferenceMember<interfaceType> member
294 
300 #define I_FACT(interfaceType, member)\
301  typedef icomp::TFactoryMember<interfaceType> member##_Type;\
302  typedef icomp::TFactoryMember<interfaceType>::AttributeType member##_AttrType;\
303  icomp::TFactoryMember<interfaceType> member;
304 
305 #define I_TFACT(interfaceType, member)\
306  typedef icomp::TFactoryMember<interfaceType> member##_Type;\
307  typedef typename icomp::TFactoryMember<interfaceType>::AttributeType member##_AttrType;\
308  icomp::TFactoryMember<interfaceType> member
309 
314 #define I_MULTIFACT(interfaceType, member)\
315  typedef icomp::TMultiFactoryMember<interfaceType> member##_Type;\
316  typedef icomp::TMultiFactoryMember<interfaceType>::AttributeType member##_AttrType;\
317  icomp::TMultiFactoryMember<interfaceType> member
318 
322 #define I_ASSIGN_BASE(member, id, description, isObligatory)\
323  static icomp::TAttributeStaticInfo<member##_AttrType> member##_Info(staticInfo, id, description, &member##_Default, isObligatory? member##_AttrType::DAF_OBLIGATORY: member##_AttrType::DAF_OPTIONAL, istd::CClassInfo::GetInfo<typename member##_Type::InterfaceType>());\
324  if (componentPtr != NULL){\
325  componentPtr->member.Init(componentPtr, member##_Info);\
326  }
327 
334 #define I_ASSIGN(member, id, description, isObligatory, defaultValue)\
335  static member##_AttrType member##_Default(defaultValue);\
336  I_ASSIGN_BASE(member, id, description, isObligatory)
337 
341 #define I_ASSIGN_MULTI_BASE(member, id, description, isObligatory, defaultValue)\
342  static member##_AttrType member##_Default(int(sizeof(member##_DefaultElements) / sizeof(member##_AttrType::ValueType)), member##_DefaultElements);\
343  I_ASSIGN_BASE(member, id, description, isObligatory)
344 
350 #define I_ASSIGN_MULTI_0(member, id, description, isObligatory)\
351  static member##_AttrType member##_Default(0, NULL);\
352  I_ASSIGN_BASE(member, id, description, isObligatory)
353 
359 #define I_ASSIGN_MULTI_1(member, id, description, isObligatory, defaultValue1)\
360  static member##_AttrType::ValueType member##_DefaultElements[] = {defaultValue1};\
361  I_ASSIGN_MULTI_BASE(member, id, description, isObligatory, defaultValue)
362 
366 #define I_ASSIGN_MULTI_2(member, id, description, isObligatory, defaultValue1, defaultValue2)\
367  static member##_AttrType::ValueType member##_DefaultElements[] = {defaultValue1, defaultValue2};\
368  I_ASSIGN_MULTI_BASE(member, id, description, isObligatory, defaultValue)
369 
373 #define I_ASSIGN_MULTI_3(member, id, description, isObligatory, defaultValue1, defaultValue2, defaultValue3)\
374  static member##_AttrType::ValueType member##_DefaultElements[] = {defaultValue1, defaultValue2, defaultValue3};\
375  I_ASSIGN_MULTI_BASE(member, id, description, isObligatory, defaultValue)
376 
380 #define I_ASSIGN_MULTI_4(member, id, description, isObligatory, defaultValue1, defaultValue2, defaultValue3, defaultValue4)\
381  static member##_AttrType::ValueType member##_DefaultElements[] = {defaultValue1, defaultValue2, defaultValue3, defaultValue4};\
382  I_ASSIGN_MULTI_BASE(member, id, description, isObligatory, defaultValue)
383 
387 #define I_ASSIGN_MULTI_5(member, id, description, isObligatory, defaultValue1, defaultValue2, defaultValue3, defaultValue4, defaultValue5)\
388  static member##_AttrType::ValueType member##_DefaultElements[] = {defaultValue1, defaultValue2, defaultValue3, defaultValue4, defaultValue5};\
389  I_ASSIGN_MULTI_BASE(member, id, description, isObligatory, defaultValue)
390 
391 
395 #define I_TASSIGN_BASE(member, id, description, isObligatory)\
396  static icomp::TAttributeStaticInfo<member##_AttrType> member##_Info(staticInfo, id, description, &member##_Default, isObligatory? member##_AttrType::DAF_OBLIGATORY: member##_AttrType::DAF_OPTIONAL, istd::CClassInfo::GetInfo<typename member##_Type::InterfaceType>());\
397  if (componentPtr != NULL){\
398  componentPtr->member.Init(componentPtr, member##_Info);\
399  }
400 
404 #define I_TASSIGN(member, id, description, isObligatory, defaultValue)\
405  static member##_AttrType member##_Default(defaultValue);\
406  I_TASSIGN_BASE(member, id, description, isObligatory)
407 
411 #define I_TASSIGN_MULTI_BASE(member, id, description, isObligatory, defaultValue)\
412  static member##_AttrType member##_Default(int(sizeof(member##_DefaultElements) / sizeof(member##_AttrType::ValueType)), member##_DefaultElements);\
413  I_TASSIGN_BASE(member, id, description, isObligatory)
414 
418 #define I_TASSIGN_MULTI_0(member, id, description, isObligatory)\
419  static member##_AttrType member##_Default(0, NULL);\
420  I_TASSIGN_BASE(member, id, description, isObligatory)
421 
425 #define I_TASSIGN_MULTI_1(member, id, description, isObligatory, defaultValue1)\
426  static member##_AttrType::ValueType member##_DefaultElements[] = {defaultValue1};\
427  I_TASSIGN_MULTI_BASE(member, id, description, isObligatory, defaultValue)
428 
432 #define I_TASSIGN_MULTI_2(member, id, description, isObligatory, defaultValue1, defaultValue2)\
433  static member##_AttrType::ValueType member##_DefaultElements[] = {defaultValue1, defaultValue2};\
434  I_TASSIGN_MULTI_BASE(member, id, description, isObligatory, defaultValue)
435 
439 #define I_TASSIGN_MULTI_3(member, id, description, isObligatory, defaultValue1, defaultValue2, defaultValue3)\
440  static member##_AttrType::ValueType member##_DefaultElements[] = {defaultValue1, defaultValue2, defaultValue3};\
441  I_TASSIGN_MULTI_BASE(member, id, description, isObligatory, defaultValue)
442 
443 
447 #define I_ASSIGN_TO(member, baseAttribute, isObligatory)\
448  static icomp::CRelatedInfoRegistrator member##_Info(baseAttribute##_Info, icomp::IComponentStaticInfo::MGI_INTERFACES, istd::CClassInfo::GetInfo<member##_Type::InterfaceType>().GetName(), isObligatory? member##_AttrType::DAF_OBLIGATORY: member##_AttrType::DAF_OPTIONAL);\
449  Q_UNUSED(member##_Info);\
450  if (componentPtr != NULL){\
451  componentPtr->member.Init(componentPtr, baseAttribute##_Info);\
452  }
453 
457 #define I_TASSIGN_TO(member, baseAttribute, isObligatory)\
458  static icomp::CRelatedInfoRegistrator member##_Info(baseAttribute##_Info, icomp::IComponentStaticInfo::MGI_INTERFACES, istd::CClassInfo::GetInfo<typename member##_Type::InterfaceType>().GetName(), isObligatory? member##_AttrType::DAF_OBLIGATORY: member##_AttrType::DAF_OPTIONAL);\
459  Q_UNUSED(member##_Info);\
460  if (componentPtr != NULL){\
461  componentPtr->member.Init(componentPtr, baseAttribute##_Info);\
462  }
463 
468 template <class Dest>
470 {
471  const icomp::IComponent* componentPtr = dynamic_cast<const icomp::IComponent*>(objectPtr);
472  if (componentPtr != NULL){
473  icomp::ICompositeComponent* parentComponentPtr = const_cast<icomp::ICompositeComponent*>(componentPtr->GetParentComponent(true));
474 
475  if (parentComponentPtr != NULL){
476  Dest* retVal = (Dest*)parentComponentPtr->GetInterface(istd::CClassInfo(typeid(Dest)));
477 
478  if (retVal != NULL){
479  return retVal;
480  }
481  }
482  }
483 
484  return dynamic_cast<Dest*>(objectPtr);
485 }
486 
487 
493 template <class Dest>
494 const Dest* CompCastPtr(const istd::IPolymorphic* objectPtr)
495 {
496  const icomp::IComponent* componentPtr = dynamic_cast<const icomp::IComponent*>(objectPtr);
497  if (componentPtr != NULL){
498  icomp::ICompositeComponent* parentComponentPtr = const_cast<icomp::ICompositeComponent*>(componentPtr->GetParentComponent(true));
499 
500  if (parentComponentPtr != NULL){
501  const Dest* retVal = (const Dest*)parentComponentPtr->GetInterface(istd::CClassInfo(typeid(Dest)));
502 
503  if (retVal != NULL){
504  return retVal;
505  }
506  }
507  }
508 
509  return dynamic_cast<const Dest*>(objectPtr);
510 }
511 
512 
513 #endif // !icomp_CComponentBase_included
514 
virtual const ICompositeComponent * GetParentComponent(bool ownerOnly=false) const
Get parent of this component.
Dest * CompCastPtr(istd::IPolymorphic *objectPtr)
Cast to specified interface trying to use component interface query.
virtual const icomp::IRealComponentStaticInfo & GetComponentStaticInfo() const =0
Get access to static info of this component.
Base class for component implementation.
Main component interface.
Definition: IComponent.h:31
Provide session context of component.
virtual const ICompositeComponent * GetParentComponent(bool ownerOnly=false) const =0
Get parent of this component.
virtual void * GetInterface(const istd::CClassInfo &interfaceType, const QByteArray &subId="")
Get access to specified component interface.
static const icomp::IRealComponentStaticInfo & InitStaticInfo(IComponent *componentPtr)
Base interface for all used interfaces and implementations.
Definition: IPolymorphic.h:17
virtual void * GetInterface(const istd::CClassInfo &interfaceType, const QByteArray &subId="")=0
Get access to specified component interface.
Interface adding to component static info functionality existing only for real components.
virtual void OnComponentCreated()
#define NULL
Definition: istd.h:64
static QByteArray GetComponentId(const icomp::IComponentContext *componentContextPtr, const QByteArray &contextId=QByteArray())
bool IsComponentActive() const
Check if component is active.
Represents platform independent type info and provide set of static class manipulation functions...
Definition: CClassInfo.h:22
virtual void OnComponentDestroyed()
virtual const IComponentContext * GetComponentContext() const
Get access to component context describing all application-specified component information loaded fro...
virtual void SetComponentContext(const icomp::IComponentContext *contextPtr, const ICompositeComponent *parentPtr, bool isParentOwner)
Set component context of this component.
Composite component interface.
CComponentBase()
Create component and assign it to specific context.

© 2007-2017 Witold Gantzke and Kirill Lepskiy