TAttribute.h
Go to the documentation of this file.
1 #ifndef iattr_TAttribute_included
2 #define iattr_TAttribute_included
3 
4 
5 // ACF includes
6 #include <istd/CChangeNotifier.h>
7 #include <istd/CClassInfo.h>
8 #include <iser/IArchive.h>
9 #include <iser/IObject.h>
10 #include <iser/CArchiveTag.h>
13 
14 
15 namespace iattr
16 {
17 
18 
24 template <typename Value>
25 class TAttribute: public iser::TCopySerializedWrap<iser::IObject>
26 {
27 public:
28  typedef Value ValueType;
30 
32  {
35  };
36 
37  TAttribute();
38  TAttribute(const TAttribute& attribute);
39 
40  explicit TAttribute(const Value& value);
41 
42  virtual const Value& GetValue() const;
43  virtual void SetValue(const Value& value);
44 
45  // reimplemented (iser::IObject)
46  virtual QByteArray GetFactoryId() const;
47 
48  // reimplemented (iser::ISerializable)
49  virtual bool Serialize(iser::IArchive& archive);
50 
51  // static methods
52  static QByteArray GetTypeName();
53 
54 protected:
55  Value m_value;
56 };
57 
58 
59 // public methods
60 
61 template <typename Value>
63  :BaseClass()
64 {
65 }
66 
67 
68 template <typename Value>
69 TAttribute<Value>::TAttribute(const Value& value)
70  :BaseClass(),
71  m_value(value)
72 {
73 }
74 
75 
76 template <typename Value>
78  :BaseClass(),
79  m_value(attribute.GetValue())
80 {
81 }
82 
83 
84 template <typename Value>
85 const Value& TAttribute<Value>::GetValue() const
86 {
87  return m_value;
88 }
89 
90 
91 template <typename Value>
92 void TAttribute<Value>::SetValue(const Value& value)
93 {
94  if (m_value != value){
95  istd::CChangeNotifier notifier(this);
96 
97  m_value = value;
98  }
99 }
100 
101 
102 // reimplemented (iser::IObject)
103 
104 template <typename Value>
106 {
107  return GetTypeName();
108 }
109 
110 
111 // reimplemented (iser::ISerializable)
112 
113 template <typename Value>
115 {
116  static iser::CArchiveTag valueTag("Value", "Value of attribute", iser::CArchiveTag::TT_LEAF);
117 
118  istd::CChangeNotifier notifier(archive.IsStoring()? NULL: this, &GetAllChanges());
119  Q_UNUSED(notifier);
120 
121  bool retVal = true;
122 
123  retVal = retVal && archive.BeginTag(valueTag);
124  retVal = retVal && archive.Process(m_value);
125  retVal = retVal && archive.EndTag(valueTag);
126 
127  return retVal;
128 }
129 
130 
131 // static methods
132 
133 template <typename Value>
135 {
136  return istd::CClassInfo::GetName<TAttribute<Value> >();
137 }
138 
139 
140 template <>
141 inline QByteArray TAttribute<int>::GetTypeName()
142 {
143  return "Integer";
144 }
145 
146 
147 template <>
149 {
150  return "Real";
151 }
152 
153 
154 template <>
155 inline QByteArray TAttribute<bool>::GetTypeName()
156 {
157  return "Boolean";
158 }
159 
160 
161 template <>
163 {
164  return "String";
165 }
166 
167 
168 template <>
170 {
171  return "Id";
172 }
173 
174 
175 // typedefs
176 
182 
183 
184 } // namespace iattr
185 
186 
187 #endif // !iattr_TAttribute_included
188 
189 
virtual bool IsStoring() const =0
Check if this archive is loading or storing.
virtual bool Process(bool &value)=0
Process primitive type.
virtual bool BeginTag(const CArchiveTag &tag)=0
Begin of archive tag.
virtual QByteArray GetFactoryId() const
Definition: TAttribute.h:105
Represent input/output persistence archive.
Definition: IArchive.h:30
Active if user declared this attribute as obligatory.
TAttribute< QString > CStringAttribute
Definition: TAttribute.h:180
static QByteArray GetTypeName()
Definition: TAttribute.h:134
Template implementation of single component attribute.
Definition: TAttribute.h:25
iser::TCopySerializedWrap< iser::IObject > BaseClass
Definition: TAttribute.h:29
Help class which provides the automatic update mechanism of the model.
Leaf tag, it can contain only one primitive element.
Definition: CArchiveTag.h:48
TAttribute< QByteArray > CIdAttribute
Definition: TAttribute.h:181
#define NULL
Definition: istd.h:64
TAttribute< int > CIntegerAttribute
Definition: TAttribute.h:177
virtual void SetValue(const Value &value)
Definition: TAttribute.h:92
TAttribute< double > CRealAttribute
Definition: TAttribute.h:178
Process tag used to group data in archive stream.
Definition: CArchiveTag.h:21
virtual const Value & GetValue() const
Definition: TAttribute.h:85
virtual bool EndTag(const CArchiveTag &tag)=0
End of archive tag.
Attribute is simple value type.
Active if this attribute can be unset (null).
TAttribute< bool > CBooleanAttribute
Definition: TAttribute.h:179
virtual bool Serialize(iser::IArchive &archive)
Load or store state of this object as a archive stream.
Definition: TAttribute.h:114

© 2007-2017 Witold Gantzke and Kirill Lepskiy