ADTF
Loading...
Searching...
No Matches
propertyconvert.h
Go to the documentation of this file.
1
7#pragma once
8#include "chrono.h"
9#include "property_intf.h"
11#include "string_conversion.h"
12
13#include <string>
14#include <limits>
15
16#ifdef max
17 #undef max
18#endif
19
20namespace adtf
21{
22namespace base
23{
34template<typename TYPE>
36{
37 static tResult Convert(const IPropertyValue& oPropertyType, TYPE& oToValue)
38 {
40 "Unsupported type! Use bool, int8_t, uint8_t, .. float, double or adtf_util::cString."
41 "Otherwise specialize this property_type_conversion template!");
42 return ERR_NOT_IMPL;
43 }
44 static tResult ToString(const adtf_util::cString& oFromValue, TYPE& strToString)
45 {
47 "Unsupported type! Use bool, int8_t, uint8_t, .. float, double or adtf_util::cString."
48 "Otherwise specialize this property_type_conversion template!");
49 return ERR_NOT_IMPL;
50 }
51 static tResult FromString(const adtf_util::cString& strFromString, TYPE& oToValue)
52 {
54 "Unsupported type! Use bool, int8_t, uint8_t, .. float, double or adtf_util::cString."
55 "Otherwise specialize this property_type_conversion template!");
56 return ERR_NOT_IMPL;
57 }
58 static tResult ToRaw(const void* pData, const size_t szDataSize, IRawMemory& oToMem)
59 {
61 "Unsupported type! Use bool, int8_t, uint8_t, .. float, double or adtf_util::cString."
62 "Otherwise specialize this property_type_conversion template!");
63 return ERR_NOT_IMPL;
64 }
65 static tResult FromRaw(const IRawMemory& oFromMem, void* pData, const size_t szDataSize)
66 {
68 "Unsupported type! Use bool, int8_t, uint8_t, .. float, double or adtf_util::cString."
69 "Otherwise specialize this property_type_conversion template!");
70 return ERR_NOT_IMPL;
71 }
72};
73
79{
80 static tResult FromString(const adtf_util::cString& strValue, bool& bValue)
81 {
82 adtf::util::cStringUtil::ToType(strValue, bValue);
84 }
85
86 template<typename T>
87 static tResult FromString(const adtf_util::cString& strValue, T& oValue)
88 {
89 std::string_view strHelper(strValue.GetPtr());
90 if (strHelper.empty())
91 {
92 oValue = T{};
93 }
94 else
95 {
96 try
97 {
98 oValue = string_conversion::to_number<T>(strHelper, 0);
99 }
100 catch (const std::overflow_error&)
101 {
102 if (strHelper.front() != '-')
103 {
104 oValue = std::numeric_limits<T>::max();
105 }
106 else
107 {
108 oValue = std::numeric_limits<T>::lowest();
109 }
110 }
111 catch (const std::exception&)
112 {
113 bool bHelper = false;
114 adtf::util::cStringUtil::ToType(strValue.GetPtr(), bHelper);
115 oValue = static_cast<T>(bHelper);
116 }
117 }
119 }
120
121 static tResult ToString(const bool& oValue, adtf_util::cString& strValue)
122 {
123 strValue.Set(adtf_util::cString::FromType(oValue));
125 }
126
127 template<typename TYPE>
128 static tResult ToString(const TYPE& oValue, adtf_util::cString& strValue)
129 {
130 strValue.Set(string_conversion::to_string(oValue).c_str());
132 }
133
134 static tResult FromString(const adtf_util::cString& strValue, adtf_util::cString& oValue)
135 {
136 oValue.Set(strValue);
138 }
139
140 static tResult ToString(const adtf_util::cString& oValue, adtf_util::cString& strValue)
141 {
142 strValue.Set(oValue);
144 }
145 static tResult ToRaw(const void* pData, const size_t szSizeOfData, IRawMemory& oToMem);
146 static tResult FromRaw(const IRawMemory& oFromMem, void* pData, const size_t szSizeOfData);
147
148 static tResult Convert(const IPropertyValue& oProp, bool& oValue);
149 static tResult Convert(const IPropertyValue& oProp, uint64_t& oValue);
150 static tResult Convert(const IPropertyValue& oProp, int64_t& oValue);
151 static tResult Convert(const IPropertyValue& oProp, uint32_t& oValue);
152 static tResult Convert(const IPropertyValue& oProp, int32_t& oValue);
153 static tResult Convert(const IPropertyValue& oProp, uint16_t& oValue);
154 static tResult Convert(const IPropertyValue& oProp, int16_t& oValue);
155 static tResult Convert(const IPropertyValue& oProp, uint8_t& oValue);
156 static tResult Convert(const IPropertyValue& oProp, int8_t& oValue);
157 static tResult Convert(const IPropertyValue& oProp, float& oValue);
158 static tResult Convert(const IPropertyValue& oProp, double& oValue);
159};
160
167template<typename TYPE>
169{
170 static tResult Convert(const IPropertyValue& oProp, TYPE& oValue)
171 {
172 return cPropertyConvert::Convert(oProp, oValue);
173 }
174
175 static tResult ToString(const TYPE& oValue, adtf_util::cString& strValue)
176 {
177 return cPropertyConvert::ToString(oValue, strValue);
178 }
179
180 static tResult FromString(const adtf_util::cString& strValue, TYPE& oValue)
181 {
182 return cPropertyConvert::FromString(strValue, oValue);
183 }
184
185 static tResult ToRaw(const void* pData, const size_t szSizeOfData, IRawMemory& oToMem)
186 {
187 return cPropertyConvert::ToRaw(pData, szSizeOfData, oToMem);
188 }
189
190 static tResult FromRaw(const IRawMemory& oFromMem, void* pData, const size_t szSizeOfData)
191 {
192 return cPropertyConvert::FromRaw(oFromMem, pData, szSizeOfData);
193 }
194};
195
201{
202 static tResult Convert(const IPropertyValue& oPropertyType, adtf_util::cString& oToValue);
203 static tResult ToString(const adtf_util::cString& oFromValue, adtf_util::cString& strToString);
204 static tResult FromString(const adtf_util::cString& strFromString, adtf_util::cString& oToValue);
205 static tResult ToRaw(const void* pData, const size_t szDataSize, IRawMemory& oToMem);
206 static tResult FromRaw(const IRawMemory& oFromMem, void* pData, const size_t szDataSize);
207};
208
214{
215 static tResult Convert(const IPropertyValue& oProp, adtf_util::cFilename& oValue);
216 static tResult FromString(const adtf_util::cString& oFromValue, adtf_util::cFilename& strToString);
217 static tResult ToString(const adtf_util::cFilename& strFromString, adtf_util::cString& oToValue);
218 static tResult ToRaw(const void* pData, const size_t szSizeOfData, adtf::base::ant::IRawMemory& oToMem);
219 static tResult FromRaw(const IRawMemory& oFromMem, void* pData, const size_t szSizeOfData);
220};
221
227{
228 static tResult Convert(const IPropertyValue& oProp, adtf_util::cFilenameList& oValue);
229 static tResult FromString(const adtf_util::cString& oFromValue, adtf_util::cFilenameList& strToString);
230 static tResult ToString(const adtf_util::cFilenameList& strFromString, adtf_util::cString& oToValue);
231
232 static tResult Convert(const IPropertyValue& oProp, adtf_util::cFilepathList& oValue);
233 static tResult FromString(const adtf_util::cString& oFromValue, adtf_util::cFilepathList& strToString);
234 static tResult ToString(const adtf_util::cFilepathList& strFromString, adtf_util::cString& oToValue);
235
236 static tResult ToRaw(const void* pData, const size_t szSizeOfData, IRawMemory& oToMem);
237 static tResult FromRaw(const IRawMemory& oFromMem, void* pData, const size_t szSizeOfData);
238};
239
244template<typename TYPE>
246{
247 static tResult Convert(const IPropertyValue& /* oPropertyType */, TYPE& oToValue)
248 {
249 oToValue = TYPE();
251 }
252 static tResult ToString(const TYPE& /* oFromValue */, adtf_util::cString& strToString)
253 {
254 strToString.Set("");
256 }
257 static tResult FromString(const adtf_util::cString& /* strFromString */, TYPE& oToValue)
258 {
259 oToValue = TYPE();
261 }
262 static tResult ToRaw(const void* /* pData */, const size_t /* szDataSize */, IRawMemory& /* oToMem */)
263 {
265 }
266 static tResult FromRaw(const IRawMemory& /* oFromMem */, void* /* pData */, const size_t /* szDataSize */)
267 {
269 }
270};
271
277{
278 static tResult Convert(const IPropertyValue& oPropertyType, flash::tNanoSeconds& oToValue);
279 static tResult ToString(const flash::tNanoSeconds& tmNanoSeconds, adtf_util::cString& strToString);
280 static tResult FromString(const adtf_util::cString& strFromString, flash::tNanoSeconds& tmNanoSeconds);
281 static tResult ToRaw(const void* pData, size_t szDataSize, IRawMemory& oToMem);
282 static tResult FromRaw(const IRawMemory& oFromMem, void* pData, size_t szDataSize);
283};
284
290{
291 static tResult Convert(const IPropertyValue& oPropertyType, std::string& oToValue);
292 static tResult ToString(const std::string& strFrom, adtf_util::cString& strToString);
293 static tResult FromString(const adtf_util::cString& strFromString, std::string& strToString);
294 static tResult ToRaw(const void* pData, size_t szDataSize, IRawMemory& oToMem);
295 static tResult FromRaw(const IRawMemory& oFromMem, void* pData, size_t szDataSize);
296};
297
298} // namespace base
299} // namespace adtf
Definition for type traits helper Copyright © Audi Electronics Venture GmbH. All rights reserved.
A_UTILS_NS::cResult tResult
For backwards compatibility and to bring latest version into scope.
Definition result.h:775
#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:61
Definition rawmemory_base.h:23
constexpr bool always_false
helper template to get a always false expression.
Definition adtf_base_type_traits.h:23
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
T to_number(std::string_view value, int base=0)
Definition string_conversion.h:188
Definition propertyconvert.h:214
Definition propertyconvert.h:227
Definition propertyconvert.h:79
Definition propertyconvert.h:277
Definition propertyconvert.h:290
Definition propertyconvert.h:201
A timestamp with nanosecond precision.
Definition chrono.h:23
Definition propertyconvert.h:246
Definition propertyconvert.h:36
Definition propertyconvert.h:169