ADTF
Loading...
Searching...
No Matches
property_helper.h
Go to the documentation of this file.
1
7#pragma once
8
12#include <adtfbase/property.h>
13#include <type_traits>
14
15namespace adtf
16{
17namespace base
18{
19
20namespace spider
21{
22
23tResult visit_property(const ant::IProperties& oProperties,
24 const char* strPropertyName,
25 const std::function<tResult(const IProperty& oProperty)>& fnCallback);
26
27tResult visit_property_by_path(const ant::IProperties& oProperties,
28 const char* strPropertyPathAndName,
29 const std::function<tResult(const IProperty& oProperty)>& fnCallback);
30
31}
32
33namespace ant
34{
35
49template<typename VALUETYPE>
50tResult set_property(IProperties& oProperties, const char* strNameOfValue, VALUETYPE oValue)
51{
52 return oProperties.SetProperty(spider::property<VALUETYPE>(strNameOfValue, oValue));
53}
54
67inline tResult set_property(IProperties& oProperties, const char* strNameOfValue, const char* poValue)
68{
69 return set_property<std::string>(oProperties, strNameOfValue, poValue);
70}
71
84template<typename T>
85T 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
112template<typename VALUETYPE>
113VALUETYPE get_property(const IProperties& oProperties, const char* strNameOfValue)
114{
115 return get_property<VALUETYPE>(oProperties, strNameOfValue, VALUETYPE());
116}
117
118}
119
120namespace hollow
121{
122
130tResult get_property_object_by_path(const IProperties& oProperties, const char* strPropertyPathAndName, ant::IProperty& oProperty);
131
132}
133
134namespace catwo
135{
136
137template <typename VALUETYPE>
138tResult 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
151template <typename T>
152T 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
168template <typename VALUETYPE>
169VALUETYPE get_property_by_path(const IProperties& oProperties, const char* strPathAndName)
170{
171 return get_property_by_path(oProperties, strPathAndName, VALUETYPE());
172}
173
174}
175
176namespace elasto
177{
178
184std::pair<std::string, std::string> split_parents_and_leaf(const char* strPropertyPathAndName);
185
193tResult create_property_tree(ant::IProperties& oProperties, const char* strPath);
194
195}
196
197namespace lucky
198{
199
200namespace detail
201{
202
203template <typename PropertyType>
204void 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
215using tPropertyVisitorCallback = std::function<void(const ant::IProperty& oProperty)>;
216
222void visit_properties(const ant::IProperties& oProperties,
223 tPropertyVisitorCallback fnCallback);
224
231template <typename SubPropertyType>
232void 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
244 tPropertyVisitorCallback fnCallback);
245
252template <typename SubPropertyType>
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
266 const char* strPropertyName,
267 tPropertyVisitorCallback fnCallback);
268
276template <typename SubPropertyType>
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
288namespace spider
289{
290
291using lucky::tPropertyVisitorCallback;
292
298void visit_properties(const ant::IProperties& oProperties,
299 const tPropertyVisitorCallback& fnCallback);
300
307template <typename SubPropertyType>
308void 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
320 const tPropertyVisitorCallback& fnCallback);
321
328template <typename SubPropertyType>
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
342 const char* strPropertyName,
343 const tPropertyVisitorCallback& fnCallback);
344
352template <typename SubPropertyType>
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
367using catwo::set_property_by_path;
368using catwo::get_property_by_path;
374using spider::visit_property;
375using spider::visit_property_by_path;
376
377}
378}
#define IS_FAILED(s)
Check if result is failed.
Definition result.h:20
A_UTILS_NS::cResult tResult
For backwards compatibility and to bring latest version into scope.
Definition result.h:736
#define RETURN_NOERROR
Return status ERR_NOERROR, which requires the calling function's return type to be tResult.
Definition result.h:29
Definition property_intf.h:213
Definition property_intf.h:119
Definition string_intf.h:29
virtual const char * Get() const =0
Definition string_intf.h:398
Definition properties_v2.h:283
Namespace for all functionality of the ADTF Base SDK provided since v3.0.
Definition adtf_class_version.h:16
VALUETYPE get_property(const IConfiguration &oConfiguration, const char *strNameOfValue, VALUETYPE oDefaultValue)
Get the property content converted to the VALUETYPE.
Definition configuration.h:291
tResult set_property(IConfiguration &oConfiguration, const char *strNameOfValue, VALUETYPE oValue)
Set the property.
Definition configuration.h:327
Namespace for all functionality of the ADTF Base SDK provided since v3.4.
Definition error_handling_intf.h:15
tResult create_property_tree(ant::IProperties &oProperties, const char *strPath)
std::pair< std::string, std::string > split_parents_and_leaf(const char *strPropertyPathAndName)
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.
Namespace for all functionality of the ADTF Base SDK provided since v3.18.
Definition properties_v2.h:24
void visit_properties(const ant::IProperties &oProperties, const tPropertyVisitorCallback &fnCallback)
void visit_sub_properties(const ant::IProperty &oProperty, const tPropertyVisitorCallback &fnCallback)
Namespace for the ADTF Base SDK.
Definition adtf_base_type_traits.h:13
Namespace for all functionality provided by ADTF and its SDKs.
Definition adtf_client_connector.h:14
void visit_sub_properties(const ant::IProperty &oProperty, tPropertyVisitorCallback fnCallback)
void visit_properties(const ant::IProperties &oProperties, tPropertyVisitorCallback fnCallback)