conversion.h 1.85 KB
Newer Older
1
2
#pragma once

jbeder's avatar
jbeder committed
3
4
5
6
#ifndef CONVERSION_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define CONVERSION_H_62B23520_7C8E_11DE_8A39_0800200C9A66


7
#include "null.h"
8
9
10
11
12
#include <string>
#include <sstream>

namespace YAML
{
13
	inline bool Convert(const std::string& input, std::string& output) {
14
15
16
		output = input;
		return true;
	}
jbeder's avatar
jbeder committed
17
	
18
19
20
	bool Convert(const std::string& input, bool& output);
	bool Convert(const std::string& input, _Null& output);
	
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
	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) {
		std::stringstream stream(input);
		stream.unsetf(std::ios::dec);
		return stream >> output;
52
	}
53
}
jbeder's avatar
jbeder committed
54
55

#endif // CONVERSION_H_62B23520_7C8E_11DE_8A39_0800200C9A66