TObjectProperty.h
Go to the documentation of this file.
1 #ifndef iprop_TObjectProperty_included
2 #define iprop_TObjectProperty_included
3 
4 
5 // ACF includes
6 #include "istd/CClassInfo.h"
7 #include "istd/TDelPtr.h"
8 #include "istd/TChangeNotifier.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 
24 template <typename Value>
26 {
27 public:
28  typedef Value ValueType;
31 
33 
35  IPropertiesManager* propertyOwnerPtr,
36  const QByteArray& propertyName,
37  const QByteArray& propertyDescription,
38  int propertyFlags,
39  int changeFlags = 0,
40  const ValueType& defaultValue = ValueType());
41 
42  const Value& GetValue() const;
43  bool SetValue(const Value& value);
44  void ResetValue();
45 
46  // reimplemented (iser::IProperty)
47  virtual const iser::IObject* GetDefaultPropertyPtr() const;
48 
49  // reimplemented (iser::IObject)
50  virtual QByteArray GetFactoryId() const;
51 
52  // reimplemented (iser::ISerializable)
53  virtual bool Serialize(iser::IArchive& archive);
54 
55  // static methods
56  static QByteArray GetTypeName();
57 
58 protected:
60 
62 };
63 
64 
65 // public methods
66 
67 template <typename Value>
69  :BaseClass()
70 {
71 }
72 
73 
74 template <typename Value>
76  IPropertiesManager* propertyOwnerPtr,
77  const QByteArray& propertyName,
78  const QByteArray& propertyDescription,
79  int propertyFlags,
80  int changeFlags,
81  const ValueType& defaultValue)
82  :BaseClass(propertyOwnerPtr, propertyName, propertyDescription, propertyFlags, changeFlags)
83 {
85 
86  m_defaultPropertyValuePtr->SetValue(defaultValue);
87 
88  SetValue(defaultValue);
89 }
90 
91 
92 template <typename Value>
94 {
95  return m_value;
96 }
97 
98 
99 template <typename Value>
100 bool TObjectProperty<Value>::SetValue(const Value& value)
101 {
102  if (!m_value.IsEqual(value)){
103  return m_value.CopyFrom(value);
104  }
105 
106  return true;
107 }
108 
109 
110 template <typename Value>
112 {
113  if (m_defaultPropertyValuePtr.IsValid()){
114  SetValue(m_defaultPropertyValuePtr->GetValue());
115  }
116 }
117 
118 
119 // reimplemented (iser::IProperty)
120 
121 template <typename Value>
123 {
124  return m_defaultPropertyValuePtr.GetPtr();
125 }
126 
127 
128 // reimplemented (iser::IObject)
129 
130 template <typename Value>
132 {
133  return GetTypeName();
134 }
135 
136 
137 // reimplemented (iser::ISerializable)
138 
139 template <typename Value>
141 {
142  static iser::CArchiveTag valueTag("Value", "Property value");
143 
144  istd::CChangeNotifier notifier(archive.IsStoring()? NULL: this);
145 
146  bool retVal = true;
147 
148  retVal = retVal && archive.BeginTag(valueTag);
149  retVal = retVal && m_value.Serialize(archive);
150  retVal = retVal && archive.EndTag(valueTag);
151 
152  return retVal;
153 }
154 
155 
156 // static methods
157 
158 template <typename Value>
160 {
161  return istd::CClassInfo::GetName<TObjectProperty<Value> >();
162 }
163 
164 
165 } // namespace iprop
166 
167 
168 #endif // !iprop_TObjectProperty_included
169 
170 
virtual bool Serialize(iser::IArchive &archive)
istd::TDelPtr< PropertyType > m_defaultPropertyValuePtr
Basic implementation of an property.
Definition: CPropertyBase.h:22
Common interface for a container of properties.
iser::TCopySerializedWrap< Value > m_value
static QByteArray GetTypeName()
TObjectProperty< Value > PropertyType
virtual QByteArray GetFactoryId() const
virtual const iser::IObject * GetDefaultPropertyPtr() const
#define NULL
Property implementation for serializable objects.
bool SetValue(const Value &value)
const Value & GetValue() const

© 2007-2011 Witold Gantzke and Kirill Lepskiy