From f5fc52e27b54a47ee86edfe9ba002426a4833d3d Mon Sep 17 00:00:00 2001 From: ljfa-ag Date: Fri, 17 Jul 2015 19:49:21 +0200 Subject: Overload has_key with version that takes tag_type --- include/tag_compound.h | 2 ++ src/tag_compound.cpp | 6 ++++++ test/nbttest.cpp | 6 ++++++ 3 files changed, 14 insertions(+) diff --git a/include/tag_compound.h b/include/tag_compound.h index abf1df239a..da6b755ad5 100644 --- a/include/tag_compound.h +++ b/include/tag_compound.h @@ -100,6 +100,8 @@ public: ///Returns true if the given key exists in the compound bool has_key(const std::string& key) const; + ///Returns true if the given key exists and the tag has the given type + bool has_key(const std::string& key, tag_type type) const; ///Returns the number of tags in the compound size_t size() const; diff --git a/src/tag_compound.cpp b/src/tag_compound.cpp index 78a5c46fc6..48f4f42239 100644 --- a/src/tag_compound.cpp +++ b/src/tag_compound.cpp @@ -72,6 +72,12 @@ bool tag_compound::has_key(const std::string& key) const return tags.find(key) != tags.end(); } +bool tag_compound::has_key(const std::string& key, tag_type type) const +{ + auto it = tags.find(key); + return it != tags.end() && it->second.get_type() == type; +} + size_t tag_compound::size() const { return tags.size(); diff --git a/test/nbttest.cpp b/test/nbttest.cpp index 89181a73c3..14f10975fd 100644 --- a/test/nbttest.cpp +++ b/test/nbttest.cpp @@ -153,8 +153,14 @@ void test_tag_compound() ASSERT(comp.erase("nothing") == false); ASSERT(comp.has_key("quux")); + ASSERT(comp.has_key("quux", tag_type::Compound)); + ASSERT(!comp.has_key("quux", tag_type::List)); + ASSERT(!comp.has_key("quux", tag_type::Null)); + ASSERT(comp.erase("quux") == true); ASSERT(!comp.has_key("quux")); + ASSERT(!comp.has_key("quux", tag_type::Compound)); + ASSERT(!comp.has_key("quux", tag_type::Null)); comp.clear(); ASSERT(comp == tag_compound{}); -- cgit 0.0.5-2-1-g0f52