ACF $AcfVersion:0$
TMultiFactoryMember.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/TDelPtr.h>
7
11
12
13namespace icomp
14{
15
16
21template <class Interface>
22class TMultiFactoryMember: public TMultiAttributeMember<CMultiFactoryAttribute>, public CInterfaceManipBase
23{
24public:
27 typedef Interface InterfaceType;
28
30
31 void Init(const IComponent* ownerPtr, const IRealAttributeStaticInfo& staticInfo);
32
37 bool IsValid() const;
38
43
50
61 static Interface* ExtractInterface(IComponent* componentPtr, const QByteArray& subId = "");
62
63protected:
65
66private:
67 const IComponent* m_definitionComponentPtr;
68};
69
70
71// public methods
72
73template <class Interface>
75: m_definitionComponentPtr(NULL)
76{
77}
78
79
80template <class Interface>
82{
83 BaseClass::InitInternal(ownerPtr, staticInfo, &m_definitionComponentPtr);
84}
85
86
87template <class Interface>
89{
90 return (m_definitionComponentPtr != NULL) && BaseClass::IsValid();
91}
92
93
94
95template <class Interface>
97{
98 if ((m_definitionComponentPtr != NULL) && BaseClass::IsValid()){
99 const ICompositeComponent* parentPtr = dynamic_cast<const ICompositeComponent*>(m_definitionComponentPtr->GetParentComponent());
100 if (parentPtr != NULL){
101 const QByteArray& componentId = BaseClass::operator[](index);
102
103 QByteArray baseId;
104 QByteArray subId;
105 BaseClass2::SplitId(componentId, baseId, subId);
106 Q_ASSERT(subId.isEmpty()); // explicit subelement ID are not implemented correctly
107
108 return parentPtr->CreateSubcomponent(baseId);
109 }
110 else{
111 qCritical("Component %s is defined, but definition component has no parent", BaseClass::operator[](index).constData());
112 }
113 }
114
115 return nullptr;
116}
117
118
119template <class Interface>
121{
122 IComponentUniquePtr newComponentPtr = CreateComponent(index);
123 if (newComponentPtr != nullptr) {
124 Interface* retVal = BaseClass2::ExtractInterface<Interface>(newComponentPtr.get());
125 if (retVal != NULL) {
126 return istd::TUniqueInterfacePtr<Interface>(newComponentPtr.release(), retVal);
127 }
128 }
129
131}
132
133
134// static methods
135
136template <class Interface>
137Interface* TMultiFactoryMember<Interface>::ExtractInterface(IComponent* componentPtr, const QByteArray& subId)
138{
139 return BaseClass2::ExtractInterface<Interface>(componentPtr, subId);
140}
141
142
143// protected methods
144
145template <class Interface>
147: BaseClass(ptr),
148 m_definitionComponentPtr(ptr.m_definitionComponentPtr)
149{
150}
151
152
153} // namespace icomp
154
155
Main component interface.
Definition IComponent.h:32
Composite component interface.
virtual IComponentUniquePtr CreateSubcomponent(const QByteArray &componentId) const =0
Create instance of subcomponent using its ID.
Interface adding to attribute static info functionality existing only for real attributes.
Pointer to component attribute.
Factory of components used as component member.
icomp::IComponentUniquePtr CreateComponent(int index) const
Create component for specified index without extracting any interface.
bool IsValid() const
Check if this factory can be resolved.
istd::TUniqueInterfacePtr< Interface > CreateInstance(int index) const
Create instance of interface for specified index.
TMultiAttributeMember< CMultiFactoryAttribute > BaseClass
void Init(const IComponent *ownerPtr, const IRealAttributeStaticInfo &staticInfo)
static Interface * ExtractInterface(IComponent *componentPtr, const QByteArray &subId="")
Extract interface from some component.
Unique ownership smart pointer for interface types.
#define NULL
Definition istd.h:74
Package with interfaces and class used for components concept.
std::unique_ptr< IComponent > IComponentUniquePtr
Definition IComponent.h:72