Refactored the traits a bit, and added displaying the key to string and numeric key not found errors

This commit is contained in:
jbeder
2009-11-12 17:00:12 +00:00
parent 7b33c7c4b4
commit bbf510d6cc
4 changed files with 110 additions and 34 deletions

View File

@@ -5,6 +5,7 @@
#include "null.h"
#include "traits.h"
#include <string>
#include <sstream>
@@ -18,34 +19,8 @@ namespace YAML
bool Convert(const std::string& input, bool& output);
bool Convert(const std::string& input, _Null& output);
template <typename>
struct is_numeric { enum { value = false }; };
template <> struct is_numeric <char> { enum { value = true }; };
template <> struct is_numeric <unsigned char> { enum { value = true }; };
template <> struct is_numeric <int> { enum { value = true }; };
template <> struct is_numeric <unsigned int> { enum { value = true }; };
template <> struct is_numeric <long int> { enum { value = true }; };
template <> struct is_numeric <unsigned long int> { enum { value = true }; };
template <> struct is_numeric <short int> { enum { value = true }; };
template <> struct is_numeric <unsigned short int> { enum { value = true }; };
template <> struct is_numeric <long long> { enum { value = true }; };
template <> struct is_numeric <unsigned long long> { enum { value = true }; };
template <> struct is_numeric <float> { enum { value = true }; };
template <> struct is_numeric <double> { enum { value = true }; };
template <> struct is_numeric <long double> { enum { value = true }; };
template <typename T, typename, bool = T::value>
struct enable_if;
template <typename T, typename R>
struct enable_if <T, R, true> {
typedef R type;
};
template <typename T>
inline bool Convert(const std::string& input, T& output, typename enable_if<is_numeric<T>, T>::type * = 0) {
inline bool Convert(const std::string& input, T& output, typename enable_if<is_numeric<T> >::type * = 0) {
std::stringstream stream(input);
stream.unsetf(std::ios::dec);
return stream >> output;