ADTF
property_helper.h
Go to the documentation of this file.
1 
7 #pragma once
8 
10 #include <adtfucom3/adtf_ucom3.h>
11 #include <adtfbase/properties_v2.h>
12 #include <adtfbase/property.h>
13 #include <type_traits>
14 
15 namespace adtf
16 {
17 namespace base
18 {
19 
20 namespace spider
21 {
22 
23 tResult visit_property(const ant::IProperties& oProperties,
24  const char* strPropertyName,
25  const std::function<tResult(const IProperty& oProperty)>& fnCallback);
26 
27 tResult visit_property_by_path(const ant::IProperties& oProperties,
28  const char* strPropertyPathAndName,
29  const std::function<tResult(const IProperty& oProperty)>& fnCallback);
30 
31 }
32 
33 namespace ant
34 {
35 
49 template<typename VALUETYPE>
50 tResult set_property(IProperties& oProperties, const char* strNameOfValue, VALUETYPE oValue)
51 {
52  return oProperties.SetProperty(spider::property<VALUETYPE>(strNameOfValue, oValue));
53 }
54 
67 inline tResult set_property(IProperties& oProperties, const char* strNameOfValue, const char* poValue)
68 {
69  return set_property<std::string>(oProperties, strNameOfValue, poValue);
70 }
71 
84 template<typename T>
85 T get_property(const IProperties& oProperties, const char* strNameOfValue, const T& oDefaultValue)
86 {
87  T oFoundValue;
88 
89  if (IS_FAILED(spider::visit_property(oProperties, strNameOfValue, [&](const IProperty& oProperty) -> tResult
90  {
91  RETURN_IF_FAILED(get_property_value(*oProperty.GetValue(), oFoundValue));
93  })))
94  {
95  return oDefaultValue;
96  }
97 
98  return oFoundValue;
99 }
100 
112 template<typename VALUETYPE>
113 VALUETYPE get_property(const IProperties& oProperties, const char* strNameOfValue)
114 {
115  return get_property<VALUETYPE>(oProperties, strNameOfValue, VALUETYPE());
116 }
117 
118 }
119 
120 namespace hollow
121 {
122 
130 tResult get_property_object_by_path(const IProperties& oProperties, const char* strPropertyPathAndName, ant::IProperty& oProperty);
131 
132 }
133 
134 namespace catwo
135 {
136 
137 template <typename VALUETYPE>
138 tResult set_property_by_path(IProperties& oProperties, const char* strPathAndName, VALUETYPE oValue)
139 {
140  util::cString strHelper(strPathAndName);
141  size_t nLastSlashPosition = strHelper.RFind('/');
142  if (nLastSlashPosition == util::cString::InvalidPos)
143  {
144  return ant::set_property<VALUETYPE>(oProperties, strPathAndName, oValue);
145  }
146 
147  util::cString strParent = strHelper.Mid(0, nLastSlashPosition);
148  return oProperties.SetPropertyByPath(strParent, property<VALUETYPE>(strHelper.Mid(nLastSlashPosition + 1), oValue));
149 }
150 
151 template <typename T>
152 T get_property_by_path(const IProperties& oProperties, const char* strPathAndName, const T& oDefaultValue)
153 {
154  T oFoundValue;
155 
156  if (IS_FAILED(spider::visit_property_by_path(oProperties, strPathAndName, [&](const IProperty& oProperty) -> tResult
157  {
158  RETURN_IF_FAILED(get_property_value(*oProperty.GetValue(), oFoundValue));
160  })))
161  {
162  return oDefaultValue;
163  }
164 
165  return oFoundValue;
166 }
167 
168 template <typename VALUETYPE>
169 VALUETYPE get_property_by_path(const IProperties& oProperties, const char* strPathAndName)
170 {
171  return get_property_by_path(oProperties, strPathAndName, VALUETYPE());
172 }
173 
174 }
175 
176 namespace elasto
177 {
178 
184 std::pair<std::string, std::string> split_parents_and_leaf(const char* strPropertyPathAndName);
185 
193 tResult create_property_tree(ant::IProperties& oProperties, const char* strPath);
194 
195 }
196 
197 namespace lucky
198 {
199 
200 namespace detail
201 {
202 
203 template <typename PropertyType>
204 void call_callback(const ant::IProperty& oProperty, const std::function<void(const char*, PropertyType)>& fnCallback)
205 {
206  oProperty.GetName(cStringRedirect([&](const IString& strName)
207  {
208  fnCallback(strName.Get(), get_property_value<std::decay_t<PropertyType>>(*oProperty.GetValue()));
210  }));
211 }
212 
213 }
214 
215 using tPropertyVisitorCallback = std::function<void(const ant::IProperty& oProperty)>;
216 
222 void visit_properties(const ant::IProperties& oProperties,
223  tPropertyVisitorCallback fnCallback);
224 
231 template <typename SubPropertyType>
232 void visit_properties(const ant::IProperties& oProperties,
233  std::function<void(const char*, SubPropertyType)> fnCallback)
234 {
235  visit_properties(oProperties, std::bind(detail::call_callback<SubPropertyType>, std::placeholders::_1, fnCallback));
236 }
237 
243 void visit_sub_properties(const ant::IProperty& oProperty,
244  tPropertyVisitorCallback fnCallback);
245 
252 template <typename SubPropertyType>
253 void visit_sub_properties(const ant::IProperty& oProperty,
254  std::function<void(const char*, SubPropertyType)> fnCallback)
255 {
256  visit_sub_properties(oProperty, std::bind(detail::call_callback<SubPropertyType>, std::placeholders::_1, fnCallback));
257 }
258 
265 void visit_sub_properties(const ant::IProperties& oProperties,
266  const char* strPropertyName,
267  tPropertyVisitorCallback fnCallback);
268 
276 template <typename SubPropertyType>
277 void visit_sub_properties(const ant::IProperties& oProperties,
278  const char* strPropertyName,
279  std::function<void(const char*, SubPropertyType)> fnCallback)
280 {
281  visit_sub_properties(oProperties,
282  strPropertyName,
283  std::bind(detail::call_callback<SubPropertyType>, std::placeholders::_1, fnCallback));
284 }
285 
286 }
287 
288 namespace spider
289 {
290 
291 using lucky::tPropertyVisitorCallback;
292 
298 void visit_properties(const ant::IProperties& oProperties,
299  const tPropertyVisitorCallback& fnCallback);
300 
307 template <typename SubPropertyType>
308 void visit_properties(const ant::IProperties& oProperties,
309  const std::function<void(const char*, SubPropertyType)>& fnCallback)
310 {
311  visit_properties(oProperties, std::bind(lucky::detail::call_callback<SubPropertyType>, std::placeholders::_1, fnCallback));
312 }
313 
319 void visit_sub_properties(const ant::IProperty& oProperty,
320  const tPropertyVisitorCallback& fnCallback);
321 
328 template <typename SubPropertyType>
329 void visit_sub_properties(const ant::IProperty& oProperty,
330  const std::function<void(const char*, SubPropertyType)>& fnCallback)
331 {
332  visit_sub_properties(oProperty, std::bind(lucky::detail::call_callback<SubPropertyType>, std::placeholders::_1, fnCallback));
333 }
334 
341 void visit_sub_properties(const ant::IProperties& oProperties,
342  const char* strPropertyName,
343  const tPropertyVisitorCallback& fnCallback);
344 
352 template <typename SubPropertyType>
353 void visit_sub_properties(const ant::IProperties& oProperties,
354  const char* strPropertyName,
355  const std::function<void(const char*, SubPropertyType)>& fnCallback)
356 {
357  visit_sub_properties(oProperties,
358  strPropertyName,
359  std::bind(lucky::detail::call_callback<SubPropertyType>, std::placeholders::_1, fnCallback));
360 }
361 
362 }
363 
364 
365 using ant::set_property;
366 using ant::get_property;
367 using catwo::set_property_by_path;
368 using catwo::get_property_by_path;
374 using spider::visit_property;
375 using spider::visit_property_by_path;
376 
377 }
378 }
Copyright © Audi Electronics Venture GmbH.
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.
_myType Mid(tSize nPos, tSize nLength=InvalidPos) const
This function extracts a substring of length nLength characters from the cStringA object,...
Definition: string.h:1421
Defintion of a property set container interface.
The IProperty interface provides methods for getting and setting property values, name of the propert...
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.
string_base< cStackString > cString
cString implementation for a stack string which works on stack if string is lower than A_UTILS_DEFAUL...
Definition: string.h:2784
VALUETYPE get_property(const IConfiguration &oConfiguration, const char *strNameOfValue, VALUETYPE oDefaultValue)
Get the property content converted to the VALUETYPE.
tResult set_property(IConfiguration &oConfiguration, const char *strNameOfValue, VALUETYPE oValue)
Set the property.
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.
tResult get_property_object_by_path(const ant::IConfiguration &oConfiguration, const char *strPropertyPathAndName, ant::IProperty &oProperty)
Retrieves a property reference under the given oConfiguration by path.
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.
void visit_properties(const ant::IProperties &oProperties, const tPropertyVisitorCallback &fnCallback)
Utility function to visit all properties of a properties object.
void visit_sub_properties(const ant::IProperty &oProperty, const tPropertyVisitorCallback &fnCallback)
Utility function to visit all sub-properties of a given property.
Namespace for entire ADTF SDK.
Copyright © Audi Electronics Venture GmbH.
Copyright © Audi Electronics Venture GmbH.
Copyright © Audi Electronics Venture GmbH.