ICF 3.0.5.47
Technical documentation of ICF Libraries
TMultiAttributeMember.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
12
13
14namespace icomp
15{
16
17
23template <typename Attribute>
25{
26public:
27 typedef Attribute AttributeType;
28 typedef typename Attribute::ValueType AttributeValueType;
29 typedef void InterfaceType;
30
32
40 void Init(const IComponent* ownerPtr, const IRealAttributeStaticInfo& staticInfo);
41
45 bool IsValid() const;
46
50 int GetCount() const;
51
55 const AttributeValueType& operator[](int index) const;
56
61 int FindValue(const AttributeValueType& value) const;
62
63protected:
65 const IComponent* ownerPtr,
66 const IRealAttributeStaticInfo& staticInfo,
67 const IComponent** definitionComponentPtr);
68
69
70private:
71 const Attribute* m_attributePtr;
72};
73
74
75// public methods
76
77template <typename Attribute>
79: m_attributePtr(nullptr)
80{
81}
82
83
84template <typename Attribute>
86 const IComponent* ownerPtr,
87 const IRealAttributeStaticInfo& staticInfo)
88{
89 InitInternal(ownerPtr, staticInfo, nullptr);
90}
91
92
93template <typename Attribute>
95{
96 return (m_attributePtr != nullptr);
97}
98
99
100template <typename Attribute>
102{
103 if (m_attributePtr != nullptr){
104 return m_attributePtr->GetValuesCount();
105 }
106 else{
107 return 0;
108 }
109}
110
111
112template <typename Attribute>
114{
115 Q_ASSERT(index >= 0);
116 Q_ASSERT(index < GetCount());
117 Q_ASSERT(m_attributePtr != nullptr); // operator* was called for invalid object, or no IsValid() check was called.
118 Q_ASSERT(m_attributePtr->GetValuesCount() == GetCount());
119
120 return m_attributePtr->GetValueAt(index);
121}
122
123
124template <typename Attribute>
126{
127 if (m_attributePtr != nullptr){
128 return m_attributePtr->FindValue(value);
129 }
130
131 return -1;
132}
133
134
135// protected methods
136
137template <typename Attribute>
139 const IComponent* ownerPtr,
140 const IRealAttributeStaticInfo& staticInfo,
141 const IComponent** definitionComponentPtr)
142{
143 Q_ASSERT(ownerPtr != nullptr);
144
145 const QByteArray& attributeId = staticInfo.GetAttributeId();
146 const IComponentContext* componentContextPtr = ownerPtr->GetComponentContext();
147 if (componentContextPtr != nullptr){
148 int definitionLevel = -1;
149 const iser::IObject* attributePtr = componentContextPtr->GetAttribute(attributeId, &definitionLevel);
150 m_attributePtr = dynamic_cast<const Attribute*>(attributePtr);
151
152 if (m_attributePtr != nullptr){
153 Q_ASSERT(definitionLevel >= 0);
154
155 if (definitionComponentPtr != nullptr){
156 while (definitionLevel > 0){
157 ownerPtr = ownerPtr->GetParentComponent();
158 Q_ASSERT(ownerPtr != nullptr);
159
160 --definitionLevel;
161 }
162
163 *definitionComponentPtr = ownerPtr;
164 }
165
166 return true;
167 }
168 }
169 else{
170 m_attributePtr = nullptr;
171 }
172
173 return false;
174}
175
176
177// Translatable attribute
178
180{
181public:
183
185 {
186 }
187
188 explicit CMultiTextAttribute(int elementsCount, QString* valuesPtr)
189 : BaseClass(elementsCount, valuesPtr)
190 {
191 }
192
198
199 static QByteArray GetTypeName()
200 {
201 return "Text[]";
202 }
203
204 // reimplemented (iser::IObject)
205 virtual QByteArray GetFactoryId() const
206 {
207 return GetTypeName();
208 }
209};
210
211
212class CMultiTextAttributeMember: public TMultiAttributeMember<CMultiTextAttribute>
213{
214public:
216
217 QString operator[](int index) const
218 {
219 return QCoreApplication::translate("Attribute", BaseClass::operator[](index).toLatin1());
220 }
221};
222
223
224} // namespace icomp
225
226
Template implementation of multiple component attribute.
CMultiTextAttribute(int elementsCount, QString *valuesPtr)
virtual QByteArray GetFactoryId() const
iattr::CStringListAttribute BaseClass
TMultiAttributeMember< CMultiTextAttribute > BaseClass
@ AF_TRANSLATABLE
Attribute is able to translate.
Provide session context of component.
virtual const iser::IObject * GetAttribute(const QByteArray &attributeId, int *definitionLevelPtr=nullptr) const =0
Get attribute using its ID.
Main component interface.
Definition IComponent.h:35
virtual const IComponentContext * GetComponentContext() const =0
Get access to component context describing all application-specified component information loaded fro...
virtual const ICompositeComponent * GetParentComponent(bool ownerOnly=false) const =0
Get parent of this component.
Interface adding to attribute static info functionality existing only for real attributes.
virtual const QByteArray & GetAttributeId() const =0
Get ID of this attribute.
Pointer to component attribute.
bool IsValid() const
Check if this attribute is valid.
int FindValue(const AttributeValueType &value) const
Find attribute value.
const AttributeValueType & operator[](int index) const
Access to object pointed by internal pointer.
void Init(const IComponent *ownerPtr, const IRealAttributeStaticInfo &staticInfo)
Internal initialize of attribute.
int GetCount() const
Get number of attributes.
bool InitInternal(const IComponent *ownerPtr, const IRealAttributeStaticInfo &staticInfo, const IComponent **definitionComponentPtr)
Attribute::ValueType AttributeValueType
Common interface for factorisable model objects.
Definition IObject.h:25
Package with interfaces and class used for components concept.

© Witold Gantzke and Kirill Lepskiy