ADTF  3.14.2
property.h
Go to the documentation of this file.
1 
7 #pragma once
8 #include "property_intf.h"
9 #include "propertyconvert.h"
10 
11 namespace adtf
12 {
13 namespace base
14 {
15 namespace ant
16 {
27 
29 
37  template <typename TYPE>
39  {
40  // static constexpr const tChar* const TYPE_NAME = "";
41  // typedef The Conversion Type con_type;
42  };
43 
47  template < >
49  {
50  static constexpr const tChar* const TYPE_NAME = "tBool";
52  };
53 
57  template < >
58  struct property_type_definition<int64_t>
59  {
60  static constexpr const tChar* const TYPE_NAME = "tInt64";
62  };
63 
67  template < >
68  struct property_type_definition<uint64_t>
69  {
70  static constexpr const tChar* const TYPE_NAME = "tUInt64";
72  };
73 
77  template < >
78  struct property_type_definition<uint32_t>
79  {
80  static constexpr const tChar* const TYPE_NAME = "tUInt32";
82  };
83 
87  template < >
88  struct property_type_definition<int32_t>
89  {
90  static constexpr const tChar* const TYPE_NAME = "tInt32";
92  };
93 
97  template < >
98  struct property_type_definition<uint16_t>
99  {
100  static constexpr const tChar* const TYPE_NAME = "tUInt16";
102  };
103 
107  template < >
108  struct property_type_definition<int16_t>
109  {
110  static constexpr const tChar* const TYPE_NAME = "tInt16";
112  };
113 
117  template < >
118  struct property_type_definition<uint8_t>
119  {
120  static constexpr const tChar* const TYPE_NAME = "tUInt8";
122  };
123 
127  template < >
129  {
130  static constexpr const tChar* const TYPE_NAME = "tInt8";
132  };
133 
137  template < >
139  {
140  static constexpr const tChar* const TYPE_NAME = "tFloat32";
142  };
143 
147  template < >
149  {
150  static constexpr const tChar* const TYPE_NAME = "tFloat64";
152  };
153 
157  template < >
158  struct property_type_definition<adtf::util::cString>
159  {
160  static constexpr const tChar* const TYPE_NAME = "cString";
162  };
163 
167  template < >
168  struct property_type_definition<adtf::util::cFilename>
169  {
170  static constexpr const tChar* const TYPE_NAME = "cFilename";
172  };
173 
177  template < >
178  struct property_type_definition<adtf::util::cFilenameList>
179  {
180  static constexpr const tChar* const TYPE_NAME = "cFilenameList";
182  };
183 
187  template < >
188  struct property_type_definition<adtf::util::cFilepath>
189  {
190  static constexpr const tChar* const TYPE_NAME = "cFilepath";
192  };
193 
197  template < >
198  struct property_type_definition<adtf::util::cFilepathList>
199  {
200  static constexpr const tChar* const TYPE_NAME = "cFilepathList";
202  };
203 
204  template<typename T>
206  {
207  protected:
208  T m_oValue;
209  public:
210  property_value() : m_oValue()
211  {
212  }
213  property_value(const property_value& oValue) : property_value()
214  {
215  m_oValue = oValue.m_oValue;
216  }
218  {
219  m_oValue = oValue.m_oValue;
220  }
221  property_value& operator=(const property_value& oValue)
222  {
223  m_oValue = oValue.m_oValue;
224  return *this;
225  }
226  property_value& operator=(property_value&& oValue)
227  {
228  m_oValue = oValue.m_oValue;
229  return *this;
230  }
231  virtual ~property_value()
232  {
233  }
234  property_value(const T& oValue) : property_value()
235  {
236  m_oValue = oValue;
237  }
238  void Release()
239  {
240  delete this;
241  }
242  const property_value& operator=(const T& oValue)
243  {
244  m_oValue = oValue;
245  return *this;
246  }
247  bool operator==(const T& oValue) const
248  {
249  return (m_oValue == oValue);
250  }
251  const T& GetValue() const
252  {
253  return m_oValue;
254  }
255 
256  tResult Set(const IPropertyValue& oValue)
257  {
258  adtf_util::cString strTypeOfValue;
259  adtf_util::cString strTypeOfMe;
260  if (IS_OK(oValue.GetType(adtf_string_intf(strTypeOfValue))))
261  {
262  GetType(adtf_string_intf(strTypeOfMe));
263  adtf_util::cMemoryBlock oTempValue;
264  RETURN_IF_FAILED(oValue.ToRaw(adtf_memory_intf(oTempValue)));
265  if (strTypeOfValue == strTypeOfMe)
266  {
267  //if Memory Value is present ...
268  //it happens by reading from XML, that only the String Representation is there !!!
269  if (oTempValue.GetSize() > 0)
270  {
271  //Try fast memory copy way
273  }
274  else
275  {
276  //try the string way
277  adtf_util::cString strTempValue;
278  RETURN_IF_FAILED(oValue.ToString(adtf_string_intf(strTempValue)));
280  }
281  }
283  {
284  // if destination type is cString: use the ToString() of every class
285  // this is a helpful when converting i.e. cFilepath to cString
286  adtf_util::cString strTempValue;
287  RETURN_IF_FAILED(oValue.ToString(adtf_string_intf(strTempValue)));
289  }
290  else
291  {
293  }
294  }
295  else
296  {
297  A_UTILS_ASSERT(IS_FAILED(oValue.GetType(adtf_string_intf(strTypeOfValue))));
298  RETURN_ERROR(ERR_INVALID_TYPE);
299  }
300  RETURN_NOERROR;
301  }
302 
303  tResult GetType(IString&& strType) const
304  {
305  return strType.Set(property_type_definition<T>::TYPE_NAME);
306  }
307 
308  tResult ToRaw(IRawMemory&& oToMem) const
309  {
310  return property_type_definition<T>::con_type::ToRaw(static_cast<const void*>(&m_oValue), sizeof(T), oToMem);
311  }
312  tResult FromRaw(const IRawMemory& oFromMem)
313  {
314  return property_type_definition<T>::con_type::FromRaw(oFromMem, static_cast<void*>(&m_oValue), sizeof(T));
315  }
316 
317  tResult ToString(IString&& oStringValue) const
318  {
319  adtf_util::cString strValue;
321  RETURN_IF_FAILED(oStringValue.Set(strValue.GetPtr()));
322  RETURN_NOERROR;
323  }
324  tResult FromString(const IString& oStringValue)
325  {
326  adtf_util::cString strValue = oStringValue.Get();
327  return property_type_definition<T>::con_type::FromString(strValue, m_oValue);
328  }
329  };
330 
331  class cPropertyBase : public IProperty
332  {
333  protected:
334  util::cString m_strName = adtf_util::cString();
335  ucom::object_ptr<IProperties> m_poSubProperties = nullptr;
336  ucom::object_ptr<IProperties> m_poAttachedProperties = nullptr;
337 
338  protected:
339  cPropertyBase();
340  virtual ~cPropertyBase() = default;
341 
342  public:
343  tResult GetName(IString&& strName) const override;
344 
345  bool HasProperties() const override;
346  bool HasAttachedProperties() const override;
347 
349  tResult SetProperties(const IProperties& oProperties) override;
350 
352  tResult AttachProperties(const ucom::ant::iobject_ptr<IProperties>& pAttachedProperties) override;
353  tResult GetAttachedProperties(IProperty& oProperty) const override;
354  tResult DetachProperties() override;
355 
357  tResult GetProperties(ucom::ant::iobject_ptr<IProperties>& pSubProperties) override;
359  tResult GetProperties(ucom::ant::iobject_ptr<const IProperties>& pSubProperties) const override;
360 
361  public:
362  tResult SetName(const IString& strName);
363 
364  };
365 
371  template <typename T>
372  class property : public cPropertyBase
373  {
374  private:
377 
378  public:
381  {
382  }
384  ~property() = default;
385 
387  property(const property& oProperty) : property()
388  {
389  Set(oProperty);
390  }
392  property(property&& oProperty)
393  {
394  m_oValue = oProperty.m_oValue;
395  m_strName = oProperty.m_strName;
396  m_poSubProperties = oProperty.m_poSubProperties;
397  oProperty.m_poSubProperties = nullptr;
398  m_poAttachedProperties = oProperty.m_poAttachedProperties;
399  oProperty.m_poAttachedProperties = nullptr;
400  }
402  property& operator=(const property& oValue)
403  {
404  Set(oValue);
405  return *this;
406  }
407 
409  property& operator=(property&& oProperty)
410  {
411  m_oValue = oProperty.m_oValue;
412  m_strName = oProperty.m_strName;
413  m_poSubProperties = oProperty.m_poSubProperties;
414  oProperty.m_poSubProperties = nullptr;
415  m_poAttachedProperties = oProperty.m_poAttachedProperties;
416  oProperty.m_poAttachedProperties = nullptr;
417  return *this;
418  }
419 
425  property(const adtf_util::cString& strName, const T& oValue)
426  {
427  m_strName = strName;
428  m_oValue = oValue;
429  }
434  property(const T& oValue)
435  {
436  m_oValue = oValue;
437  }
442  const property& operator=(const T& oValue)
443  {
444  m_oValue = oValue;
445  return *this;
446  }
447 
454  bool operator==(const property& oProperty) const
455  {
456  return (m_oValue == oProperty);
457  }
458 
465  bool operator==(const T& oValue) const
466  {
467  return (m_oValue == oValue);
468  }
469 
474  T GetValueT() const
475  {
476  return m_oValue.GetValue();
477  }
478 
486  tResult Set(const property& oProperty)
487  {
488  m_oValue = oProperty.m_oValue;
489  m_strName = oProperty.m_strName;
491  oProperty.GetProperties(pSubProperties);
492 
493  //if the subproperties are attached we attach them too
494  //mind : If we there are already set properties in our own m_poSubProperties they are hidden then
495  if (oProperty.HasAttachedProperties())
496  {
497  oProperty.GetAttachedProperties(*this);
498  }
499  else
500  {
501  m_poSubProperties->Set(*pSubProperties.Get());
502  }
503  RETURN_NOERROR;
504  }
505 
506  public:
507  virtual const IPropertyValue* GetValue() const
508  {
509  return static_cast<const IPropertyValue*>(&m_oValue);
510  }
511  virtual IPropertyValue* GetValue()
512  {
513  return static_cast<IPropertyValue*>(&m_oValue);
514  }
515 
516  virtual tResult SetValue(const IPropertyValue& oValue)
517  {
518  return m_oValue.Set(oValue);
519  }
520 
521  tResult Set(const IProperty& oProp)
522  {
523  oProp.GetName(adtf_string_intf(m_strName));
524  m_oValue.Set(*oProp.GetValue());
525 
527  oProp.GetProperties(pSubProperties);
528 
529  //if the the subproperties are attached we attach them too
530  //mind : If we would have set properties already in our own m_poSubProperties they are hidden then
531  if (oProp.HasAttachedProperties())
532  {
533  oProp.GetAttachedProperties(*this);
534  }
535  else
536  {
537  m_poSubProperties->Set(*pSubProperties.Get());
538  }
539  RETURN_NOERROR;
540  }
541  };
542 
543 
544 
545 } //namespace ant
546 
547 namespace elasto
548 {
549 
554 {
555 };
556 
557 }
558 
559 // everything following this is available from elasto onwards only.
560 
561 namespace ant
562 {
563 
564 template<>
566 {
567  constexpr static const tChar* const TYPE_NAME = "tree_node_property";
569 };
570 
571 }
572 
573 // everything following this is available from flash onwards only.
574 
575 namespace ant
576 {
577 
578 template < >
580 {
581  static constexpr const tChar* TYPE_NAME = "tNanoSeconds";
583 };
584 
585 template < >
586 struct property_type_definition<std::string>
587 {
588  static constexpr const tChar* TYPE_NAME = "cString";
590 };
591 
592 
593 }
594 
596 using ant::property;
597 using ant::property_value;
599 
600 } //namespace base
601 } // namespace adtf
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.
Definition: property_intf.h:60
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 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:24
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 SetProperties(const IProperties &oProperties) override
will copy given properties
tResult GetProperties(ucom::ant::iobject_ptr< IProperties > &pSubProperties) override
get subproperties for writing access
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:256
tResult GetType(IString &&strType) const
Retrieves the string for the property value type.
Definition: property.h:303
tResult ToString(IString &&oStringValue) const
Implement to serialize the value to a textfile and/or to show it on a display.
Definition: property.h:317
tResult ToRaw(IRawMemory &&oToMem) const
Implement to create a fast value copy in memory.
Definition: property.h:308
tResult FromString(const IString &oStringValue)
Implement to deserialize the value from a textfile and/or to set by string.
Definition: property.h:324
tResult FromRaw(const IRawMemory &oFromMem)
Implement to create a fast value copy in memory.
Definition: property.h:312
Property property implementation template.
Definition: property.h:373
const property & operator=(const T &oValue)
value assignment
Definition: property.h:442
property(const T &oValue)
CTOR with value.
Definition: property.h:434
property & operator=(property &&oProperty)
move assignment (its not moving yet)
Definition: property.h:409
tResult Set(const property &oProperty)
Sets the property value and name as COPY of oProperty.
Definition: property.h:486
T GetValueT() const
Get the containing value.
Definition: property.h:474
~property()=default
DTOR.
bool operator==(const property &oProperty) const
compare operator
Definition: property.h:454
property_value< T > m_oValue
value type container
Definition: property.h:376
property(const adtf_util::cString &strName, const T &oValue)
CTOR with name an value.
Definition: property.h:425
property(const property &oProperty)
Copy CTOR.
Definition: property.h:387
bool operator==(const T &oValue) const
compare operator
Definition: property.h:465
property & operator=(const property &oValue)
copy assignment
Definition: property.h:402
property(property &&oProperty)
implementation of the move CTOR (but it is not moving yet)
Definition: property.h:392
Base object pointer to realize binary compatible reference counting in interface methods.
Object pointer implementation used for reference counting on objects of type IObject.
Definition: object_ptr.h:158
virtual T * Get() const
Get pointer to shared object.
Definition: object_ptr.h:376
Namespace for entire ADTF SDK.
Copyright © Audi Electronics Venture GmbH.
Copyright © Audi Electronics Venture GmbH.
#define adtf_memory_intf(__utils_memblock__)
This macro will create a rvalue reference with the help of adtf::base::adtf_memory It will only work ...
#define adtf_string_intf(__string__)
The adtf_string_intf Macro helps to easily create a rvalue reference of a adtf::util::cString.
Definition: string_intf.h:285
Conversion type used for adtf::base::ant::property<cFilename> and adtf::base::ant::property<cFilepath...
Conversion type used for adtf::base::ant::property<cFilenameList> and adtf::base::ant::property<cFile...
Conversion type used for property<cString>
Default conversion type used for all build in property types of adtf.
Concept template to define the Name and the conversion type for the given type TYPE.
Definition: property.h:39
Property type that creates a property that functions as a container for subproperties only.
Definition: property.h:554
Conversion type used for property<tNanoSeconds>
Conversion type used for adtf::base::ant::property<std::string>
#define RETURN_IF_FAILED(s)
returns if the expression returns a failed tResult or throws an exception.

Copyright © Audi Electronics Venture GmbH. All rights reserved. (Generated on Tue May 10 2022 by doxygen 1.9.1)