From 37cd3bd53c89fd821065e79a814ca1c5af4f5c45 Mon Sep 17 00:00:00 2001 From: beder Date: Thu, 8 Sep 2011 02:10:04 -0500 Subject: [PATCH] Added half of the std::map conversion (we don't have reading from Values yet) --- include/yaml-cpp/value/convert.h | 16 ++++++++++++++++ src/value/convert.cpp | 9 --------- util/value.cpp | 8 ++++++++ 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/include/yaml-cpp/value/convert.h b/include/yaml-cpp/value/convert.h index 9baf596..7244fe1 100644 --- a/include/yaml-cpp/value/convert.h +++ b/include/yaml-cpp/value/convert.h @@ -7,6 +7,7 @@ #include "yaml-cpp/value/value.h" +#include #include namespace YAML @@ -61,6 +62,21 @@ namespace YAML YAML_DEFINE_CONVERT_STREAMABLE(long double); #undef YAML_DEFINE_CONVERT_STREAMABLE + + template + struct convert > { + static Value encode(const std::map& rhs) { + Value value(ValueType::Map); + for(typename std::map::const_iterator it=rhs.begin();it!=rhs.end();++it) + value[it->first] = it->second; + return value; + } + + static bool decode(const Value& value, std::map& rhs) { + rhs.clear(); + return false; + } + }; } #endif // VALUE_CONVERT_H_62B23520_7C8E_11DE_8A39_0800200C9A66 diff --git a/src/value/convert.cpp b/src/value/convert.cpp index 6ea5b96..79fd852 100644 --- a/src/value/convert.cpp +++ b/src/value/convert.cpp @@ -2,13 +2,4 @@ namespace YAML { - -// -// template -// Value convert >(const std::map& rhs) { -// Value value(ValueType::Map); -// for(std::map::const_iterator it=rhs.begin();it!=rhs.end();++it) -// value[it->first] = it->second; -// return value; -// } } diff --git a/util/value.cpp b/util/value.cpp index 48fcfe1..b8ac6af 100644 --- a/util/value.cpp +++ b/util/value.cpp @@ -1,4 +1,5 @@ #include "yaml-cpp/value.h" +#include int main() { @@ -12,5 +13,12 @@ int main() value["monkey"] = 5; std::cout << value["monkey"].as() << "\n"; + std::map names; + names[1] = "one"; + names[2] = "two"; + names[3] = "three"; + names[4] = "four"; + value["names"] = names; + return 0; }