ICF 3.1.1.10
Technical documentation of ICF Libraries
TAttribute.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/QByteArray>
11
12// ICF includes
14#include <istd/CClassInfo.h>
15#include <iser/IArchive.h>
16#include <iser/IObject.h>
17#include <iser/CArchiveTag.h>
20
21
22namespace iattr
23{
24
25
31template <typename Value>
32class TAttribute: public iser::TCopySerializedWrap<iser::IObject>
33{
34public:
35 typedef Value ValueType;
37
43
44 TAttribute();
45 TAttribute(const TAttribute& attribute);
46
47 explicit TAttribute(const Value& value);
48
49 virtual const Value& GetValue() const;
50 virtual void SetValue(const Value& value);
51
52 // reimplemented (iser::IObject)
53 virtual QByteArray GetFactoryId() const;
54
55 // reimplemented (iser::ISerializable)
56 virtual bool Serialize(iser::IArchive& archive);
57
58 // static methods
59 static QByteArray GetTypeName();
60
61protected:
62 Value m_value;
63};
64
65
66// public methods
67
68template <typename Value>
73
74
75template <typename Value>
77 :BaseClass(),
78 m_value(value)
79{
80}
81
82
83template <typename Value>
85 :BaseClass(),
86 m_value(attribute.GetValue())
87{
88}
89
90
91template <typename Value>
92const Value& TAttribute<Value>::GetValue() const
93{
94 return m_value;
95}
96
97
98template <typename Value>
99void TAttribute<Value>::SetValue(const Value& value)
100{
101 if (m_value != value){
102 istd::CChangeNotifier notifier(this);
103
104 m_value = value;
105 }
106}
107
108
109// reimplemented (iser::IObject)
110
111template <typename Value>
113{
114 return GetTypeName();
115}
116
117
118// reimplemented (iser::ISerializable)
119
120template <typename Value>
122{
123 static iser::CArchiveTag valueTag("Value", "Value of attribute", iser::CArchiveTag::Type::Leaf);
124
125 istd::CChangeNotifier notifier(archive.IsChanging()? this: nullptr, &GetAllChanges());
126
127 return archive.ProcessLeaf(valueTag, m_value);
128}
129
130
131// static methods
132
133template <typename Value>
138
139
140template <>
142{
143 return "Integer";
144}
145
146
147template <>
149{
150 return "Real";
151}
152
153
154template <>
156{
157 return "Boolean";
158}
159
160
161template <>
163{
164 return "String";
165}
166
167
168template <>
170{
171 return "Id";
172}
173
174
175// typedefs
176
182
183
184} // namespace iattr
185
186
@ AF_OBLIGATORY
Active if user declared this attribute as obligatory.
@ AF_NULLABLE
Active if this attribute can be unset (null).
@ AF_SINGLE
Attribute is single type.
@ AF_VALUE
Attribute is simple value type.
Template implementation of single component attribute.
Definition TAttribute.h:33
virtual QByteArray GetFactoryId() const
Definition TAttribute.h:112
virtual bool Serialize(iser::IArchive &archive)
Load or store state of this object as a archive stream.
Definition TAttribute.h:121
iser::TCopySerializedWrap< iser::IObject > BaseClass
Definition TAttribute.h:36
virtual const Value & GetValue() const
Definition TAttribute.h:92
static QByteArray GetTypeName()
Definition TAttribute.h:134
virtual void SetValue(const Value &value)
Definition TAttribute.h:99
Process tag used to group data in archive stream.
Definition CArchiveTag.h:25
@ Leaf
Leaf tag, it can contain only one primitive element.
Represent input/output persistence archive.
Definition IArchive.h:34
virtual bool ProcessLeaf(const CArchiveTag &tag, bool &value)=0
Process primitive type.
virtual bool IsChanging() const =0
Check if this archive processing change the object state.
Help class which provides the automatic update mechanism of the model.
const QByteArray & GetName() const
Get undecorated and platform undependent class name.
Definition CClassInfo.h:150
This namespace containes implementations of attributes concept.
TAttribute< int > CIntegerAttribute
Definition TAttribute.h:177
TAttribute< QString > CStringAttribute
Definition TAttribute.h:180
TAttribute< QByteArray > CIdAttribute
Definition TAttribute.h:181
TAttribute< bool > CBooleanAttribute
Definition TAttribute.h:179
TAttribute< double > CRealAttribute
Definition TAttribute.h:178

© Witold Gantzke and Kirill Lepskiy