ICF 3.1.1.10
Technical documentation of ICF Libraries
CComponentBase.h
Go to the documentation of this file.
1/********************************************************************************
2** This file is part of the ICF Framework. Copyright (C) Witold Gantzke & Kirill Lepskiy
3** ICF Framework may be used under the terms of the LGPL License v. 2.1 by the Free Software Foundation.
4********************************************************************************/
5
6#pragma once
7
8
9// ICF includes
10#include <istd/CClassInfo.h>
11#include <iattr/TAttribute.h>
13#include <icomp/IComponent.h>
28
29
30namespace icomp
31{
32
33
39class CComponentBase: virtual public IComponent
40{
41public:
48
49 // reimplemented (icomp::IComponent)
50 virtual const ICompositeComponent* GetParentComponent(bool ownerOnly = false) const;
51 virtual void* GetInterface(const istd::CClassInfo& interfaceType, const QByteArray& subId = "");
52 virtual const IComponentContext* GetComponentContext() const;
53 virtual void SetComponentContext(
54 const IComponentContext* contextPtr,
55 const ICompositeComponent* parentPtr,
56 bool isParentOwner);
57
58protected:
63 bool IsComponentActive() const;
64
65 virtual void OnComponentCreated();
66 virtual void OnComponentDestroyed();
67
68 // abstract methods
73
74 // static protected methods
76 static QByteArray GetComponentId(const IComponentContext* componentContextPtr, const QByteArray& contextId = QByteArray());
77
78private:
79 const IComponentContext* m_contextPtr;
80 const ICompositeComponent* m_parentPtr;
81 bool m_isParentOwner;
82};
83
84
85// inline protected methods
86
88{
89 return (m_contextPtr != nullptr);
90}
91
92
93} // namespace icomp
94
95
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(nullptr));\
107 static bool isStaticInitialized = false;\
108 if (isStaticInitialized && (componentPtr == nullptr)){\
109 return staticInfo;\
110 }\
111 isStaticInitialized = true;\
112 BaseClass::InitStaticInfo(componentPtr);
113
119#define I_BEGIN_BASE_COMPONENT(ComponentType)\
120 typedef ComponentType CurrentComponentType;\
121 static const icomp::IRealComponentStaticInfo& InitStaticInfo(ComponentType* componentPtr)\
122 {\
123 static icomp::CBaseComponentStaticInfo staticInfo(&BaseClass::InitStaticInfo(nullptr));\
124 static bool isStaticInitialized = false;\
125 if (isStaticInitialized && (componentPtr == nullptr)){\
126 return staticInfo;\
127 }\
128 isStaticInitialized = true;\
129 BaseClass::InitStaticInfo(componentPtr);
130
136#define I_END_COMPONENT\
137 return staticInfo;\
138 }\
139 virtual const icomp::IRealComponentStaticInfo& GetComponentStaticInfo() const override\
140 {\
141 return InitStaticInfo(nullptr);\
142 }
143
148#define I_REGISTER_INTERFACE(InterfaceType)\
149 {\
150 static icomp::TInterfaceRegistrator<InterfaceType> staticRegistrator(staticInfo);\
151 Q_UNUSED(staticRegistrator);\
152 }
153
158#define I_REGISTER_SUBELEMENT(ElementName)\
159 static icomp::TSubelementStaticInfo<CurrentComponentType> subelementInfo_##ElementName(#ElementName, staticInfo);
160
168#define I_REGISTER_SUBELEMENT_INTERFACE(ElementName, InterfaceType, extractorFunction)\
169 {\
170 static icomp::SubElementInterfaceRegistrator<InterfaceType, CurrentComponentType> staticRegistrator(\
171 subelementInfo_##ElementName,\
172 extractorFunction);\
173 Q_UNUSED(staticRegistrator);\
174 }
175
183#define I_REGISTER_SUBELEMENT_INTERFACE_T(ElementName, InterfaceType, extractorFunction)\
184 {\
185 static icomp::SubElementInterfaceRegistrator<InterfaceType, CurrentComponentType> staticRegistrator(\
186 subelementInfo_##ElementName,\
187 extractorFunction<InterfaceType>);\
188 Q_UNUSED(staticRegistrator);\
189 }
190
194#define I_USER_ATTR(attrType, member)\
195 typedef icomp::TAttributeMember< attrType > member##_Type;\
196 typedef icomp::TAttributeMember< attrType >::AttributeType member##_AttrType;\
197 icomp::TAttributeMember< attrType > member
198
209#define I_ATTR(attrType, member)\
210 I_USER_ATTR(iattr::TAttribute< attrType >, member)
211
217#define I_TEXTATTR(member)\
218 typedef icomp::CTextAttributeMember member##_Type;\
219 typedef icomp::CTextAttributeMember::AttributeType member##_AttrType;\
220 icomp::CTextAttributeMember member
221
225#define I_USER_MULTIATTR(attrType, member)\
226 typedef icomp::TMultiAttributeMember< attrType > member##_Type;\
227 typedef icomp::TMultiAttributeMember< attrType >::AttributeType member##_AttrType;\
228 icomp::TMultiAttributeMember< attrType > member
229
240#define I_MULTIATTR(attrType, member)\
241 I_USER_MULTIATTR(iattr::TMultiAttribute< attrType >, member)
242
248#define I_MULTITEXTATTR(member)\
249 typedef icomp::CMultiTextAttributeMember member##_Type;\
250 typedef icomp::CMultiTextAttributeMember::AttributeType member##_AttrType;\
251 icomp::CMultiTextAttributeMember member
252
258#define I_REF(interfaceType, member)\
259 typedef icomp::TReferenceMember<interfaceType> member##_Type;\
260 typedef icomp::TReferenceMember<interfaceType>::AttributeType member##_AttrType;\
261 icomp::TReferenceMember<interfaceType> member
262
266#define I_TREF(interfaceType, member)\
267 typedef icomp::TReferenceMember<interfaceType> member##_Type;\
268 typedef typename icomp::TReferenceMember<interfaceType>::AttributeType member##_AttrType;\
269 icomp::TReferenceMember<interfaceType> member
270
274#define I_TMULTIREF(interfaceType, member)\
275 typedef icomp::TMultiReferenceMember<interfaceType> member##_Type;\
276 typedef typename icomp::TMultiReferenceMember<interfaceType>::AttributeType member##_AttrType;\
277 icomp::TMultiReferenceMember<interfaceType> member
278
279
285#define I_MULTIREF(interfaceType, member)\
286 typedef icomp::TMultiReferenceMember<interfaceType> member##_Type;\
287 typedef icomp::TMultiReferenceMember<interfaceType>::AttributeType member##_AttrType;\
288 icomp::TMultiReferenceMember<interfaceType> member
289
295#define I_FACT(interfaceType, member)\
296 typedef icomp::TFactoryMember<interfaceType> member##_Type;\
297 typedef icomp::TFactoryMember<interfaceType>::AttributeType member##_AttrType;\
298 icomp::TFactoryMember<interfaceType> member;
299
300#define I_TFACT(interfaceType, member)\
301 typedef icomp::TFactoryMember<interfaceType> member##_Type;\
302 typedef typename icomp::TFactoryMember<interfaceType>::AttributeType member##_AttrType;\
303 icomp::TFactoryMember<interfaceType> member
309#define I_MULTIFACT(interfaceType, member)\
310 typedef icomp::TMultiFactoryMember<interfaceType> member##_Type;\
311 typedef icomp::TMultiFactoryMember<interfaceType>::AttributeType member##_AttrType;\
312 icomp::TMultiFactoryMember<interfaceType> member
313
317#define I_ASSIGN_BASE(member, id, description, isObligatory)\
318 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>());\
319 if (componentPtr != nullptr){\
320 componentPtr->member.Init(componentPtr, member##_Info);\
321 }
322
327#define I_ASSIGN(member, id, description, isObligatory, defaultValue)\
328 static member##_AttrType member##_Default(defaultValue);\
329 I_ASSIGN_BASE(member, id, description, isObligatory)
330
334#define I_ASSIGN_MULTI_BASE(member, id, description, isObligatory, defaultValue)\
335 static member##_AttrType member##_Default(int(sizeof(member##_DefaultElements) / sizeof(member##_AttrType::ValueType)), member##_DefaultElements);\
336 I_ASSIGN_BASE(member, id, description, isObligatory)
337
342#define I_ASSIGN_MULTI_0(member, id, description, isObligatory)\
343 static member##_AttrType member##_Default(0, nullptr);\
344 I_ASSIGN_BASE(member, id, description, isObligatory)
345
350#define I_ASSIGN_MULTI_1(member, id, description, isObligatory, defaultValue1)\
351 static member##_AttrType::ValueType member##_DefaultElements[] = {defaultValue1};\
352 I_ASSIGN_MULTI_BASE(member, id, description, isObligatory, defaultValue)
353
357#define I_ASSIGN_MULTI_2(member, id, description, isObligatory, defaultValue1, defaultValue2)\
358 static member##_AttrType::ValueType member##_DefaultElements[] = {defaultValue1, defaultValue2};\
359 I_ASSIGN_MULTI_BASE(member, id, description, isObligatory, defaultValue)
360
364#define I_ASSIGN_MULTI_3(member, id, description, isObligatory, defaultValue1, defaultValue2, defaultValue3)\
365 static member##_AttrType::ValueType member##_DefaultElements[] = {defaultValue1, defaultValue2, defaultValue3};\
366 I_ASSIGN_MULTI_BASE(member, id, description, isObligatory, defaultValue)
367
371#define I_ASSIGN_MULTI_4(member, id, description, isObligatory, defaultValue1, defaultValue2, defaultValue3, defaultValue4)\
372 static member##_AttrType::ValueType member##_DefaultElements[] = {defaultValue1, defaultValue2, defaultValue3, defaultValue4};\
373 I_ASSIGN_MULTI_BASE(member, id, description, isObligatory, defaultValue)
374
378#define I_ASSIGN_MULTI_5(member, id, description, isObligatory, defaultValue1, defaultValue2, defaultValue3, defaultValue4, defaultValue5)\
379 static member##_AttrType::ValueType member##_DefaultElements[] = {defaultValue1, defaultValue2, defaultValue3, defaultValue4, defaultValue5};\
380 I_ASSIGN_MULTI_BASE(member, id, description, isObligatory, defaultValue)
381
382
386#define I_TASSIGN_BASE(member, id, description, isObligatory)\
387 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>());\
388 if (componentPtr != nullptr){\
389 componentPtr->member.Init(componentPtr, member##_Info);\
390 }
391
395#define I_TASSIGN(member, id, description, isObligatory, defaultValue)\
396 static member##_AttrType member##_Default(defaultValue);\
397 I_TASSIGN_BASE(member, id, description, isObligatory)
398
402#define I_TASSIGN_MULTI_BASE(member, id, description, isObligatory, defaultValue)\
403 static member##_AttrType member##_Default(int(sizeof(member##_DefaultElements) / sizeof(member##_AttrType::ValueType)), member##_DefaultElements);\
404 I_TASSIGN_BASE(member, id, description, isObligatory)
405
409#define I_TASSIGN_MULTI_0(member, id, description, isObligatory)\
410 static member##_AttrType member##_Default(0, nullptr);\
411 I_TASSIGN_BASE(member, id, description, isObligatory)
412
416#define I_TASSIGN_MULTI_1(member, id, description, isObligatory, defaultValue1)\
417 static member##_AttrType::ValueType member##_DefaultElements[] = {defaultValue1};\
418 I_TASSIGN_MULTI_BASE(member, id, description, isObligatory, defaultValue)
419
423#define I_TASSIGN_MULTI_2(member, id, description, isObligatory, defaultValue1, defaultValue2)\
424 static member##_AttrType::ValueType member##_DefaultElements[] = {defaultValue1, defaultValue2};\
425 I_TASSIGN_MULTI_BASE(member, id, description, isObligatory, defaultValue)
426
430#define I_TASSIGN_MULTI_3(member, id, description, isObligatory, defaultValue1, defaultValue2, defaultValue3)\
431 static member##_AttrType::ValueType member##_DefaultElements[] = {defaultValue1, defaultValue2, defaultValue3};\
432 I_TASSIGN_MULTI_BASE(member, id, description, isObligatory, defaultValue)
433
434
438#define I_ASSIGN_TO(member, baseAttribute, isObligatory)\
439 static icomp::CRelatedInfoRegistrator member##_Info(baseAttribute##_Info, icomp::IElementStaticInfo::MetaGroupId::Interfaces, istd::CClassInfo::GetInfo<member##_Type::InterfaceType>().GetName(), isObligatory? member##_AttrType::DAF_OBLIGATORY: member##_AttrType::DAF_OPTIONAL);\
440 Q_UNUSED(member##_Info);\
441 if (componentPtr != nullptr){\
442 componentPtr->member.Init(componentPtr, baseAttribute##_Info);\
443 }
444
448#define I_TASSIGN_TO(member, baseAttribute, isObligatory)\
449 static icomp::CRelatedInfoRegistrator member##_Info(baseAttribute##_Info, icomp::IElementStaticInfo::MetaGroupId::Interfaces, istd::CClassInfo::GetInfo<typename member##_Type::InterfaceType>().GetName(), isObligatory? member##_AttrType::DAF_OBLIGATORY: member##_AttrType::DAF_OPTIONAL);\
450 Q_UNUSED(member##_Info);\
451 if (componentPtr != nullptr){\
452 componentPtr->member.Init(componentPtr, baseAttribute##_Info);\
453 }
454
455
460template <class Dest>
461inline Dest* CompCastPtr(istd::IPolymorphic* objectPtr)
462{
463 if (const icomp::IComponent* componentPtr = dynamic_cast<const icomp::IComponent*>(objectPtr)) {
464 if (icomp::ICompositeComponent* parentComponentPtr = const_cast<icomp::ICompositeComponent*>(componentPtr->GetParentComponent(true))) {
465 if (Dest* retVal = (Dest*)parentComponentPtr->GetInterface(istd::CClassInfo(typeid(Dest)))) {
466 return retVal;
467 }
468 }
469 }
470
471 return dynamic_cast<Dest*>(objectPtr);
472}
473
474
480template <class Dest>
481inline const Dest* CompCastPtr(const istd::IPolymorphic* objectPtr)
482{
483 if (const icomp::IComponent* componentPtr = dynamic_cast<const icomp::IComponent*>(objectPtr)) {
484 if (icomp::ICompositeComponent* parentComponentPtr = const_cast<icomp::ICompositeComponent*>(componentPtr->GetParentComponent(true))) {
485 if (const Dest* retVal = (const Dest*)parentComponentPtr->GetInterface(istd::CClassInfo(typeid(Dest)))) {
486 return retVal;
487 }
488 }
489 }
490
491 return dynamic_cast<const Dest*>(objectPtr);
492}
493
494
Dest * CompCastPtr(istd::IPolymorphic *objectPtr)
Cast to specified interface trying to use component interface query.
Base class for component implementation.
virtual void OnComponentDestroyed()
virtual const ICompositeComponent * GetParentComponent(bool ownerOnly=false) const
Get parent of this component.
static QByteArray GetComponentId(const IComponentContext *componentContextPtr, const QByteArray &contextId=QByteArray())
bool IsComponentActive() const
Check if component is active.
CComponentBase(const CComponentBase &)=delete
virtual void OnComponentCreated()
CComponentBase()
Create component and assign it to specific context.
CComponentBase & operator=(const CComponentBase &)=delete
virtual void SetComponentContext(const IComponentContext *contextPtr, const ICompositeComponent *parentPtr, bool isParentOwner)
Set component context of this component.
static const IRealComponentStaticInfo & InitStaticInfo(IComponent *componentPtr)
virtual void * GetInterface(const istd::CClassInfo &interfaceType, const QByteArray &subId="")
Get access to specified component interface.
virtual const IComponentContext * GetComponentContext() const
Get access to component context describing all application-specified component information loaded fro...
virtual const IRealComponentStaticInfo & GetComponentStaticInfo() const =0
Get access to static info of this component.
Provide session context of component.
Main component interface.
Definition IComponent.h:35
Composite component interface.
Interface adding to component static info functionality existing only for real components.
Represents platform independent type info and provide set of static class manipulation functions.
Definition CClassInfo.h:27
Package with interfaces and class used for components concept.

© Witold Gantzke and Kirill Lepskiy