16 #include <forward_list> 24 #include "commonlib/datatypes/stringhelper.h" 26 BEGIN_NAMESPACE_SERIALIZATION
31 static bool const value =
false;
34 template <
typename T,
size_t N>
37 static bool const value =
true;
40 template <
typename... Args>
43 static bool const value =
true;
46 template <
typename... Args>
49 static bool const value =
true;
52 template <
typename... Args>
55 static bool const value =
true;
58 template <
typename... Args>
61 static bool const value =
true;
67 static bool const value =
false;
70 template <
typename... Args>
73 static bool const value =
true;
76 template <
typename... Args>
79 static bool const value =
true;
82 template <
typename... Args>
85 static bool const value =
true;
88 template <
typename T,
typename T2 =
void>
94 std::string defaultValue =
"";
96 static std::string toString(
const std::string& value)
101 static std::string convertStringToProperType(
const std::string& value)
110 std::string defaultValue =
"";
112 static std::string toString(
const char* value)
117 static std::string convertStringToProperType(
const std::string& value)
126 std::string defaultValue =
"";
128 static std::string toString(
const char* value)
133 static std::string convertStringToProperType(
const std::string& value)
142 bool defaultValue =
false;
144 static std::string toString(
const bool value)
152 static bool convertStringToProperType(
const std::string& value)
154 std::string boolString = value;
155 std::transform(boolString.begin(), boolString.end(), boolString.begin(), [](
char c) {
156 return char(tolower(c));
159 if (boolString ==
"true")
162 if (boolString ==
"false")
166 if (!Mathematics::MathFuncs::areSame(strtod(boolString.c_str(), &pEnd), 0.0) && std::string(pEnd).empty())
173 template <
typename T>
174 struct TypeConverter<T, typename
std::enable_if<std::is_floating_point<T>::value && !is_container<T>::value>::type>
176 T defaultValue = 0.0;
178 static void changeDecimalToCLocale(std::string& value)
180 const auto decPoint = std::use_facet<std::numpunct<char>>(std::locale(setlocale(LC_NUMERIC,
nullptr))).decimal_point();
181 for (
char& c : value)
183 if (c ==
',' || c ==
'.')
191 static std::string toString(
const T& value)
193 std::stringstream ssFloatingPoint;
195 if (std::is_same<T, float>::value)
197 ssFloatingPoint.precision(FLT_DIG);
201 ssFloatingPoint.precision(DBL_DIG);
203 ssFloatingPoint << std::fixed << value;
204 return ssFloatingPoint.str();
207 static T convertStringToProperType(
const std::string& value)
209 std::string tempStr(value);
210 changeDecimalToCLocale(tempStr);
212 if (std::is_same<T, float>::value)
214 return static_cast<T
>(std::stof(tempStr));
218 return static_cast<T
>(std::stod(tempStr));
223 template <
typename T>
224 struct TypeConverter<T, typename
std::enable_if<std::is_signed<T>::value && std::is_integral<T>::value && !is_container<T>::value>::type>
228 static std::string toString(
const T& value)
230 return std::to_string(value);
233 static int64_t convertStringToProperType(
const std::string& value)
235 return std::stoll(value);
239 template <
typename T>
240 struct TypeConverter<T, typename
std::enable_if<std::is_unsigned<T>::value && std::is_integral<T>::value && !is_container<T>::value>::type>
244 static std::string toString(
const T& value)
246 return std::to_string(value);
249 static uint64_t convertStringToProperType(
const std::string& value)
251 return std::stoull(value);
255 template <
typename T,
typename T2 =
void>
258 template <
typename T>
261 static auto begin(
const T& container)
263 return std::begin(container);
266 static auto end(
const T& container)
268 return std::end(container);
272 template <
typename T,
typename T2 =
void>
275 template <
typename T>
278 static auto begin(T& container)
280 return std::begin(container);
283 static auto end(T& container)
285 return std::end(container);
289 template <
typename IteratorCategory,
typename ValueType>
293 using iterator_category = IteratorCategory;
294 using value_type = ValueType;
295 using difference_type = std::ptrdiff_t;
296 using pointer = ValueType*;
297 using reference = ValueType&;
305 template <
class Container>
311 END_NAMESPACE_SERIALIZATION
MathFuncs class implements helper functions for mathematical operations.
XmlException class that inherits from std::exception and is used for exception handling in xml serial...
Definition: type_converter.h:273
Definition: type_converter.h:65
Definition: type_converter.h:290
Definition: type_converter.h:89
Definition: type_converter.h:29
Definition: type_converter.h:301