mirror of
https://github.com/jbeder/yaml-cpp.git
synced 2025-09-09 12:41:17 +00:00
Added a convert<> specialization for YAML::_Null (so you can say node[YAML::Null])
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
|
||||
#include "yaml-cpp/node/node.h"
|
||||
#include "yaml-cpp/node/iterator.h"
|
||||
#include "yaml-cpp/null.h"
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <sstream>
|
||||
@@ -30,6 +31,17 @@ namespace YAML
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct convert<_Null> {
|
||||
static Node encode(const _Null& /* rhs */) {
|
||||
return Node();
|
||||
}
|
||||
|
||||
static bool decode(const Node& node, _Null& /* rhs */) {
|
||||
return node.Type() == NodeType::Null;
|
||||
}
|
||||
};
|
||||
|
||||
#define YAML_DEFINE_CONVERT_STREAMABLE(type)\
|
||||
template<>\
|
||||
struct convert<type> {\
|
||||
@@ -66,6 +78,7 @@ namespace YAML
|
||||
|
||||
#undef YAML_DEFINE_CONVERT_STREAMABLE
|
||||
|
||||
// std::map
|
||||
template<typename K, typename V>
|
||||
struct convert<std::map<K, V> > {
|
||||
static Node encode(const std::map<K, V>& rhs) {
|
||||
@@ -86,6 +99,7 @@ namespace YAML
|
||||
}
|
||||
};
|
||||
|
||||
// std::vector
|
||||
template<typename T>
|
||||
struct convert<std::vector<T> > {
|
||||
static Node encode(const std::vector<T>& rhs) {
|
||||
@@ -106,6 +120,7 @@ namespace YAML
|
||||
}
|
||||
};
|
||||
|
||||
// std::list
|
||||
template<typename T>
|
||||
struct convert<std::list<T> > {
|
||||
static Node encode(const std::list<T>& rhs) {
|
||||
|
@@ -132,6 +132,7 @@ namespace YAML
|
||||
inline node& node_data::convert_to_node(const T& rhs, shared_memory_holder pMemory)
|
||||
{
|
||||
Node value = convert<T>::encode(rhs);
|
||||
value.EnsureNodeExists();
|
||||
pMemory->merge(*value.m_pMemory);
|
||||
return *value.m_pNode;
|
||||
}
|
||||
|
@@ -558,8 +558,7 @@ namespace Test
|
||||
YAML::Node doc = YAML::Parse(ex7_3);
|
||||
YAML_ASSERT(doc.size() == 2);
|
||||
YAML_ASSERT(doc["foo"].Type() == YAML::NodeType::Null);
|
||||
// YAML_ASSERT(doc[YAML::as<.as<std::string>() == "bar");
|
||||
return " null as a key not implemented";
|
||||
YAML_ASSERT(doc[YAML::Null].as<std::string>() == "bar");
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -692,8 +691,7 @@ namespace Test
|
||||
YAML_ASSERT(doc.size() == 3);
|
||||
YAML_ASSERT(doc["explicit"].as<std::string>() == "entry");
|
||||
YAML_ASSERT(doc["implicit"].as<std::string>() == "entry");
|
||||
// YAML_ASSERT(doc[YAML::as<.Type() == YAML::NodeType::Null);
|
||||
return " null as a key not implemented";
|
||||
YAML_ASSERT(doc[YAML::Null].Type() == YAML::NodeType::Null);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -704,8 +702,7 @@ namespace Test
|
||||
YAML_ASSERT(doc["unquoted"].as<std::string>() == "separate");
|
||||
YAML_ASSERT(doc["http://foo.com"].Type() == YAML::NodeType::Null);
|
||||
YAML_ASSERT(doc["omitted value"].Type() == YAML::NodeType::Null);
|
||||
// YAML_ASSERT(doc[YAML::as<.as<std::string>() == "omitted key");
|
||||
return " null as a key not implemented";
|
||||
YAML_ASSERT(doc[YAML::Null].as<std::string>() == "omitted key");
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -746,8 +743,7 @@ namespace Test
|
||||
YAML_ASSERT(doc[0][0]["YAML"].as<std::string>() == "separate");
|
||||
YAML_ASSERT(doc[1].size() == 1);
|
||||
YAML_ASSERT(doc[1][0].size() == 1);
|
||||
// YAML_ASSERT(doc[1][0][YAML::as<.as<std::string>() == "empty key entry");
|
||||
return " null as a key not implemented";
|
||||
YAML_ASSERT(doc[1][0][YAML::Null].as<std::string>() == "empty key entry");
|
||||
YAML_ASSERT(doc[2].size() == 1);
|
||||
YAML_ASSERT(doc[2][0].size() == 1);
|
||||
|
||||
@@ -989,8 +985,7 @@ namespace Test
|
||||
YAML::Node doc = YAML::Parse(ex8_18);
|
||||
YAML_ASSERT(doc.size() == 3);
|
||||
YAML_ASSERT(doc["plain key"].as<std::string>() == "in-line value");
|
||||
// YAML_ASSERT(doc[YAML::Null].Type() == YAML::NodeType::Null);
|
||||
return " null not implemented as key";
|
||||
YAML_ASSERT(doc[YAML::Null].Type() == YAML::NodeType::Null);
|
||||
YAML_ASSERT(doc["quoted key"].size() == 1);
|
||||
YAML_ASSERT(doc["quoted key"][0].as<std::string>() == "entry");
|
||||
return true;
|
||||
|
Reference in New Issue
Block a user