1 #ifndef CONVERSION_H_62B23520_7C8E_11DE_8A39_0800200C9A66
2 #define CONVERSION_H_62B23520_7C8E_11DE_8A39_0800200C9A66
4 #if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
9 #include "yaml-cpp/null.h"
10 #include "yaml-cpp/traits.h"
17 // traits for conversion
20 struct is_scalar_convertible
{ enum { value
= is_numeric
<T
>::value
}; };
22 template<> struct is_scalar_convertible
<std::string
> { enum { value
= true }; };
23 template<> struct is_scalar_convertible
<bool> { enum { value
= true }; };
24 template<> struct is_scalar_convertible
<_Null
> { enum { value
= true }; };
28 inline bool Convert(const std::string
& input
, std::string
& output
) {
33 YAML_CPP_API
bool Convert(const std::string
& input
, bool& output
);
34 YAML_CPP_API
bool Convert(const std::string
& input
, _Null
& output
);
36 inline bool IsInfinity(const std::string
& input
) {
37 return input
== ".inf" || input
== ".Inf" || input
== ".INF" || input
== "+.inf" || input
== "+.Inf" || input
== "+.INF";
40 inline bool IsNegativeInfinity(const std::string
& input
) {
41 return input
== "-.inf" || input
== "-.Inf" || input
== "-.INF";
44 inline bool IsNaN(const std::string
& input
) {
45 return input
== ".nan" || input
== ".NaN" || input
== ".NAN";
50 inline bool Convert(const std::string
& input
, T
& output
, typename enable_if
<is_numeric
<T
> >::type
* = 0) {
51 std::stringstream
stream(input
);
52 stream
.unsetf(std::ios::dec
);
53 if((stream
>> output
) && (stream
>> std::ws
).eof())
56 if(std::numeric_limits
<T
>::has_infinity
) {
57 if(IsInfinity(input
)) {
58 output
= std::numeric_limits
<T
>::infinity();
60 } else if(IsNegativeInfinity(input
)) {
61 output
= -std::numeric_limits
<T
>::infinity();
66 if(std::numeric_limits
<T
>::has_quiet_NaN
&& IsNaN(input
)) {
67 output
= std::numeric_limits
<T
>::quiet_NaN();
75 #endif // CONVERSION_H_62B23520_7C8E_11DE_8A39_0800200C9A66