conversion.h 1.13 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
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <string>
#include <sstream>

namespace YAML
{
	template <typename T>
	struct Converter {
		static bool Convert(const std::string& input, T& output);
	};

	template <typename T>
	bool Convert(const std::string& input, T& output) {
		return Converter<T>::Convert(input, output);
	}
	
	// this is the one to specialize
	template <typename T>
	inline bool Converter<T>::Convert(const std::string& input, T& output) {
		std::stringstream stream(input);
		stream >> output;
		return !stream.fail();
	}

	// specializations
	template <>
	inline bool Converter<std::string>::Convert(const std::string& input, std::string& output) {
		output = input;
		return true;
	}

	template <>
	bool Converter<bool>::Convert(const std::string& input, bool& output);
jbeder's avatar
jbeder committed
40
	
41
42
43
	template <>
	bool Converter<_Null>::Convert(const std::string& input, _Null& output);
	
jbeder's avatar
jbeder committed
44
45
	template <>
	bool Converter<std::wstring>::Convert(const std::string& input, std::wstring& output);
46
}
jbeder's avatar
jbeder committed
47
48

#endif // CONVERSION_H_62B23520_7C8E_11DE_8A39_0800200C9A66