6 #ifndef IFW_CTD_CONVERSION_HPP_
7 #define IFW_CTD_CONVERSION_HPP_
12 #include "ctd/defines/defines.hpp"
13 #include "ctd/string/string.hpp"
17 namespace conversion {
20 template <
class TYPE> std::string
NbToStr(
const TYPE number,
21 const std::string& format =
"") {
24 std::stringstream nb_str;
25 if ((
typeid(number) ==
typeid(uint8_t)) || (
typeid(number) ==
typeid(int8_t))) {
26 nb_str << int(number);
27 }
else if ((
typeid(number) ==
typeid(
float)) || (
typeid(number) ==
typeid(
double))) {
31 strncpy(tmp_format, format.c_str(),
sizeof(tmp_format));
33 strncpy(tmp_format,
"%%.%df",
sizeof(tmp_format));
35 double tmp_dbl =
static_cast<double>(number);
36 snprintf(tmp_buf,
sizeof(tmp_buf), tmp_format, tmp_dbl);
46 const std::string& prec_or_format =
"3");
50 const bool long_format =
true);
54 const bool permissive =
true);
57 template <
class TYPE> std::string
TypeName(TYPE instance) {
60 return typeid(instance).
name();
76 if (m_value != NULL) {
88 typeid(value).
name()), m_name.c_str());
91 typeid(value).
name()));
94 if (
typeid(value) ==
typeid(static_cast<std::string>(
""))) {
95 std::stringstream tmp_str;
97 m_string_value = tmp_str.str();
99 m_value = malloc(
sizeof(TYPE));
100 memcpy(m_value, &value,
sizeof(TYPE));
110 return &m_string_value;
119 std::string m_string_value;
125 Value& native_value);
128 template <
class TYPE>
void Convert(
const std::string& str_value,
129 TYPE& native_value) {
132 std::map<std::string, ctd::defines::DataType>::const_iterator type_it =
138 Value tmp_native_value;
139 Convert(str_value, data_type, tmp_native_value);
140 native_value = *(
static_cast<TYPE*
>(tmp_native_value.GetValue()));
147 #endif // IFW_CTD_CONVERSION_HPP_
double value
Definition: easylogging++.h:814
void Convert(const std::string &value, ctd::defines::DataType data_type, Value &native_value)
Convert a value represented as a string into its 'native type'. Data type given.
Definition: conversion.cpp:52
const std::map< std::string, DataType > & TypeId2DataTypeMap()
Return reference to data types numeric to string map.
Definition: defines.cpp:60
std::string NbToStr(const TYPE number, const std::string &format="")
Convert the given value to a string representation.
Definition: conversion.hpp:20
Definition: defines.hpp:45
std::string BoolToString(const bool value, const bool long_format)
Convert a boolean value to a string (Short format: T/F; Long format: True/False). ...
Definition: conversion.cpp:27
DataType
Data types numeric representations.
Definition: defines.hpp:33
~Value()
Definition: conversion.hpp:73
std::string DblToString(const double value, const std::string &prec_or_format)
Convert a double value to its string representation, applying the given precision.
Definition: conversion.cpp:12
bool Boolean(const std::string &value, const bool permissive)
Interpret a string as a boolean (t/T/true/TRUE -> true; f/F/false/FALSE -> false).
Definition: conversion.cpp:38
Definition: Exceptions.hpp:44
bool SupportedType(const TYPE &variable)
Check if the variable has a data type which is supported by the ELT ICS.
Definition: defines.hpp:183
std::string TypeName(TYPE instance)
Get the typename of the given variable as a string.
Definition: conversion.hpp:57
std::string Print(const char *format,...)
Create formatted string, return formatted string (C formatting convention).
Definition: defines.cpp:71
#define RAD_LOG_TRACE()
Definition: Logger.hpp:319
Value(const std::string &name="")
Definition: conversion.hpp:66
void * GetValue()
Return value as void*. Calling function must cast to the appropriate type.
Definition: conversion.hpp:106
optional string name
Definition: topics.proto:50
void SetValue(const TYPE &value)
Set the internal value.
Definition: conversion.hpp:82