ADTF  3.18.2
propertyconvert.h
Go to the documentation of this file.
1 
7 #pragma once
8 #include "chrono.h"
9 #include "property_intf.h"
10 #include "adtf_base_type_traits.h"
11 #include "string_conversion.h"
12 
13 #include <string>
14 #include <limits>
15 
16 #ifdef max
17 #undef max
18 #endif
19 
20 //****************************************************************************************************//
21 //****************************************************************************************************//
22 namespace adtf
23 {
24 namespace base
25 {
26 namespace ant
27 {
38  template <typename TYPE>
40  {
41  static tResult Convert(const IPropertyValue& oPropertyType, TYPE& oToValue)
42  {
43  static_assert(adtf::base::penguin::detail::always_false<TYPE>, "Unsupported type! Use bool, int8_t, uint8_t, .. float, double or adtf_util::cString."
44  "Otherwise specialize this property_type_conversion template!");
45  return ERR_NOT_IMPL;
46  }
47  static tResult ToString(const adtf_util::cString& oFromValue, TYPE& strToString)
48  {
49  static_assert(adtf::base::penguin::detail::always_false<TYPE>, "Unsupported type! Use bool, int8_t, uint8_t, .. float, double or adtf_util::cString."
50  "Otherwise specialize this property_type_conversion template!");
51  return ERR_NOT_IMPL;
52  }
53  static tResult FromString(const adtf_util::cString& strFromString, TYPE& oToValue)
54  {
55  static_assert(adtf::base::penguin::detail::always_false<TYPE>, "Unsupported type! Use bool, int8_t, uint8_t, .. float, double or adtf_util::cString."
56  "Otherwise specialize this property_type_conversion template!");
57  return ERR_NOT_IMPL;
58  }
59  static tResult ToRaw(const void* pData, const size_t szDataSize, IRawMemory& oToMem)
60  {
61  static_assert(adtf::base::penguin::detail::always_false<TYPE>, "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  {
67  static_assert(adtf::base::penguin::detail::always_false<TYPE>, "Unsupported type! Use bool, int8_t, uint8_t, .. float, double or adtf_util::cString."
68  "Otherwise specialize this property_type_conversion template!");
69  return ERR_NOT_IMPL;
70  }
71  };
72 
78  {
79  static tResult FromString(const adtf_util::cString& strValue, bool& bValue)
80  {
81  adtf::util::cStringUtil::ToType(strValue, bValue);
83  }
84 
85  template <typename T>
86  static tResult FromString(const adtf_util::cString& strValue, T& oValue)
87  {
88  std::string_view strHelper(strValue.GetPtr());
89  if (strHelper.empty())
90  {
91  oValue = T{};
92  }
93  else
94  {
95  try
96  {
97  oValue = string_conversion::to_number<T>(strHelper, 0);
98  }
99  catch (const std::overflow_error&)
100  {
101  if (strHelper.front() != '-')
102  {
103  oValue = std::numeric_limits<T>::max();
104  }
105  else
106  {
107  oValue = std::numeric_limits<T>::lowest();
108  }
109  }
110  catch (const std::exception&)
111  {
112  bool bHelper = false;
113  adtf::util::cStringUtil::ToType(strValue.GetPtr(), bHelper);
114  oValue = static_cast<T>(bHelper);
115  }
116  }
118  }
119 
120  static tResult ToString(const bool& oValue, adtf_util::cString& strValue)
121  {
122  strValue.Set(adtf_util::cString::FromType(oValue));
124  }
125 
126  template <typename TYPE>
127  static tResult ToString(const TYPE& oValue, adtf_util::cString& strValue)
128  {
129  strValue.Set(string_conversion::to_string(oValue).c_str());
131  }
132 
133  static tResult FromString(const adtf_util::cString& strValue, adtf_util::cString& oValue)
134  {
135  oValue.Set(strValue);
137  }
138 
139  static tResult ToString(const adtf_util::cString& oValue, adtf_util::cString& strValue)
140  {
141  strValue.Set(oValue);
143  }
144  static tResult ToRaw(const void* pData, const size_t szSizeOfData, IRawMemory& oToMem);
145  static tResult FromRaw(const IRawMemory& oFromMem, void* pData, const size_t szSizeOfData);
146 
147  static tResult Convert(const IPropertyValue& oProp, bool& oValue);
148  static tResult Convert(const IPropertyValue& oProp, uint64_t& oValue);
149  static tResult Convert(const IPropertyValue& oProp, int64_t& oValue);
150  static tResult Convert(const IPropertyValue& oProp, uint32_t& oValue);
151  static tResult Convert(const IPropertyValue& oProp, int32_t& oValue);
152  static tResult Convert(const IPropertyValue& oProp, uint16_t& oValue);
153  static tResult Convert(const IPropertyValue& oProp, int16_t& oValue);
154  static tResult Convert(const IPropertyValue& oProp, uint8_t& oValue);
155  static tResult Convert(const IPropertyValue& oProp, int8_t& oValue);
156  static tResult Convert(const IPropertyValue& oProp, float& oValue);
157  static tResult Convert(const IPropertyValue& oProp, double& oValue);
158  };
159 
166  template <typename TYPE>
168  {
169  static tResult Convert(const IPropertyValue& oProp, TYPE& oValue)
170  {
171  return cPropertyConvert::Convert(oProp, oValue);
172  }
173 
174  static tResult ToString(const TYPE& oValue, adtf_util::cString& strValue)
175  {
176  return cPropertyConvert::ToString(oValue, strValue);
177  }
178 
179  static tResult FromString(const adtf_util::cString& strValue, TYPE& oValue)
180  {
181  return cPropertyConvert::FromString(strValue, oValue);
182  }
183 
184  static tResult ToRaw(const void* pData, const size_t szSizeOfData, IRawMemory& oToMem)
185  {
186  return cPropertyConvert::ToRaw(pData, szSizeOfData, oToMem);
187  }
188 
189  static tResult FromRaw(const IRawMemory& oFromMem, void* pData, const size_t szSizeOfData)
190  {
191  return cPropertyConvert::FromRaw(oFromMem, pData, szSizeOfData);
192  }
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 
244  template <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 
272 } //ant
273 
274 namespace flash
275 {
276 
282 {
283  static tResult Convert(const IPropertyValue& oPropertyType, flash::tNanoSeconds& oToValue);
284  static tResult ToString(const flash::tNanoSeconds& tmNanoSeconds, adtf_util::cString& strToString);
285  static tResult FromString(const adtf_util::cString& strFromString, flash::tNanoSeconds& tmNanoSeconds);
286  static tResult ToRaw(const void* pData, size_t szDataSize, IRawMemory& oToMem);
287  static tResult FromRaw(const IRawMemory& oFromMem, void* pData, size_t szDataSize);
288 };
289 
295 {
296  static tResult Convert(const IPropertyValue& oPropertyType, std::string& oToValue);
297  static tResult ToString(const std::string& strFrom, adtf_util::cString& strToString);
298  static tResult FromString(const adtf_util::cString& strFromString, std::string& strToString);
299  static tResult ToRaw(const void* pData, size_t szDataSize, IRawMemory& oToMem);
300  static tResult FromRaw(const IRawMemory& oFromMem, void* pData, size_t szDataSize);
301 };
302 
303 }
304 
308 
309 } //base
310 } //adtf
311 
312 
313 
314 
315 //*************************************************************************************************
316 
#define RETURN_NOERROR
Return status ERR_NOERROR, which requires the calling function's return type to be tResult.
The IPropertyValue interface provides methods for getting and setting property values.
Definition: property_intf.h:60
The IRawMemory interface provides methods for getting and setting memory values through abstract inte...
cString to_string(const tResult &i_oResult, eResultFormatFlags i_eFormatFlags=eResultFormatFlags::RFF_DisableNone, const tChar *i_strFormat=nullptr)
Copy all information of an assigned result object to a (formatted) 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:2778
Namespace for entire ADTF SDK.
Copyright © Audi Electronics Venture GmbH.
Copyright © Audi Electronics Venture GmbH.
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...
Adtf build in conversion type implementation used by property_type_default_conversion.
Conversion type used for property<cString>
Concept template to define the conversion type for the given type TYPE of a property.
Default conversion type used for all build in property types of adtf.
Conversion type used for property<tNanoSeconds>
Conversion type used for adtf::base::ant::property<std::string>
Public API for compatibility to C++11 <chrono>