TMultiAttributeMember.h
Go to the documentation of this file.
1 #ifndef icomp_TMultiAttributeMember_included
2 #define icomp_TMultiAttributeMember_included
3 
4 
5 // ACF includes
8 
9 
10 namespace icomp
11 {
12 
13 
19 template <typename Attribute>
21 {
22 public:
23  typedef Attribute AttributeType;
24  typedef typename Attribute::ValueType AttributeValueType;
25  typedef void InterfaceType;
26 
28 
36  void Init(const IComponent* ownerPtr, const IRealAttributeStaticInfo& staticInfo);
37 
41  bool IsValid() const;
42 
46  int GetCount() const;
47 
51  const AttributeValueType& operator[](int index) const;
52 
57  int FindValue(const AttributeValueType& value) const;
58 
59 protected:
60  bool InitInternal(
61  const IComponent* ownerPtr,
62  const IRealAttributeStaticInfo& staticInfo,
63  const IComponent** definitionComponentPtr);
64 
65 
66 private:
67  const Attribute* m_attributePtr;
68 };
69 
70 
71 // public methods
72 
73 template <typename Attribute>
75 : m_attributePtr(NULL)
76 {
77 }
78 
79 
80 template <typename Attribute>
82  const IComponent* ownerPtr,
83  const IRealAttributeStaticInfo& staticInfo)
84 {
85  InitInternal(ownerPtr, staticInfo, NULL);
86 }
87 
88 
89 template <typename Attribute>
91 {
92  return (m_attributePtr != NULL);
93 }
94 
95 
96 template <typename Attribute>
98 {
99  if (m_attributePtr != NULL){
100  return m_attributePtr->GetValuesCount();
101  }
102  else{
103  return 0;
104  }
105 }
106 
107 
108 template <typename Attribute>
110 {
111  Q_ASSERT(index >= 0);
112  Q_ASSERT(index < GetCount());
113  Q_ASSERT(m_attributePtr != NULL); // operator* was called for invalid object, or no IsValid() check was called.
114  Q_ASSERT(m_attributePtr->GetValuesCount() == GetCount());
115 
116  return m_attributePtr->GetValueAt(index);
117 }
118 
119 
120 template <typename Attribute>
122 {
123  if (m_attributePtr != NULL){
124  return m_attributePtr->FindValue(value);
125  }
126 
127  return -1;
128 }
129 
130 
131 // protected methods
132 
133 template <typename Attribute>
135  const IComponent* ownerPtr,
136  const IRealAttributeStaticInfo& staticInfo,
137  const IComponent** definitionComponentPtr)
138 {
139  Q_ASSERT(ownerPtr != NULL);
140 
141  const QByteArray& attributeId = staticInfo.GetAttributeId();
142  const IComponentContext* componentContextPtr = ownerPtr->GetComponentContext();
143  if (componentContextPtr != NULL){
144  int definitionLevel = -1;
145  const iser::IObject* attributePtr = componentContextPtr->GetAttribute(attributeId, &definitionLevel);
146  m_attributePtr = dynamic_cast<const Attribute*>(attributePtr);
147 
148  if (m_attributePtr != NULL){
149  Q_ASSERT(definitionLevel >= 0);
150 
151  if (definitionComponentPtr != NULL){
152  while (definitionLevel > 0){
153  ownerPtr = ownerPtr->GetParentComponent();
154  Q_ASSERT(ownerPtr != NULL);
155 
156  --definitionLevel;
157  }
158 
159  *definitionComponentPtr = ownerPtr;
160  }
161 
162  return true;
163  }
164  }
165  else{
166  m_attributePtr = NULL;
167  }
168 
169  return false;
170 }
171 
172 
173 // Translatable attribute
174 
176 {
177 public:
179 
181  {
182  }
183 
184  explicit CMultiTextAttribute(int elementsCount, QString* valuesPtr)
185  : BaseClass(elementsCount, valuesPtr)
186  {
187  }
188 
190  {
193  };
194 
195  static QByteArray GetTypeName()
196  {
197  return "Text[]";
198  }
199 
200  // reimplemented (iser::IObject)
201  virtual QByteArray GetFactoryId() const
202  {
203  return GetTypeName();
204  }
205 };
206 
207 
208 class CMultiTextAttributeMember: public TMultiAttributeMember<CMultiTextAttribute>
209 {
210 public:
212 
213  QString operator[](int index) const
214  {
215  return QCoreApplication::translate("Attribute", BaseClass::operator[](index).toLatin1());
216  }
217 };
218 
219 
220 } // namespace icomp
221 
222 
223 #endif // !icomp_TMultiAttributeMember_included
224 
225 
CMultiTextAttribute(int elementsCount, QString *valuesPtr)
bool InitInternal(const IComponent *ownerPtr, const IRealAttributeStaticInfo &staticInfo, const IComponent **definitionComponentPtr)
Template implementation of multiple component attribute.
QString operator[](int index) const
virtual const IComponentContext * GetComponentContext() const =0
Get access to component context describing all application-specified component information loaded fro...
Main component interface.
Definition: IComponent.h:31
Provide session context of component.
Common interface for factorisable model objects.
Definition: IObject.h:19
void Init(const IComponent *ownerPtr, const IRealAttributeStaticInfo &staticInfo)
Internal initialize of attribute.
virtual const ICompositeComponent * GetParentComponent(bool ownerOnly=false) const =0
Get parent of this component.
virtual const QByteArray & GetAttributeId() const =0
Get ID of this attribute.
Interface adding to attribute static info functionality existing only for real attributes.
TMultiAttributeMember< CMultiTextAttribute > BaseClass
bool IsValid() const
Check if this attribute is valid.
int GetCount() const
Get number of attributes.
int FindValue(const AttributeValueType &value) const
Find attribute value.
#define NULL
Definition: istd.h:64
const AttributeValueType & operator[](int index) const
Access to object pointed by internal pointer.
virtual QByteArray GetFactoryId() const
virtual const iser::IObject * GetAttribute(const QByteArray &attributeId, int *definitionLevelPtr=NULL) const =0
Get attribute using its ID.
Attribute::ValueType AttributeValueType
iattr::CStringListAttribute BaseClass
Pointer to component attribute.

© 2007-2017 Witold Gantzke and Kirill Lepskiy