ADTF  3.14.3
properties.h
Go to the documentation of this file.
1 
7 #pragma once
8 #include "property.h"
9 
10 #include <adtfbase/property_intf.h>
11 #include <adtfucom3/adtf_ucom3.h>
12 
13 namespace adtf
14 {
15 namespace base
16 {
17 namespace ant
18 {
24  class cPropertiesBase : public ucom::catwo::object<IProperties>
25  {
28  public:
32  virtual ~cPropertiesBase();
41  cPropertiesBase(const IProperties& oIPropy);
45 
46  private:
48  cPropertiesBase(cPropertiesBase&& oPropy) = delete;
51 
52  public: //implement IProperties
53  bool Exists(const char* strName) const override;
54  tResult Get(IProperties& pProperties) const override;
55  tResult Set(const IProperties& pProperties) override;
56 
57  size_t GetSize() const override;
58 
59  tResult GetProperty(const char* strName, IProperty& pProperty) const override;
60  tResult SetProperty(const IProperty& pProperty) override;
61  tResult SetPropertyByPath(const char* strParentPath, const IProperty& pProperty) override;
62 
63  tResult RemoveProperty(const char* strName) override;
64 
65  public: //Simple Access
71  bool IsEqual(const IProperties& oProperties) const;
72 
73  public:
74  tResult RegisterPropertyObserver(const char* strPropertyName, IPropertyObserver& oObserver);
75  tResult UnregisterPropertyObserver(IPropertyObserver& oObserver);
76 
77  public:
86  cPropertiesBase& CreateProperty(const char* strName, const ant::IPropertyValue& oValue);
87  };
88 
93  {
94  public:
98  virtual ~cProperties();
101  cProperties(const cProperties& oPropy);
107  cProperties(const IProperties& oIPropy);
111 
112  private:
114  cProperties(cProperties&& oPropy) = delete;
116  cProperties& operator=(cProperties&& oPropy) = delete;
117  };
118 
123  public ucom::catwo::object<IProperties>
124  {
125  public:
126  bool Exists(const char* /* strName */) const override
127  {
128  return false;
129  }
130 
131  tResult GetProperty(const char* /* strName */, IProperty& /* oProperty */) const override
132  {
133  RETURN_ERROR(ERR_NOT_IMPL);
134  }
135 
136  //this needs to overwrite
137  tResult SetProperty(const IProperty& /* oProperty */) = 0;
138 
139  tResult SetPropertyByPath(const char* /* strParentPath */, const IProperty& /* pProperty */) override
140  {
141  RETURN_ERROR(ERR_NOT_IMPL);
142  }
143 
144  tResult Set(const IProperties& /* oProperties */ ) override
145  {
146  RETURN_ERROR(ERR_NOT_IMPL);
147  }
148 
149  tResult Get(IProperties& /* oProperties */ ) const override
150  {
151  RETURN_ERROR(ERR_NOT_IMPL);
152  }
153 
154  size_t GetSize() const override
155  {
156  return 0;
157  }
158 
159  tResult RemoveProperty(const char* /* strName */ ) override
160  {
161  RETURN_ERROR(ERR_NOT_IMPL);
162  }
163 
164  tResult RegisterPropertyObserver(const char* /* strPropertyName */,
165  IPropertyObserver& /* oObserver */) override
166  {
167  RETURN_ERROR(ERR_NOT_IMPL);
168  }
169 
170  tResult UnregisterPropertyObserver(IPropertyObserver& /* oObserver */) override
171  {
172  RETURN_ERROR(ERR_NOT_IMPL);
173  }
174  };
175 
189  template<typename VALUETYPE>
190  tResult set_property(IProperties& oProperties, const char* strNameOfValue, VALUETYPE oValue)
191  {
192  return oProperties.SetProperty(property<VALUETYPE>(strNameOfValue, oValue));
193  }
194 
207  inline tResult set_property(IProperties& oProperties, const char* strNameOfValue, const char* poValue)
208  {
209  return set_property<adtf_util::cString>(oProperties, strNameOfValue, adtf_util::cString(poValue));
210  }
211 
224  template<typename VALUETYPE>
225  VALUETYPE get_property(const IProperties& oProperties, const char* strNameOfValue, VALUETYPE oDefaultValue)
226  {
227  property<VALUETYPE> oValue = oDefaultValue;
228  if (oProperties.Exists(strNameOfValue))
229  {
230  oProperties.GetProperty(strNameOfValue, oValue);
231  }
232  return oValue.GetValueT();
233  }
234 
246  template<typename VALUETYPE>
247  VALUETYPE get_property(const IProperties& oProperties, const char* strNameOfValue)
248  {
249  return get_property<VALUETYPE>(oProperties, strNameOfValue, VALUETYPE());
250  }
251 } //namespace ant
252 
253 namespace hollow
254 {
255 
263 tResult get_property_object_by_path(const IProperties& oProperties, const char* strPropertyPathAndName, ant::IProperty& oProperty);
264 
265 }
266 
267 namespace catwo
268 {
269 
270 template <typename VALUETYPE>
271 tResult set_property_by_path(IProperties& oProperties, const char* strPathAndName, VALUETYPE oValue)
272 {
273  util::cString strHelper(strPathAndName);
274  size_t nLastSlashPosition = strHelper.RFind('/');
275  if (nLastSlashPosition == util::cString::InvalidPos)
276  {
277  return ant::set_property<VALUETYPE>(oProperties, strPathAndName, oValue);
278  }
279 
280  util::cString strParent = strHelper.Mid(0, nLastSlashPosition);
281  return oProperties.SetPropertyByPath(strParent, property<VALUETYPE>(strHelper.Mid(nLastSlashPosition + 1), oValue));
282 }
283 
284 template <typename VALUETYPE>
285 VALUETYPE get_property_by_path(const IProperties& oProperties, const char* strPathAndName, VALUETYPE oDefaultValue)
286 {
287  property<VALUETYPE> oProperty;
288  if (IS_FAILED(hollow::get_property_object_by_path(oProperties, strPathAndName, oProperty)))
289  {
290  return oDefaultValue;
291  }
292 
293  return oProperty.GetValueT();
294 }
295 
296 template <typename VALUETYPE>
297 VALUETYPE get_property_by_path(const IProperties& oProperties, const char* strPathAndName)
298 {
299  return get_property_by_path(oProperties, strPathAndName, VALUETYPE());
300 }
301 
302 }
303 
304 namespace elasto
305 {
306 
312 std::pair<std::string, std::string> split_parents_and_leaf(const char* strPropertyPathAndName);
313 
321 tResult create_property_tree(ant::IProperties& oProperties, const char* strPath);
322 
323 }
324 
325 namespace lucky
326 {
327 
328 namespace detail
329 {
330 
331 template <typename PropertyType>
332 void call_callback(const ant::IProperty& oProperty, std::function<void(const char*, PropertyType)> fnCallback)
333 {
334  std::string strName;
335  oProperty.GetName(adtf_string_intf(strName));
337  oValue.Set(*oProperty.GetValue());
338  fnCallback(strName.c_str(), oValue.GetValue());
339 }
340 
341 }
342 
343 using tPropertyVisitorCallback = std::function<void(const ant::IProperty& oProperty)>;
344 
350 void visit_properties(const ant::IProperties& oProperties,
351  tPropertyVisitorCallback fnCallback);
352 
359 template <typename SubPropertyType>
360 void visit_properties(const ant::IProperties& oProperties,
361  std::function<void(const char*, SubPropertyType)> fnCallback)
362 {
363  visit_properties(oProperties, std::bind(detail::call_callback<SubPropertyType>, std::placeholders::_1, fnCallback));
364 }
365 
371 void visit_sub_properties(const ant::IProperty& oProperty,
372  tPropertyVisitorCallback fnCallback);
373 
380 template <typename SubPropertyType>
381 void visit_sub_properties(const ant::IProperty& oProperty,
382  std::function<void(const char*, SubPropertyType)> fnCallback)
383 {
384  visit_sub_properties(oProperty, std::bind(detail::call_callback<SubPropertyType>, std::placeholders::_1, fnCallback));
385 }
386 
393 void visit_sub_properties(const ant::IProperties& oProperties,
394  const char* strPropertyName,
395  tPropertyVisitorCallback fnCallback);
396 
404 template <typename SubPropertyType>
405 void visit_sub_properties(const ant::IProperties& oProperties,
406  const char* strPropertyName,
407  std::function<void(const char*, SubPropertyType)> fnCallback)
408 {
409  visit_sub_properties(oProperties,
410  strPropertyName,
411  std::bind(detail::call_callback<SubPropertyType>, std::placeholders::_1, fnCallback));
412 }
413 
414 }
415 
416 using ant::cPropertiesHelper;
417 using ant::set_property;
418 using ant::get_property;
419 using ant::cProperties;
420 using catwo::set_property_by_path;
421 using catwo::get_property_by_path;
422 using hollow::get_property_object_by_path;
427 
428 } //namespace base
429 } // namespace adtf
Copyright © Audi Electronics Venture GmbH.
Defintion of a property set container interface.
virtual bool Exists(const char *strName) const =0
Checks if property exists by name.
virtual tResult GetProperty(const char *strName, IProperty &pProperty) const =0
Find a property and set the content to the pProperty.
The IProperty interface provides methods for getting and setting property values, name of the propert...
Observer Interface to react on property changes.
The IPropertyValue interface provides methods for getting and setting property values.
Definition: property_intf.h:60
Base class for basic implementation of a IProperties interface.
Definition: properties.h:25
cPropertiesBase(const cPropertiesBase &oPropy)
copy CTOR
cPropertiesBase & operator=(const cPropertiesBase &oPropy)
copy assignment
cPropertiesBase & operator=(cPropertiesBase &&oPropy)=delete
no move
cPropertiesBase(cPropertiesBase &&oPropy)=delete
no move
cPropertiesBase & operator=(const IProperties &oIPropy)
copy asignment
bool IsEqual(const IProperties &oProperties) const
compares the content of the current storage with the given oProperties
cPropertiesBase & CreateProperty(const char *strName, const ant::IPropertyValue &oValue)
Adds a new property and returns a reference to the sub-properties object.
cPropertiesBase(const IProperties &oIPropy)
copy CTOR tfrom interface value
A_UTILS_D(cPropertiesBase)
dptr impl
Helper to create a copy.
Definition: properties.h:124
Property Store as IObject.
Definition: properties.h:93
cProperties & operator=(const cProperties &oPropy)
assinment operator
cProperties(const IProperties &oIPropy)
copy CTOR
cProperties(cProperties &&oPropy)=delete
no move
cProperties(const cProperties &oPropy)
copy CTOR
cProperties & operator=(cProperties &&oPropy)=delete
no move
cProperties & operator=(const IProperties &oIPropy)
assinment operator
tResult Set(const IPropertyValue &oValue)
Sets the value by a deep copy.
Definition: property.h:256
Property property implementation template.
Definition: property.h:373
T GetValueT() const
Get the containing value.
Definition: property.h:474
Use this template if you want to implement an ucom::ant::IObject based Interface and/or subclass an e...
Definition: object.h:359
tResult create_property_tree(ant::IProperties &oProperties, const char *strPath)
Creates a property tree structure.
std::pair< std::string, std::string > split_parents_and_leaf(const char *strPropertyPathAndName)
Splits a property path into the parent path and the property name.
void visit_sub_properties(const ant::IProperty &oProperty, tPropertyVisitorCallback fnCallback)
Utility function to visit all sub-properties of a given property.
void visit_properties(const ant::IProperties &oProperties, tPropertyVisitorCallback fnCallback)
Utility function to visit all properties of a properties object.
Namespace for entire ADTF SDK.
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.
Definition: string_intf.h:285

Copyright © Audi Electronics Venture GmbH. All rights reserved. (Generated on Thu Jun 9 2022 by doxygen 1.9.1)