Changed the way we read different types of scalars.

It's better organized now, I think - nodes only offer a single main way of getting the fundamental scalar (as a string), and now we can specialize a single template to read specific types.
This commit is contained in:
jbeder
2009-05-23 23:51:01 +00:00
parent 0c34137d84
commit 51457eece9
12 changed files with 158 additions and 270 deletions

35
include/conversion.h Normal file
View File

@@ -0,0 +1,35 @@
#pragma once
#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);
}