21 namespace illumina {
namespace interop {
namespace util
27 template<
class Source,
class Destination>
34 template<
class Destination>
42 static Destination
cast(
const std::string &str)
44 if (is_nan(str, static_cast<Destination*>(0)))
46 return nan_value(static_cast<Destination*>(0));
48 if(is_inf(str, static_cast<Destination*>(0)))
50 return inf_value(static_cast<Destination*>(0));
52 std::istringstream iss(str);
53 Destination val = Destination();
59 static double nan_value(
double*)
61 return std::numeric_limits<double>::quiet_NaN();
63 static float nan_value(
float*)
65 return std::numeric_limits<float>::quiet_NaN();
67 static Destination nan_value(
void*)
71 static bool is_nan(
const std::string &str,
double*)
73 return is_string_nan(str);
75 static bool is_nan(
const std::string &str,
float*)
77 return is_string_nan(str);
79 static bool is_nan(
const std::string&,
void*)
83 static bool is_string_nan(
const std::string &str)
85 const size_t n = str.length();
92 static double inf_value(
double*)
94 return std::numeric_limits<double>::infinity();
96 static float inf_value(
float*)
98 return std::numeric_limits<float>::infinity();
100 static Destination inf_value(
void*)
102 return Destination();
104 static bool is_inf(
const std::string &str,
double*)
106 return is_string_inf(str);
108 static bool is_inf(
const std::string &str,
float*)
110 return is_string_inf(str);
112 static bool is_inf(
const std::string&,
void*)
116 static bool is_string_inf(
const std::string &str)
118 const size_t n = str.length();
131 template<
class Destination>
139 static Destination
cast(
const char *str)
149 template<
class Destination>
157 static Destination
cast(
const char *str)
167 template<
class Source>
175 static std::string
cast(
const Source &source)
177 std::ostringstream oss;
187 template<
class Source>
202 static const std::string &
cast(
const std::string &source)
218 static std::string
cast(
const char *source)
220 return std::string(source);
234 static std::string
cast(
const char *source)
236 return std::string(source);
250 static const char *
cast(
const std::string &source)
252 return source.c_str();
263 template<
class Destination,
class Source>
278 inline std::string
format(
const float val,
const int width,
const int precision,
const char fill =
' ',
279 const bool fixed =
true)
281 std::ostringstream oss;
284 oss << std::numeric_limits<float>::quiet_NaN();
287 if (fixed) oss << std::fixed;
288 if (width > -1) oss << std::setw(width);
289 if (precision > -1) oss << std::setprecision(precision);
290 if (fill != 0) oss << std::setfill(fill);
static Destination cast(const std::string &str)
Definition: lexical_cast.h:42
Definition: enum_description.h:15
Definition: lexical_cast.h:168
static const std::string & cast(const std::string &source)
Definition: lexical_cast.h:202
static std::string cast(const char *source)
Definition: lexical_cast.h:218
Definition: lexical_cast.h:28
char tolower(const char ch)
Definition: string.h:25
static Destination cast(const char *str)
Definition: lexical_cast.h:157
static const char * cast(const std::string &source)
Definition: lexical_cast.h:250
std::string format(const float val, const int width, const int precision, const char fill= ' ', const bool fixed=true)
Definition: lexical_cast.h:278
static std::string cast(const char *source)
Definition: lexical_cast.h:234
static Destination cast(const char *str)
Definition: lexical_cast.h:139
static std::string cast(const Source &source)
Definition: lexical_cast.h:175
Destination lexical_cast(const Source &src)
Definition: lexical_cast.h:264