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

© Witold Gantzke and Kirill Lepskiy