ACF $AcfVersion:0$
CComponentBase.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-2.1-or-later OR GPL-2.0-or-later OR GPL-3.0-or-later OR LicenseRef-ACF-Commercial
2#pragma once
3
4
5// ACF includes
6#include <istd/CClassInfo.h>
7#include <iattr/TAttribute.h>
9#include <icomp/IComponent.h>
24
25
26namespace icomp
27{
28
29
37class CComponentBase: virtual public IComponent
38{
39public:
44
45 // reimplemented (icomp::IComponent)
46 virtual const icomp::IComponent* GetParentComponent(bool ownerOnly = false) const override;
47 virtual void* GetInterface(const istd::CClassInfo& interfaceType, const QByteArray& subId = "") override;
49 virtual void SetComponentContext(
50 const IComponentContextSharedPtr& contextPtr,
51 const icomp::IComponent* parentPtr,
52 bool isParentOwner) override;
53
54protected:
59 bool IsComponentActive() const;
60
61 virtual void OnComponentCreated();
62 virtual void OnComponentDestroyed();
63
64 // abstract methods
69
70 // static protected methods
72 static QByteArray GetComponentId(const icomp::IComponentContext* componentContextPtr, const QByteArray& contextId = QByteArray());
73
74private:
75 Q_DISABLE_COPY(CComponentBase)
76
77 IComponentContextSharedPtr m_contextPtr;
78 const icomp::IComponent* m_parentPtr;
79
80 bool m_isParentOwner;
81};
82
83
84// inline protected methods
85
87{
88 return (m_contextPtr != nullptr);
89}
90
91
92} // namespace icomp
93
94
103#define I_BEGIN_COMPONENT(ComponentType)\
104 typedef ComponentType CurrentComponentType;\
105 static const icomp::IRealComponentStaticInfo& InitStaticInfo(ComponentType* componentPtr)\
106 {\
107 static icomp::TComponentStaticInfo<ComponentType> staticInfo(&BaseClass::InitStaticInfo(nullptr));\
108 static bool isStaticInitialized = false;\
109 if (isStaticInitialized && (componentPtr == nullptr)){\
110 return staticInfo;\
111 }\
112 isStaticInitialized = true;\
113 BaseClass::InitStaticInfo(componentPtr);
114
121#define I_BEGIN_BASE_COMPONENT(ComponentType)\
122 typedef ComponentType CurrentComponentType;\
123 static const icomp::IRealComponentStaticInfo& InitStaticInfo(ComponentType* componentPtr)\
124 {\
125 static icomp::CBaseComponentStaticInfo staticInfo(&BaseClass::InitStaticInfo(nullptr));\
126 static bool isStaticInitialized = false;\
127 if (isStaticInitialized && (componentPtr == nullptr)){\
128 return staticInfo;\
129 }\
130 isStaticInitialized = true;\
131 BaseClass::InitStaticInfo(componentPtr);
132
140#define I_END_COMPONENT\
141 return staticInfo;\
142 }\
143 virtual const icomp::IRealComponentStaticInfo& GetComponentStaticInfo() const override\
144 {\
145 return InitStaticInfo(nullptr);\
146 }
147
154#define I_REGISTER_INTERFACE(InterfaceType)\
155 {\
156 static icomp::TInterfaceRegistrator<InterfaceType> staticRegistrator(staticInfo);\
157 Q_UNUSED(staticRegistrator);\
158 }
159
163#define I_REGISTER_SUBELEMENT(ElementName)\
164 static icomp::TSubelementStaticInfo<CurrentComponentType> subelementInfo_##ElementName(#ElementName, staticInfo);
165
172#define I_REGISTER_SUBELEMENT_INTERFACE(ElementName, InterfaceType, extractorFunction)\
173 {\
174 static icomp::SubElementInterfaceRegistrator<InterfaceType, CurrentComponentType> staticRegistrator(\
175 subelementInfo_##ElementName,\
176 extractorFunction);\
177 Q_UNUSED(staticRegistrator);\
178 }
179
186#define I_REGISTER_SUBELEMENT_INTERFACE_T(ElementName, InterfaceType, extractorFunction)\
187 {\
188 static icomp::SubElementInterfaceRegistrator<InterfaceType, CurrentComponentType> staticRegistrator(\
189 subelementInfo_##ElementName,\
190 extractorFunction<InterfaceType>);\
191 Q_UNUSED(staticRegistrator);\
192 }
193
198#define I_USER_ATTR(attrType, member)\
199 typedef icomp::TAttributeMember< attrType > member##_Type;\
200 typedef icomp::TAttributeMember< attrType >::AttributeType member##_AttrType;\
201 icomp::TAttributeMember< attrType > member
202
214#define I_ATTR(attrType, member)\
215 I_USER_ATTR(iattr::TAttribute< attrType >, member)
216
223#define I_TEXTATTR(member)\
224 typedef icomp::CTextAttributeMember member##_Type;\
225 typedef icomp::CTextAttributeMember::AttributeType member##_AttrType;\
226 icomp::CTextAttributeMember member
227
232#define I_USER_MULTIATTR(attrType, member)\
233 typedef icomp::TMultiAttributeMember< attrType > member##_Type;\
234 typedef icomp::TMultiAttributeMember< attrType >::AttributeType member##_AttrType;\
235 icomp::TMultiAttributeMember< attrType > member
236
247#define I_MULTIATTR(attrType, member)\
248 I_USER_MULTIATTR(iattr::TMultiAttribute< attrType >, member)
249
255#define I_MULTITEXTATTR(member)\
256 typedef icomp::CMultiTextAttributeMember member##_Type;\
257 typedef icomp::CMultiTextAttributeMember::AttributeType member##_AttrType;\
258 icomp::CMultiTextAttributeMember member
259
266#define I_REF(interfaceType, member)\
267 typedef icomp::TReferenceMember<interfaceType> member##_Type;\
268 typedef icomp::TReferenceMember<interfaceType>::AttributeType member##_AttrType;\
269 icomp::TReferenceMember<interfaceType> member
270
276#define I_TREF(interfaceType, member)\
277 typedef icomp::TReferenceMember<interfaceType> member##_Type;\
278 typedef typename icomp::TReferenceMember<interfaceType>::AttributeType member##_AttrType;\
279 icomp::TReferenceMember<interfaceType> member
280
286#define I_TMULTIREF(interfaceType, member)\
287 typedef icomp::TMultiReferenceMember<interfaceType> member##_Type;\
288 typedef typename icomp::TMultiReferenceMember<interfaceType>::AttributeType member##_AttrType;\
289 icomp::TMultiReferenceMember<interfaceType> member
290
291
297#define I_MULTIREF(interfaceType, member)\
298 typedef icomp::TMultiReferenceMember<interfaceType> member##_Type;\
299 typedef icomp::TMultiReferenceMember<interfaceType>::AttributeType member##_AttrType;\
300 icomp::TMultiReferenceMember<interfaceType> member
301
307#define I_FACT(interfaceType, member)\
308 typedef icomp::TFactoryMember<interfaceType> member##_Type;\
309 typedef icomp::TFactoryMember<interfaceType>::AttributeType member##_AttrType;\
310 icomp::TFactoryMember<interfaceType> member;
311
317#define I_TFACT(interfaceType, member)\
318 typedef icomp::TFactoryMember<interfaceType> member##_Type;\
319 typedef typename icomp::TFactoryMember<interfaceType>::AttributeType member##_AttrType;\
320 icomp::TFactoryMember<interfaceType> member
321
327#define I_MULTIFACT(interfaceType, member)\
328 typedef icomp::TMultiFactoryMember<interfaceType> member##_Type;\
329 typedef icomp::TMultiFactoryMember<interfaceType>::AttributeType member##_AttrType;\
330 icomp::TMultiFactoryMember<interfaceType> member
331
337#define I_ASSIGN_BASE(member, id, description, isObligatory)\
338 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>());\
339 if (componentPtr != nullptr){\
340 componentPtr->member.Init(componentPtr, member##_Info);\
341 }
342
349#define I_ASSIGN(member, id, description, isObligatory, defaultValue)\
350 static member##_AttrType member##_Default(defaultValue);\
351 I_ASSIGN_BASE(member, id, description, isObligatory)
352
356#define I_ASSIGN_MULTI_BASE(member, id, description, isObligatory, defaultValue)\
357 static member##_AttrType member##_Default(int(sizeof(member##_DefaultElements) / sizeof(member##_AttrType::ValueType)), member##_DefaultElements);\
358 I_ASSIGN_BASE(member, id, description, isObligatory)
359
365#define I_ASSIGN_MULTI_0(member, id, description, isObligatory)\
366 static member##_AttrType member##_Default(0, nullptr);\
367 I_ASSIGN_BASE(member, id, description, isObligatory)
368
374#define I_ASSIGN_MULTI_1(member, id, description, isObligatory, defaultValue1)\
375 static member##_AttrType::ValueType member##_DefaultElements[] = {defaultValue1};\
376 I_ASSIGN_MULTI_BASE(member, id, description, isObligatory, defaultValue)
377
383#define I_ASSIGN_MULTI_2(member, id, description, isObligatory, defaultValue1, defaultValue2)\
384 static member##_AttrType::ValueType member##_DefaultElements[] = {defaultValue1, defaultValue2};\
385 I_ASSIGN_MULTI_BASE(member, id, description, isObligatory, defaultValue)
386
392#define I_ASSIGN_MULTI_3(member, id, description, isObligatory, defaultValue1, defaultValue2, defaultValue3)\
393 static member##_AttrType::ValueType member##_DefaultElements[] = {defaultValue1, defaultValue2, defaultValue3};\
394 I_ASSIGN_MULTI_BASE(member, id, description, isObligatory, defaultValue)
395
401#define I_ASSIGN_MULTI_4(member, id, description, isObligatory, defaultValue1, defaultValue2, defaultValue3, defaultValue4)\
402 static member##_AttrType::ValueType member##_DefaultElements[] = {defaultValue1, defaultValue2, defaultValue3, defaultValue4};\
403 I_ASSIGN_MULTI_BASE(member, id, description, isObligatory, defaultValue)
404
410#define I_ASSIGN_MULTI_5(member, id, description, isObligatory, defaultValue1, defaultValue2, defaultValue3, defaultValue4, defaultValue5)\
411 static member##_AttrType::ValueType member##_DefaultElements[] = {defaultValue1, defaultValue2, defaultValue3, defaultValue4, defaultValue5};\
412 I_ASSIGN_MULTI_BASE(member, id, description, isObligatory, defaultValue)
413
419#define I_TASSIGN_BASE(member, id, description, isObligatory)\
420 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>());\
421 if (componentPtr != nullptr){\
422 componentPtr->member.Init(componentPtr, member##_Info);\
423 }
424
430#define I_TASSIGN(member, id, description, isObligatory, defaultValue)\
431 static member##_AttrType member##_Default(defaultValue);\
432 I_TASSIGN_BASE(member, id, description, isObligatory)
433
439#define I_TASSIGN_MULTI_BASE(member, id, description, isObligatory, defaultValue)\
440 static member##_AttrType member##_Default(int(sizeof(member##_DefaultElements) / sizeof(member##_AttrType::ValueType)), member##_DefaultElements);\
441 I_TASSIGN_BASE(member, id, description, isObligatory)
442
448#define I_TASSIGN_MULTI_0(member, id, description, isObligatory)\
449 static member##_AttrType member##_Default(0, nullptr);\
450 I_TASSIGN_BASE(member, id, description, isObligatory)
451
457#define I_TASSIGN_MULTI_1(member, id, description, isObligatory, defaultValue1)\
458 static member##_AttrType::ValueType member##_DefaultElements[] = {defaultValue1};\
459 I_TASSIGN_MULTI_BASE(member, id, description, isObligatory, defaultValue)
460
466#define I_TASSIGN_MULTI_2(member, id, description, isObligatory, defaultValue1, defaultValue2)\
467 static member##_AttrType::ValueType member##_DefaultElements[] = {defaultValue1, defaultValue2};\
468 I_TASSIGN_MULTI_BASE(member, id, description, isObligatory, defaultValue)
469
475#define I_TASSIGN_MULTI_3(member, id, description, isObligatory, defaultValue1, defaultValue2, defaultValue3)\
476 static member##_AttrType::ValueType member##_DefaultElements[] = {defaultValue1, defaultValue2, defaultValue3};\
477 I_TASSIGN_MULTI_BASE(member, id, description, isObligatory, defaultValue)
478
479
485#define I_ASSIGN_TO(member, baseAttribute, isObligatory)\
486 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);\
487 Q_UNUSED(member##_Info);\
488 if (componentPtr != nullptr){\
489 componentPtr->member.Init(componentPtr, baseAttribute##_Info);\
490 }
491
497#define I_TASSIGN_TO(member, baseAttribute, isObligatory)\
498 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);\
499 Q_UNUSED(member##_Info);\
500 if (componentPtr != nullptr){\
501 componentPtr->member.Init(componentPtr, baseAttribute##_Info);\
502 }
503
510template <class Dest>
512{
513 const icomp::IComponent* componentPtr = dynamic_cast<const icomp::IComponent*>(objectPtr);
514 if (componentPtr != nullptr){
515 icomp::ICompositeComponent* parentComponentPtr = const_cast<icomp::ICompositeComponent*>(dynamic_cast<const icomp::ICompositeComponent*>(componentPtr->GetParentComponent(true)));
516
517 if (parentComponentPtr != nullptr){
518 Dest* retVal = (Dest*)parentComponentPtr->GetInterface(istd::CClassInfo(typeid(Dest)));
519
520 if (retVal != nullptr){
521 return retVal;
522 }
523 }
524 }
525
526 return dynamic_cast<Dest*>(objectPtr);
527}
528
529
536template <class Dest>
537const Dest* CompCastPtr(const istd::IPolymorphic* objectPtr)
538{
539 const icomp::IComponent* componentPtr = dynamic_cast<const icomp::IComponent*>(objectPtr);
540 if (componentPtr != nullptr){
541 icomp::ICompositeComponent* parentComponentPtr = const_cast<icomp::ICompositeComponent*>(dynamic_cast<const icomp::ICompositeComponent*>(componentPtr->GetParentComponent(true)));
542 if (parentComponentPtr != nullptr){
543 const Dest* retVal = (const Dest*)parentComponentPtr->GetInterface(istd::CClassInfo(typeid(Dest)));
544
545 if (retVal != nullptr){
546 return retVal;
547 }
548 }
549 }
550
551 return dynamic_cast<const Dest*>(objectPtr);
552}
553
554
560template <class Dest>
561Dest* QueryInterface(istd::IPolymorphic* objectPtr, const QByteArray& componentId = QByteArray())
562{
563 const icomp::IComponent* componentPtr = dynamic_cast<const icomp::IComponent*>(objectPtr);
564 if (componentPtr != nullptr) {
565 icomp::ICompositeComponent* parentComponentPtr = const_cast<icomp::ICompositeComponent*>(dynamic_cast<const icomp::ICompositeComponent*>(componentPtr->GetParentComponent(true)));
566 if (parentComponentPtr != nullptr) {
567 Dest* retVal = (Dest*)parentComponentPtr->GetInterface(istd::CClassInfo(typeid(Dest)), componentId);
568 if (retVal != nullptr) {
569 return retVal;
570 }
571
572 return QueryInterface<Dest>(parentComponentPtr, componentId);
573 }
574 }
575
576 return nullptr;
577}
578
579
Base class for component implementation.
static QByteArray GetComponentId(const icomp::IComponentContext *componentContextPtr, const QByteArray &contextId=QByteArray())
virtual void OnComponentDestroyed()
static const icomp::IRealComponentStaticInfo & InitStaticInfo(IComponent *componentPtr)
bool IsComponentActive() const
Check if component is active.
virtual IComponentContextSharedPtr GetComponentContext() const override
Get access to component context describing all application-specified component information loaded fro...
virtual const icomp::IRealComponentStaticInfo & GetComponentStaticInfo() const =0
Get access to static info of this component.
virtual void * GetInterface(const istd::CClassInfo &interfaceType, const QByteArray &subId="") override
Get access to specified component interface.
virtual void OnComponentCreated()
CComponentBase()
Create component and assign it to specific context.
virtual void SetComponentContext(const IComponentContextSharedPtr &contextPtr, const icomp::IComponent *parentPtr, bool isParentOwner) override
Set component context of this component.
virtual const icomp::IComponent * GetParentComponent(bool ownerOnly=false) const override
Get parent of this component.
Provide session context of component.
Main component interface.
Definition IComponent.h:32
virtual const icomp::IComponent * GetParentComponent(bool ownerOnly=false) const =0
Get parent of this component.
virtual void * GetInterface(const istd::CClassInfo &interfaceType, const QByteArray &subId="")=0
Get access to specified component interface.
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:23
Base interface for all used interfaces and implementations.
Dest * QueryInterface(istd::IPolymorphic *objectPtr, const QByteArray &componentId=QByteArray())
Queries an object for a specified interface.
Dest * CompCastPtr(istd::IPolymorphic *objectPtr)
Cast to specified interface trying to use component interface query.
Package with interfaces and class used for components concept.
std::shared_ptr< icomp::IComponentContext > IComponentContextSharedPtr