From c08047844465e1f3012ee0f613755ba6d8ae07e7 Mon Sep 17 00:00:00 2001 From: beder Date: Thu, 8 Sep 2011 02:05:03 -0500 Subject: [PATCH] Added back the streamable conversions --- include/yaml-cpp/value/convert.h | 36 ++++++++++++++++++++++++++++++++ src/value/convert.cpp | 31 --------------------------- util/value.cpp | 8 +++---- 3 files changed, 40 insertions(+), 35 deletions(-) diff --git a/include/yaml-cpp/value/convert.h b/include/yaml-cpp/value/convert.h index 55d9356..9baf596 100644 --- a/include/yaml-cpp/value/convert.h +++ b/include/yaml-cpp/value/convert.h @@ -25,6 +25,42 @@ namespace YAML return true; } }; + +#define YAML_DEFINE_CONVERT_STREAMABLE(type)\ + template<>\ + struct convert {\ + static Value encode(const type& rhs) {\ + std::stringstream stream;\ + stream << rhs;\ + return Value(stream.str());\ + }\ + \ + static bool decode(const Value& value, type& rhs) {\ + if(value.Type() != ValueType::Scalar)\ + return false;\ + std::stringstream stream(value.scalar());\ + stream >> rhs;\ + return !!stream;\ + }\ + } + + YAML_DEFINE_CONVERT_STREAMABLE(int); + YAML_DEFINE_CONVERT_STREAMABLE(unsigned); + YAML_DEFINE_CONVERT_STREAMABLE(short); + YAML_DEFINE_CONVERT_STREAMABLE(unsigned short); + YAML_DEFINE_CONVERT_STREAMABLE(long); + YAML_DEFINE_CONVERT_STREAMABLE(unsigned long); + YAML_DEFINE_CONVERT_STREAMABLE(long long); + YAML_DEFINE_CONVERT_STREAMABLE(unsigned long long); + + YAML_DEFINE_CONVERT_STREAMABLE(char); + YAML_DEFINE_CONVERT_STREAMABLE(unsigned char); + + YAML_DEFINE_CONVERT_STREAMABLE(float); + YAML_DEFINE_CONVERT_STREAMABLE(double); + YAML_DEFINE_CONVERT_STREAMABLE(long double); + +#undef YAML_DEFINE_CONVERT_STREAMABLE } #endif // VALUE_CONVERT_H_62B23520_7C8E_11DE_8A39_0800200C9A66 diff --git a/src/value/convert.cpp b/src/value/convert.cpp index 586ac9a..6ea5b96 100644 --- a/src/value/convert.cpp +++ b/src/value/convert.cpp @@ -3,37 +3,6 @@ namespace YAML { -//#define YAML_DEFINE_CONVERT_STREAMABLE(type)\ -// template<> Value convert(const type& rhs) {\ -// std::stringstream stream;\ -// stream << rhs;\ -// return Value(stream.str());\ -// }\ -// template<> bool convert(const Value& value, type& rhs) {\ -// if(value.Type() != ValueType::Scalar)\ -// return false;\ -// std::stringstream stream(value.scalar());\ -// stream >> rhs;\ -// return !!stream;\ -// } -// -// YAML_DEFINE_CONVERT_STREAMABLE(int) -// YAML_DEFINE_CONVERT_STREAMABLE(unsigned) -// YAML_DEFINE_CONVERT_STREAMABLE(short) -// YAML_DEFINE_CONVERT_STREAMABLE(unsigned short) -// YAML_DEFINE_CONVERT_STREAMABLE(long) -// YAML_DEFINE_CONVERT_STREAMABLE(unsigned long) -// YAML_DEFINE_CONVERT_STREAMABLE(long long) -// YAML_DEFINE_CONVERT_STREAMABLE(unsigned long long) -// -// YAML_DEFINE_CONVERT_STREAMABLE(char) -// YAML_DEFINE_CONVERT_STREAMABLE(unsigned char) -// -// YAML_DEFINE_CONVERT_STREAMABLE(float) -// YAML_DEFINE_CONVERT_STREAMABLE(double) -// YAML_DEFINE_CONVERT_STREAMABLE(long double) -// -//#undef YAML_DEFINE_CONVERT_STREAMABLE // // template // Value convert >(const std::map& rhs) { diff --git a/util/value.cpp b/util/value.cpp index adcabb2..48fcfe1 100644 --- a/util/value.cpp +++ b/util/value.cpp @@ -7,10 +7,10 @@ int main() std::cout << value["key"].as() << "\n"; value["key"]["key"] = "value"; std::cout << value["key"]["key"].as() << "\n"; -// value[5] = "monkey"; -// std::cout << value[5].as() << "\n"; -// value["monkey"] = 5; -// std::cout << value["monkey"].as() << "\n"; + value[5] = "monkey"; + std::cout << value[5].as() << "\n"; + value["monkey"] = 5; + std::cout << value["monkey"].as() << "\n"; return 0; }