From 737117332d962d47fef697f46313b9a001ab7775 Mon Sep 17 00:00:00 2001 From: marcel Date: Mon, 30 Aug 2021 14:15:48 +0200 Subject: [PATCH] add a Node::ContainsKey function for quick checking of subordinated --- include/yaml-cpp/node/impl.h | 10 ++++++++++ include/yaml-cpp/node/node.h | 2 ++ 2 files changed, 12 insertions(+) diff --git a/include/yaml-cpp/node/impl.h b/include/yaml-cpp/node/impl.h index c89171c..261dc88 100644 --- a/include/yaml-cpp/node/impl.h +++ b/include/yaml-cpp/node/impl.h @@ -350,6 +350,16 @@ std::string key_to_string(const Key& key) { } // indexing +template +inline bool Node::ContainsKey(const Key& key) const { + EnsureNodeExists(); + if (! IsMap()) + return false; + detail::node* value = + static_cast(*m_pNode).get(key, m_pMemory); + return (bool)value; +} + template inline const Node Node::operator[](const Key& key) const { EnsureNodeExists(); diff --git a/include/yaml-cpp/node/node.h b/include/yaml-cpp/node/node.h index c9e9a0a..634f09d 100644 --- a/include/yaml-cpp/node/node.h +++ b/include/yaml-cpp/node/node.h @@ -99,6 +99,8 @@ class YAML_CPP_API Node { // indexing template + bool ContainsKey(const Key& key) const; + template const Node operator[](const Key& key) const; template Node operator[](const Key& key);