ACF $AcfVersion:0$
TAttribute.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-2.1-or-later OR GPL-2.0-or-later OR GPL-3.0-or-later OR LicenseRef-ACF-Commercial
2#pragma once
3
4
5// Qt includes
6#include <QtCore/QByteArray>
7
8// ACF includes
10#include <istd/CClassInfo.h>
11#include <iser/IArchive.h>
12#include <iser/IObject.h>
13#include <iser/CArchiveTag.h>
16
17
18namespace iattr
19{
20
21
27template <typename Value>
28class TAttribute: public iser::TCopySerializedWrap<iser::IObject>
29{
30public:
31 typedef Value ValueType;
33
39
40 TAttribute();
41 TAttribute(const TAttribute& attribute);
42
43 explicit TAttribute(const Value& value);
44
45 virtual const Value& GetValue() const;
46 virtual void SetValue(const Value& value);
47
48 // reimplemented (iser::IObject)
49 virtual QByteArray GetFactoryId() const override;
50
51 // reimplemented (iser::ISerializable)
52 virtual bool Serialize(iser::IArchive& archive) override;
53
54 // static methods
55 static QByteArray GetTypeName();
56
57protected:
58 Value m_value;
59};
60
61
62// public methods
63
64template <typename Value>
69
70
71template <typename Value>
73 :BaseClass(),
74 m_value(value)
75{
76}
77
78
79template <typename Value>
81 :BaseClass(),
82 m_value(attribute.GetValue())
83{
84}
85
86
87template <typename Value>
88const Value& TAttribute<Value>::GetValue() const
89{
90 return m_value;
91}
92
93
94template <typename Value>
95void TAttribute<Value>::SetValue(const Value& value)
96{
97 if (m_value != value){
98 istd::CChangeNotifier notifier(this);
99
100 m_value = value;
101 }
102}
103
104
105// reimplemented (iser::IObject)
106
107template <typename Value>
109{
110 return GetTypeName();
111}
112
113
114// reimplemented (iser::ISerializable)
115
116template <typename Value>
118{
119 static iser::CArchiveTag valueTag("Value", "Value of attribute", iser::CArchiveTag::TT_LEAF);
120
121 istd::CChangeNotifier notifier(archive.IsStoring()? NULL: this, &GetAllChanges());
122 Q_UNUSED(notifier);
123
124 bool retVal = true;
125
126 retVal = retVal && archive.BeginTag(valueTag);
127 retVal = retVal && archive.Process(m_value);
128 retVal = retVal && archive.EndTag(valueTag);
129
130 return retVal;
131}
132
133
134// static methods
135
136template <typename Value>
138{
139 return istd::CClassInfo::GetName<TAttribute<Value> >();
140}
141
142
143template <>
145{
146 return "Integer";
147}
148
149
150template <>
152{
153 return "Real";
154}
155
156
157template <>
159{
160 return "Boolean";
161}
162
163
164template <>
166{
167 return "String";
168}
169
170
171template <>
173{
174 return "Id";
175}
176
177
178// typedefs
179
185
186
187} // namespace iattr
188
189
190
191
@ 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:29
virtual bool Serialize(iser::IArchive &archive) override
Load or store state of this object as a archive stream.
Definition TAttribute.h:117
iser::TCopySerializedWrap< iser::IObject > BaseClass
Definition TAttribute.h:32
virtual const Value & GetValue() const
Definition TAttribute.h:88
static QByteArray GetTypeName()
Definition TAttribute.h:137
virtual void SetValue(const Value &value)
Definition TAttribute.h:95
virtual QByteArray GetFactoryId() const override
Definition TAttribute.h:108
Process tag used to group data in archive stream.
Definition CArchiveTag.h:22
@ TT_LEAF
Leaf tag, it can contain only one primitive element.
Definition CArchiveTag.h:48
Represents an input/output persistence archive for object serialization.
Definition IArchive.h:164
virtual bool Process(bool &value)=0
Processes (reads or writes) a boolean value.
virtual bool EndTag(const CArchiveTag &tag)=0
Ends a tagged section in the archive.
virtual bool IsStoring() const =0
Checks if this archive is in storing (writing) or loading (reading) mode.
virtual bool BeginTag(const CArchiveTag &tag)=0
Begins a tagged section in the archive.
Help class which provides the automatic update mechanism of the model.
#define NULL
Definition istd.h:74
This namespace containes implementations of attributes concept.
TAttribute< int > CIntegerAttribute
Definition TAttribute.h:180
TAttribute< QString > CStringAttribute
Definition TAttribute.h:183
TAttribute< QByteArray > CIdAttribute
Definition TAttribute.h:184
TAttribute< bool > CBooleanAttribute
Definition TAttribute.h:182
TAttribute< double > CRealAttribute
Definition TAttribute.h:181