47 #ifndef _MIRA_TOSTRING_H_ 48 #define _MIRA_TOSTRING_H_ 50 #include <boost/algorithm/string/predicate.hpp> 69 inline std::string genericToString(
const T& value,
int precision)
76 MIRA_THROW(XIO,
"Failed to convert value into a string");
82 inline std::string fpToString(
const T& value,
int precision)
84 if(boost::math::isnan(value))
86 else if(boost::math::isinf(value)) {
93 return genericToString<T>(value,
precision);
98 inline std::string charToString(
const T& value)
100 return genericToString<int>((int)value, 0);
114 template <
typename T>
119 operator T()
const {
return value; }
120 friend std::ostream& operator<<(std::ostream& oStream, const ToHex<T>& iValue)
122 oStream << std::hex << iValue.value;
135 template <
typename T>
140 operator T()
const {
return value; }
141 friend std::ostream& operator<<(std::ostream& oStream, const ToOct<T>& iValue)
143 oStream << std::oct << iValue.value;
157 template <
typename T>
160 return Private::genericToString<T>(value,
precision);
167 return Private::charToString<char>(value);
175 return Private::charToString<signed char>(value);
183 return Private::charToString<unsigned char>(value);
188 inline std::string toString<std::string>(
const std::string& value,
198 return Private::fpToString<float>(value,
precision);
205 return Private::fpToString<double>(value,
precision);
213 return Private::fpToString<long double>(value,
precision);
std::string toString< bool >(const bool &value, int precision)
Specialization for bool.
Definition: ToString.h:218
T value
Definition: ToString.h:126
Includes often needed math headers and methods and provides additional constants. ...
specialize cv::DataType for our ImgPixel and inherit from cv::DataType<Vec>
Definition: IOService.h:67
Can be used with toString to convert values to their string hex representation.
Definition: ToString.h:115
std::string toString< long double >(const long double &value, int precision)
Specialization for long double.
Definition: ToString.h:210
#define MIRA_THROW(ex, msg)
Macro for throwing an exception.
Definition: Exception.h:78
Definitions used by fromString/toString conversion.
std::string toString(const T &value, int precision=-1)
Converts any data type to string (the data type must support the stream << operator).
Definition: ToString.h:158
ToOct(T v)
Definition: ToString.h:139
static constexpr auto MIRA_TOSTRING_POSITIVE_INF
Definition: FromToStringConstants.h:55
std::string toString< unsigned char >(const unsigned char &value, int precision)
Specialization for unsigned char.
Definition: ToString.h:180
Commonly used exception classes.
std::string toString< signed char >(const signed char &value, int precision)
Specialization for signed char.
Definition: ToString.h:172
static constexpr auto MIRA_TOSTRING_NEGATIVE_INF
Definition: FromToStringConstants.h:56
ToHex(T v)
Definition: ToString.h:118
std::string toString< float >(const float &value, int precision)
Specialization for float.
Definition: ToString.h:196
Can be used with toString to convert values to their string oct representation.
Definition: ToString.h:136
std::string toString< char >(const char &value, int precision)
Specialization for char.
Definition: ToString.h:165
PropertyHint precision(int p)
Sets the attribute "precision".
Definition: PropertyHint.h:286
static constexpr auto MIRA_TOSTRING_NAN
Definition: FromToStringConstants.h:54
std::string toString< double >(const double &value, int precision)
Specialization for double.
Definition: ToString.h:203
T value
Definition: ToString.h:147