From 5dbcf7eeb106e616b115901739c6a84507fc1628 Mon Sep 17 00:00:00 2001 From: Jesse Beder Date: Mon, 1 Apr 2013 22:25:53 -0500 Subject: [PATCH] Fix conversion for C-strings (both literals and normal C-strings) so it compiles on Visual Studio. --- include/yaml-cpp/node/convert.h | 15 +++++++++++++++ include/yaml-cpp/node/detail/impl.h | 7 ++++++- include/yaml-cpp/node/detail/node_data.h | 1 + 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/include/yaml-cpp/node/convert.h b/include/yaml-cpp/node/convert.h index a8de752..146067b 100644 --- a/include/yaml-cpp/node/convert.h +++ b/include/yaml-cpp/node/convert.h @@ -47,7 +47,22 @@ namespace YAML } }; + // C-strings can only be encoded template<> + struct convert { + static Node encode(const char *&rhs) { + return Node(rhs); + } + }; + + template + struct convert { + static Node encode(const char (&rhs)[N]) { + return Node(rhs); + } + }; + + template<> struct convert<_Null> { static Node encode(const _Null& /* rhs */) { return Node(); diff --git a/include/yaml-cpp/node/detail/impl.h b/include/yaml-cpp/node/detail/impl.h index c618758..ce5fd57 100644 --- a/include/yaml-cpp/node/detail/impl.h +++ b/include/yaml-cpp/node/detail/impl.h @@ -149,7 +149,12 @@ namespace YAML return false; } - template + inline bool node_data::equals(node& node, const char *rhs, shared_memory_holder pMemory) + { + return equals(node, rhs, pMemory); + } + + template inline node& node_data::convert_to_node(const T& rhs, shared_memory_holder pMemory) { Node value = convert::encode(rhs); diff --git a/include/yaml-cpp/node/detail/node_data.h b/include/yaml-cpp/node/detail/node_data.h index 7fe05b8..413da5f 100644 --- a/include/yaml-cpp/node/detail/node_data.h +++ b/include/yaml-cpp/node/detail/node_data.h @@ -77,6 +77,7 @@ namespace YAML template static bool equals(node& node, const T& rhs, shared_memory_holder pMemory); + static bool equals(node& node, const char *rhs, shared_memory_holder pMemory); template static node& convert_to_node(const T& rhs, shared_memory_holder pMemory);