diff --git a/include/yaml-cpp/node/convert.h b/include/yaml-cpp/node/convert.h index 51f7d4c..8fbcc4a 100644 --- a/include/yaml-cpp/node/convert.h +++ b/include/yaml-cpp/node/convert.h @@ -68,6 +68,21 @@ struct convert { } }; +template <> +struct convert { + static Node encode(const unsigned char& rhs) { Node n; n = rhs; return n; } + + static bool decode(const Node& node, unsigned char& rhs) { + if (node.Type() != NodeType::Scalar) { + return false; + } + int t = stoi(node.Scalar()); + if(t < 0 || t > 255) return false; + rhs = (unsigned char)t; + return true; + } +}; + // C-strings can only be encoded template <> struct convert { @@ -146,7 +161,7 @@ YAML_DEFINE_CONVERT_STREAMABLE_UNSIGNED(unsigned long long); YAML_DEFINE_CONVERT_STREAMABLE_SIGNED(char); YAML_DEFINE_CONVERT_STREAMABLE_SIGNED(signed char); -YAML_DEFINE_CONVERT_STREAMABLE_UNSIGNED(unsigned char); +//YAML_DEFINE_CONVERT_STREAMABLE_UNSIGNED(unsigned char); YAML_DEFINE_CONVERT_STREAMABLE_SIGNED(float); YAML_DEFINE_CONVERT_STREAMABLE_SIGNED(double); diff --git a/include/yaml-cpp/node/impl.h b/include/yaml-cpp/node/impl.h index 06a4884..9ffc84d 100644 --- a/include/yaml-cpp/node/impl.h +++ b/include/yaml-cpp/node/impl.h @@ -116,6 +116,7 @@ struct as_if { } }; + template struct as_if { explicit as_if(const Node& node_) : node(node_) {}