TAttributeStaticInfo.h
Go to the documentation of this file.
1 #ifndef icomp_TAttributeStaticInfo_included
2 #define icomp_TAttributeStaticInfo_included
3 
4 
5 // Qt includes
6 #include <QtCore/QMap>
7 
8 // ACF includes
9 #include <istd/CClassInfo.h>
10 
13 
14 
15 namespace icomp
16 {
17 
18 
19 template <class Attribute>
21 {
22 public:
25  const QByteArray& id,
26  const QString& description,
27  const Attribute* defaultValuePtr,
28  int flags,
29  const istd::CClassInfo& relatedInterfaceInfo);
30 
31  // reimplemented (icomp::IRealAttributeStaticInfo)
32  virtual const QByteArray& GetAttributeId() const;
33  virtual void AddRelatedMetaId(int metaGroupId, const QByteArray& id, int flags);
34 
35  // reimplemented (icomp::IAttributeStaticInfo)
36  virtual IElementStaticInfo::Ids GetRelatedMetaIds(int metaGroupId, int flags, int flagsMask) const;
37 
38  // reimplemented (iattr::IAttributeMetaInfo)
39  virtual QString GetAttributeDescription() const;
40  virtual const iser::IObject* GetAttributeDefaultValue() const;
41  virtual QByteArray GetAttributeTypeId() const;
42  virtual int GetAttributeFlags() const;
43 
44 private:
45  QByteArray m_id;
46  QString m_description;
47  const Attribute* m_defaultValuePtr;
48  int m_attributeFlags;
49 
50  typedef QMap<QByteArray, int> IdsToFlagsMap;
51  typedef QMap<int, IdsToFlagsMap> RelatedIdsMap;
52  RelatedIdsMap m_relatedInterfacesMap;
53 };
54 
55 
56 // public methods
57 
58 template <class Attribute>
61  const QByteArray& id,
62  const QString& description,
63  const Attribute* defaultValuePtr,
64  int flags,
65  const istd::CClassInfo& relatedInterfaceInfo)
66 : m_id(id),
67  m_description(description),
68  m_defaultValuePtr(defaultValuePtr),
69  m_attributeFlags(flags)
70 {
71  if (relatedInterfaceInfo.IsValid() && !relatedInterfaceInfo.IsVoid()){
72  m_relatedInterfacesMap[IComponentStaticInfo::MGI_INTERFACES][relatedInterfaceInfo.GetName()] = flags;
73  }
74 
75  staticInfo.RegisterAttributeInfo(id, this);
76 }
77 
78 
79 // reimplemented (icomp::IRealAttributeStaticInfo)
80 
81 template <class Attribute>
83 {
84  return m_id;
85 }
86 
87 
88 template <class Attribute>
89 void TAttributeStaticInfo<Attribute>::AddRelatedMetaId(int metaGroupId, const QByteArray& id, int flags)
90 {
91  IdsToFlagsMap& groupMap = m_relatedInterfacesMap[metaGroupId];
92 
93  IdsToFlagsMap::iterator foundIter = groupMap.find(id);
94  if (foundIter != groupMap.end()){
95  Q_ASSERT((flags & (AF_REFERENCE | AF_FACTORY)) == (foundIter.value() & (AF_REFERENCE | AF_FACTORY))); // factory can be combined with factory only and reference with reference
96 
97  foundIter.value() |= flags & AF_OBLIGATORY; // is obligatory if once obligatory registred is
98  foundIter.value() &= flags | ~AF_NULLABLE; // is nullable if always nullable registred is
99  }
100  else{
101  groupMap[id] = flags;
102  }
103 
104  if (metaGroupId == IComponentStaticInfo::MGI_INTERFACES){
105  m_attributeFlags |= flags & AF_OBLIGATORY; // attribute is obligatory if one of declared interfaces obligatory is
106  m_attributeFlags &= flags | ~AF_NULLABLE; // attribute is nullable if all of declared interfaces nullable are
107  }
108 }
109 
110 
111 // reimplemented (iattr::IAttributeMetaInfo)
112 
113 template <class Attribute>
114 IElementStaticInfo::Ids TAttributeStaticInfo<Attribute>::GetRelatedMetaIds(int metaGroupId, int flags, int flagsMask) const
115 {
117 
118  RelatedIdsMap::ConstIterator foundGroupIter = m_relatedInterfacesMap.constFind(metaGroupId);
119  if (foundGroupIter != m_relatedInterfacesMap.constEnd()){
120  const IdsToFlagsMap& groupMap = foundGroupIter.value();
121 
122  for ( IdsToFlagsMap::const_iterator iter = groupMap.begin();
123  iter != groupMap.end();
124  ++iter){
125  const QByteArray& id = iter.key();
126  int idFlags = iter.value();
127 
128  if (((idFlags & flagsMask) == flags)){
129  retVal.insert(id);
130  }
131  }
132  }
133 
134  return retVal;
135 }
136 
137 
138 // reimplemented (icomp::IAttributeStaticInfo)
139 
140 template <class Attribute>
142 {
143  return m_description;
144 }
145 
146 
147 template <class Attribute>
149 {
150  return m_defaultValuePtr;
151 }
152 
153 
154 template <class Attribute>
156 {
157  return Attribute::GetTypeName();
158 }
159 
160 
161 template <class Attribute>
163 {
164  return m_attributeFlags;
165 }
166 
167 
168 } // namespace icomp
169 
170 
171 #endif // !icomp_TAttributeStaticInfo_included
172 
173 
virtual QString GetAttributeDescription() const
Get description of this attribute.
const QByteArray & GetName() const
Get undecorated and platform undependent class name.
Definition: CClassInfo.h:146
Common interface for factorisable model objects.
Definition: IObject.h:19
bool IsValid() const
Check if this class info object is valid.
Definition: CClassInfo.h:140
virtual QByteArray GetAttributeTypeId() const
Return attribute type ID.
Interface adding to attribute static info functionality existing only for real attributes.
virtual IElementStaticInfo::Ids GetRelatedMetaIds(int metaGroupId, int flags, int flagsMask) const
Get related meta information.
virtual void RegisterAttributeInfo(const QByteArray &attributeId, const IAttributeStaticInfo *attributeInfoPtr)
Register static attribute info.
Standard implementation of static info for base component classes.
virtual int GetAttributeFlags() const
Get flags of this attribute.
bool IsVoid() const
Check if this class information represents void type.
Definition: CClassInfo.h:152
virtual const iser::IObject * GetAttributeDefaultValue() const
Get default attribute value.
Represents platform independent type info and provide set of static class manipulation functions...
Definition: CClassInfo.h:22
ID of meta group storing list of supported interfaces.
virtual const QByteArray & GetAttributeId() const
Get ID of this attribute.
virtual void AddRelatedMetaId(int metaGroupId, const QByteArray &id, int flags)
Add related interface to this attribute info.
TAttributeStaticInfo(icomp::CBaseComponentStaticInfo &staticInfo, const QByteArray &id, const QString &description, const Attribute *defaultValuePtr, int flags, const istd::CClassInfo &relatedInterfaceInfo)

© 2007-2017 Witold Gantzke and Kirill Lepskiy