TProperty.h
Go to the documentation of this file.
1 #ifndef iprop_TProperty_included
2 #define iprop_TProperty_included
3 
4 
5 // ACF includes
6 #include "istd/TDelPtr.h"
7 #include "istd/TChangeNotifier.h"
8 #include "istd/CClassInfo.h"
9 #include "iser/IArchive.h"
10 #include "iser/CArchiveTag.h"
11 
12 // ACF-Solutions includes
13 #include "iprop/CPropertyBase.h"
14 
15 
16 namespace iprop
17 {
18 
19 
27 template <typename Value>
28 class TProperty: public CPropertyBase
29 {
30 public:
31  typedef Value ValueType;
34 
35  TProperty();
36 
37  TProperty(
38  IPropertiesManager* propertyOwnerPtr,
39  const QByteArray& propertyName,
40  const QByteArray& propertyDescription,
41  int propertyFlags,
42  int changeFlags = 0,
43  const ValueType& defaultValue = ValueType());
44 
45  const Value& GetValue() const;
46  void SetValue(const Value& value);
47 
48  // reimplemented (iser::IProperty)
49  virtual void ResetValue();
50  virtual const iser::IObject* GetDefaultPropertyPtr() const;
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 
61 protected:
62  Value m_value;
63 
65 };
66 
67 
68 // public methods
69 
70 template <typename Value>
72  :BaseClass()
73 {
74 }
75 
76 
77 template <typename Value>
79  IPropertiesManager* propertyOwnerPtr,
80  const QByteArray& propertyName,
81  const QByteArray& propertyDescription,
82  int propertyFlags,
83  int changeFlags,
84  const ValueType& defaultValue)
85  :BaseClass(propertyOwnerPtr, propertyName, propertyDescription, propertyFlags, changeFlags),
86  m_value(defaultValue)
87 {
88  if (!m_defaultPropertyValuePtr.IsValid()){
90 
91  m_defaultPropertyValuePtr->SetValue(defaultValue);
92  }
93 }
94 
95 
96 template <typename Value>
97 const Value& TProperty<Value>::GetValue() const
98 {
99  return m_value;
100 }
101 
102 
103 template <typename Value>
104 void TProperty<Value>::SetValue(const Value& value)
105 {
106  if (m_value != value){
107  istd::CChangeNotifier changePtr(m_propertyOwnerPtr, m_changeFlags);
108 
109  m_value = value;
110  }
111 }
112 
113 
114 // reimplemented (iser::IProperty)
115 
116 template <typename Value>
118 {
119  if (m_defaultPropertyValuePtr.IsValid()){
120  SetValue(m_defaultPropertyValuePtr->GetValue());
121  }
122 }
123 
124 
125 template <typename Value>
127 {
128  return m_defaultPropertyValuePtr.GetPtr();
129 }
130 
131 
132 // reimplemented (iser::IObject)
133 
134 template <typename Value>
136 {
137  return GetTypeName();
138 }
139 
140 
141 // reimplemented (iser::ISerializable)
142 
143 template <typename Value>
145 {
146  static iser::CArchiveTag valueTag("Value", "Property value");
147 
148  istd::CChangeNotifier notifier(archive.IsStoring()? NULL: this);
149 
150  bool retVal = true;
151 
152  retVal = retVal && archive.BeginTag(valueTag);
153  retVal = retVal && archive.Process(m_value);
154  retVal = retVal && archive.EndTag(valueTag);
155 
156  return retVal;
157 }
158 
159 
160 // static methods
161 
162 template <typename Value>
164 {
165  return istd::CClassInfo::GetName<TProperty<Value> >();
166 }
167 
168 
169 template <>
170 inline QByteArray TProperty<bool>::GetTypeName()
171 {
172  return "Boolean";
173 }
174 
175 
176 template <>
178 {
179  return "Real";
180 }
181 
182 
183 template <>
184 inline QByteArray TProperty<int>::GetTypeName()
185 {
186  return "Integer";
187 }
188 
189 
190 template <>
192 {
193  return "String";
194 }
195 
196 
197 template <>
199 {
200  return "Id";
201 }
202 
203 
204 // typedefs
205 
211 
212 
213 } // namespace iprop
214 
215 
216 #endif // !iprop_TProperty_included
217 
218 
const Value & GetValue() const
Definition: TProperty.h:97
TProperty< int > CIntProperty
Definition: TProperty.h:208
Template implementation of an atomic property.
Definition: TProperty.h:28
TProperty< bool > CBoolProperty
Definition: TProperty.h:207
TProperty< double > CDoubleProperty
Definition: TProperty.h:206
virtual void ResetValue()
Definition: TProperty.h:117
Basic implementation of an property.
Definition: CPropertyBase.h:22
Common interface for a container of properties.
virtual bool Serialize(iser::IArchive &archive)
Definition: TProperty.h:144
TProperty< QByteArray > CStdStringProperty
Definition: TProperty.h:210
#define NULL
TProperty< QString > CStringProperty
Definition: TProperty.h:209
virtual const iser::IObject * GetDefaultPropertyPtr() const
Definition: TProperty.h:126
static QByteArray GetTypeName()
Definition: TProperty.h:163
virtual QByteArray GetFactoryId() const
Definition: TProperty.h:135
CPropertyBase BaseClass
Definition: TProperty.h:33
TProperty< Value > PropertyType
Definition: TProperty.h:32
istd::TDelPtr< PropertyType > m_defaultPropertyValuePtr
Definition: TProperty.h:64
void SetValue(const Value &value)
Definition: TProperty.h:104

© 2007-2011 Witold Gantzke and Kirill Lepskiy