ADTF
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
property.h
Go to the documentation of this file.
1
7#pragma once
8#include "property_intf.h"
9#include "propertyconvert.h"
11#include <optional>
12#include <cstring>
13
14namespace adtf
15{
16namespace base
17{
18namespace ant
19{
20 template<typename T>
21 class property_value : public adtf::base::ant::IPropertyValue
22 {
23 protected:
24 T m_oValue;
25 public:
26 property_value() : m_oValue()
27 {
28 }
29 property_value(const property_value& oValue) : property_value()
30 {
31 m_oValue = oValue.m_oValue;
32 }
33 property_value(property_value&& oValue) : property_value()
34 {
35 m_oValue = oValue.m_oValue;
36 }
37 property_value& operator=(const property_value& oValue)
38 {
39 m_oValue = oValue.m_oValue;
40 return *this;
41 }
42 property_value& operator=(property_value&& oValue)
43 {
44 m_oValue = oValue.m_oValue;
45 return *this;
46 }
47 virtual ~property_value()
48 {
49 }
50 property_value(const T& oValue) : property_value()
51 {
52 m_oValue = oValue;
53 }
54 void Release()
55 {
56 delete this;
57 }
58 const property_value& operator=(const T& oValue)
59 {
60 m_oValue = oValue;
61 return *this;
62 }
63 bool operator==(const T& oValue) const
64 {
65 return (m_oValue == oValue);
66 }
67 bool operator==(const property_value& oValue) const
68 {
69 return (m_oValue == oValue.GetValue());
70 }
71 const T& GetValue() const
72 {
73 return m_oValue;
74 }
75
76 tResult Set(const IPropertyValue& oValue)
77 {
78 std::string strTypeOfValue;
79 std::string strTypeOfMe;
80 if (IS_OK(oValue.GetType(adtf_string_intf(strTypeOfValue))))
81 {
82 bool bTryStringConversion = false;
83
84 GetType(adtf_string_intf(strTypeOfMe));
85 if (strTypeOfValue == strTypeOfMe)
86 {
87 bool bCalled = false;
89 {
90 bCalled = true;
91 //if Memory Value is present ...
92 //it happens by reading from XML, that only the String Representation is there !!!
93 if (oMem.GetSize() > 0)
94 {
95 //Try fast memory copy way
97 }
98 else
99 {
100 bTryStringConversion = true;
101 }
102
104 })));
105
106 if (!bCalled)
107 {
108 bTryStringConversion = true;
109 }
110 }
112 {
113 // if destination type is cString: use the ToString() of every class
114 // this is a helpful when converting i.e. cFilepath to cString
115 bTryStringConversion = true;
116 }
117 else
118 {
120 }
121
122 if (bTryStringConversion)
123 {
124 RETURN_IF_FAILED(oValue.ToString(cStringRedirect([this](const IString& strValue) -> tResult
125 {
126 RETURN_IF_FAILED(FromString(strValue));
128 })));
129 }
130 }
131 else
132 {
133 A_UTILS_ASSERT(IS_FAILED(oValue.GetType(adtf_string_intf(strTypeOfValue))));
134 RETURN_ERROR(ERR_INVALID_TYPE);
135 }
137 }
138
139 tResult GetType(IString&& strType) const
140 {
141 return strType.Set(property_type_definition<T>::TYPE_NAME);
142 }
143
144 tResult ToRaw(IRawMemory&& oToMem) const
145 {
146 return property_type_definition<T>::con_type::ToRaw(static_cast<const void*>(&m_oValue), sizeof(T), oToMem);
147 }
148 tResult FromRaw(const IRawMemory& oFromMem)
149 {
150 return property_type_definition<T>::con_type::FromRaw(oFromMem, static_cast<void*>(&m_oValue), sizeof(T));
151 }
152
153 tResult ToString(IString&& oStringValue) const
154 {
155 adtf_util::cString strValue;
157 RETURN_IF_FAILED(oStringValue.Set(strValue.GetPtr()));
159 }
160 tResult FromString(const IString& oStringValue)
161 {
162 adtf_util::cString strValue = oStringValue.Get();
163 return property_type_definition<T>::con_type::FromString(strValue, m_oValue);
164 }
165 };
166
167 class cPropertyBase : public IProperty
168 {
169 protected:
170 util::cString m_strName;
171 mutable ucom::object_ptr<IProperties> m_poSubProperties = nullptr;
172 ucom::object_ptr<IProperties> m_poAttachedProperties = nullptr;
173
174 protected:
175 cPropertyBase();
176 virtual ~cPropertyBase() override;
177
178 public:
179 tResult GetName(IString&& strName) const override;
180
181 bool HasProperties() const override;
182 bool HasAttachedProperties() const override;
183
185 tResult SetProperties(const IProperties& oProperties) override;
186
189 tResult GetAttachedProperties(IProperty& oProperty) const override;
191
196
197 public:
198 tResult SetName(const IString& strName) override;
199
200 };
201
203 {};
204
210 template <typename T>
211 class property : public cPropertyBase
212 {
213 private:
216
217 public:
219 property() : cPropertyBase()
220 {
221 }
222
223 ~property() = default;
224
226 property(const property& oProperty) : property()
227 {
228 Set(oProperty);
229 }
230
231 property(property&& oProperty)
232 {
233 m_oValue = oProperty.m_oValue;
234 m_strName = oProperty.m_strName;
235 m_poSubProperties = oProperty.m_poSubProperties;
236 oProperty.m_poSubProperties = nullptr;
237 m_poAttachedProperties = oProperty.m_poAttachedProperties;
238 oProperty.m_poAttachedProperties = nullptr;
239 }
240
241 property& operator=(const property& oValue)
242 {
243 Set(oValue);
244 return *this;
245 }
246
248 property& operator=(property&& oProperty)
249 {
250 m_oValue = oProperty.m_oValue;
251 m_strName = oProperty.m_strName;
252 m_poSubProperties = oProperty.m_poSubProperties;
253 oProperty.m_poSubProperties = nullptr;
254 m_poAttachedProperties = oProperty.m_poAttachedProperties;
255 oProperty.m_poAttachedProperties = nullptr;
256 return *this;
257 }
258
264 property(const adtf_util::cString& strName, const T& oValue)
265 {
266 m_strName = strName;
267 m_oValue = oValue;
268 }
269
275 property(std_string_helper, std::string_view strName)
276 {
277 m_strName.Set(strName.data(), strName.size());
278 }
279
284 property(const T& oValue)
285 {
286 m_oValue = oValue;
287 }
288
292 const property& operator=(const T& oValue)
293 {
294 m_oValue = oValue;
295 return *this;
296 }
297
304 bool operator==(const property& oProperty) const
305 {
306 return (m_oValue.operator==(oProperty.GetValueT()));
307 }
308
315 bool operator==(const T& oValue) const
316 {
317 return (m_oValue == oValue);
318 }
319
324 T GetValueT() const
325 {
326 return m_oValue.GetValue();
327 }
328
336 tResult Set(const property& oProperty)
337 {
338 m_oValue = oProperty.m_oValue;
339 m_strName = oProperty.m_strName;
341 oProperty.GetProperties(pSubProperties);
342
343 //if the subproperties are attached we attach them too
344 //mind : If we there are already set properties in our own m_poSubProperties they are hidden then
345 if (oProperty.HasAttachedProperties())
346 {
347 oProperty.GetAttachedProperties(*this);
348 }
349 else
350 {
351 m_poSubProperties->Set(*pSubProperties.Get());
352 }
354 }
355
356 public:
357 virtual const IPropertyValue* GetValue() const
358 {
359 return static_cast<const IPropertyValue*>(&m_oValue);
360 }
361 virtual IPropertyValue* GetValue()
362 {
363 return static_cast<IPropertyValue*>(&m_oValue);
364 }
365
366 virtual tResult SetValue(const IPropertyValue& oValue)
367 {
368 return m_oValue.Set(oValue);
369 }
370
371#if defined(_MSC_VER)
372#pragma warning( push )
373#pragma warning( disable: 4996 )
374#elif defined(__clang__)
375#pragma clang diagnostic push
376#pragma clang diagnostic ignored "-Wdeprecated-declarations"
377#else
378#pragma GCC diagnostic push
379#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
380#endif
381
382 tResult Set(const IProperty& oProp)
383 {
384 oProp.GetName(adtf_string_intf(m_strName));
385 RETURN_IF_FAILED_DESC(m_oValue.Set(*oProp.GetValue()),
386 "Unable to set value of property '%s'", m_strName.GetPtr());
387
388 if (oProp.HasProperties())
389 {
390 //if the the subproperties are attached we attach them too
391 //mind : If we would have set properties already in our own m_poSubProperties they are hidden then
392 if (oProp.HasAttachedProperties())
393 {
394 oProp.GetAttachedProperties(*this);
395 }
396 else
397 {
398 adtf::ucom::object_ptr<const IProperties> pSubProperties;
399 oProp.GetProperties(pSubProperties);
400 SetProperties(*pSubProperties.Get());
401 }
402 }
403
405 }
406 };
407#if defined(_MSC_VER)
408#pragma warning( pop )
409#elif defined(__clang__)
410#pragma clang diagnostic pop
411#else
412#pragma GCC diagnostic pop
413#endif
414
415
416} //namespace ant
417
421
422} //namespace base
423} // namespace adtf
424
425#include "properties_v2.h"
#define A_UTILS_ASSERT
This macro is used for platform independent assertion expressions.
A_UTILS_NS::cResult tResult
For backwards compatibility and to bring latest version into scope.
#define RETURN_IF_FAILED(s)
Return if expression is failed, which requires the calling function's return type to be tResult.
#define RETURN_NOERROR
Return status ERR_NOERROR, which requires the calling function's return type to be tResult.
#define RETURN_ERROR(code)
Return specific error code, which requires the calling function's return type to be tResult.
Defintion of a property set container interface.
The IProperty interface provides methods for getting and setting property values, name of the propert...
The IPropertyValue interface provides methods for getting and setting property values.
virtual tResult ToString(IString &&strIToString) const =0
Implement to serialize the value to a textfile and/or to show it on a display.
virtual tResult GetType(IString &&strType) const =0
Retrieves the string for the property value type.
The IRawMemory interface provides methods for getting and setting memory values through abstract inte...
virtual size_t GetSize() const =0
Returns the size in bytes of the memory.
virtual tResult ToRaw(IRawMemory &&oRawValue) const =0
Implement to create a fast value copy in memory.
The IString interface provides methods for getting and setting strings through abstract interfaces.
Definition string_intf.h:28
virtual const char * Get() const =0
Gets the pointer to the current associated nullterminated-string.
tResult AttachProperties(const ucom::ant::iobject_ptr< IProperties > &pAttachedProperties) override
will set given properties to be attached
tResult DetachProperties() override
tResult SetProperties(const IProperties &oProperties) override
will copy given properties
tResult GetProperties(ucom::ant::iobject_ptr< IProperties > &pSubProperties) override
get subproperties for writing access
tResult GetAttachedProperties(IProperty &oProperty) const override
tResult GetProperties(ucom::ant::iobject_ptr< const IProperties > &pSubProperties) const override
get subproperties for readonly access
tResult Set(const IPropertyValue &oValue)
Sets the value by a deep copy.
Definition property.h:76
tResult GetType(IString &&strType) const
Retrieves the string for the property value type.
Definition property.h:139
tResult ToString(IString &&oStringValue) const
Implement to serialize the value to a textfile and/or to show it on a display.
Definition property.h:153
tResult ToRaw(IRawMemory &&oToMem) const
Implement to create a fast value copy in memory.
Definition property.h:144
tResult FromString(const IString &oStringValue)
Implement to deserialize the value from a textfile and/or to set by string.
Definition property.h:160
tResult FromRaw(const IRawMemory &oFromMem)
Implement to create a fast value copy in memory.
Definition property.h:148
property(const T &oValue)
CTOR with value.
Definition property.h:284
tResult Set(const property &oProperty)
Sets the property value and name as COPY of oProperty.
Definition property.h:336
property(std_string_helper, std::string_view strName)
CTOR with name an value.
Definition property.h:275
T GetValueT() const
Get the containing value.
Definition property.h:324
~property()=default
DTOR.
bool operator==(const property &oProperty) const
compare operator
Definition property.h:304
property_value< ::adtf::base::ant::property_attached_configuration_type > m_oValue
Definition property.h:215
property & operator=(const property &oValue)
copy assignment
Definition property.h:241
property(const adtf_util::cString &strName, const T &oValue)
CTOR with name an value.
Definition property.h:264
property(const property &oProperty)
Copy CTOR.
Definition property.h:226
property & operator=(property &&oProperty)
move assignment (its not moving yet)
Definition property.h:248
bool operator==(const T &oValue) const
compare operator
Definition property.h:315
const property & operator=(const T &oValue)
value assignment
Definition property.h:292
property(property &&oProperty)
implementation of the move CTOR (but it is not moving yet)
Definition property.h:231
Base object pointer to realize binary compatible reference counting in interface methods.
Namespace for all functionality of the ADTF Base SDK provided since v3.0.
Namespace for the ADTF Base SDK.
Namespace for entire ADTF SDK.
Copyright © Audi Electronics Venture GmbH.
Copyright © Audi Electronics Venture GmbH.
Copyright © Audi Electronics Venture GmbH.
Copyright © Audi Electronics Venture GmbH.
#define adtf_string_intf(__string__)
The adtf_string_intf Macro helps to easily create a rvalue reference of a adtf::util::cString.
Concept template to define the Name and the conversion type for the given type TYPE.
Property type that creates a property that functions as a container for subproperties only.