ICF 3.1.1.10
Technical documentation of ICF Libraries
TMultiReferenceMember.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
13
14
15namespace icomp
16{
17
18
23template <class Interface>
24class TMultiReferenceMember: public TMultiAttributeMember<CMultiReferenceAttribute>, public CInterfaceManipBase
25{
26public:
29 typedef Interface InterfaceType;
30
32
33 void Init(const IComponent* ownerPtr, const IRealAttributeStaticInfo& staticInfo);
34
39 bool IsValid() const;
40
45 bool EnsureInitialized() const;
46
51 Interface* operator[](int index) const;
52
53protected:
55
56private:
57 const IComponent* m_definitionComponentPtr;
58
59 typedef QVector<Interface*> Components;
60 mutable Components m_components;
61 mutable bool m_isInitialized;
62};
63
64
65// public methods
66
67template <class Interface>
69: m_definitionComponentPtr(nullptr), m_isInitialized(false)
70{
71}
72
73
74template <class Interface>
76{
77 BaseClass::InitInternal(ownerPtr, staticInfo, &m_definitionComponentPtr);
78
79 m_components.clear();
80}
81
82
83template <class Interface>
85{
86 return EnsureInitialized();
87}
88
89
90template <class Interface>
92{
93 if (!m_isInitialized && (m_definitionComponentPtr != nullptr) && BaseClass::IsValid()){
94 const ICompositeComponent* parentPtr = m_definitionComponentPtr->GetParentComponent();
95 if (parentPtr != nullptr){
96 int attributesCount = BaseClass::GetCount();
97
98 m_components.resize(attributesCount);
99
100 for (int i = 0; i < attributesCount; ++i){
101 const QByteArray& componentId = BaseClass::operator[](i);
102
103 QByteArray baseId;
104 QByteArray subId;
105 BaseClass2::SplitId(componentId, baseId, subId);
106
107 IComponent* componentPtr = parentPtr->GetSubcomponent(baseId);
108
109 m_components[i] = BaseClass2::ExtractInterface<Interface>(componentPtr, subId);
110 }
111
112 m_isInitialized = true;
113 }
114 else{
115 qCritical("Components are is defined, but definition component has no parent");
116 }
117 }
118
119 return m_isInitialized;
120}
121
122
123template <class Interface>
125{
126 Q_ASSERT(index >= 0);
127
128 if (EnsureInitialized()){
129 Q_ASSERT(index < int(m_components.size()));
130
131 return m_components[index];
132 }
133
134 return nullptr;
135}
136
137
138// protected methods
139
140template <class Interface>
142: BaseClass(ptr),
143 m_definitionComponentPtr(ptr.m_definitionComponentPtr),
144 m_components(ptr.m_components),
145 m_isInitialized(ptr.m_isInitialized)
146{
147}
148
149
150} // namespace icomp
151
152
Main component interface.
Definition IComponent.h:35
virtual const ICompositeComponent * GetParentComponent(bool ownerOnly=false) const =0
Get parent of this component.
Composite component interface.
virtual IComponent * GetSubcomponent(const QByteArray &componentId) const =0
Get access to subcomponent using its ID.
Interface adding to attribute static info functionality existing only for real attributes.
Pointer to component attribute.
Pointer to list of referenced component objects.
bool IsValid() const
Check if this reference can be resolved.
TMultiAttributeMember< CMultiReferenceAttribute > BaseClass
void Init(const IComponent *ownerPtr, const IRealAttributeStaticInfo &staticInfo)
Interface * operator[](int index) const
Access to interface of component at specified index.
bool EnsureInitialized() const
Ensure that initlization process is closed.
Package with interfaces and class used for components concept.

© Witold Gantzke and Kirill Lepskiy