diff options
| author | ljfa-ag <ljfa-ag@web.de> | 2015-06-28 17:48:20 +0200 |
|---|---|---|
| committer | ljfa-ag <ljfa-ag@web.de> | 2015-06-28 17:48:20 +0200 |
| commit | 9337c5455222c878019ab1cd4779cc5023e73507 (patch) | |
| tree | 50294954a8d608039cb0e2540922a3bb151ad16a | |
| parent | 1393bc318e61b57e2cd6906a6abd3fb4607111c7 (diff) | |
| download | Project-Tick-9337c5455222c878019ab1cd4779cc5023e73507.tar.gz Project-Tick-9337c5455222c878019ab1cd4779cc5023e73507.zip | |
Add at method to value
| -rw-r--r-- | include/value.h | 9 | ||||
| -rw-r--r-- | test/nbttest.cpp | 6 |
2 files changed, 12 insertions, 3 deletions
diff --git a/include/value.h b/include/value.h index 4553b3e8f4..2a9ecc0d1a 100644 --- a/include/value.h +++ b/include/value.h @@ -85,6 +85,15 @@ public: explicit operator const std::string&() const; /** + * @brief In case of a tag_compound, accesses a tag by key with bounds checking + * @throw std::bad_cast if the tag type is not tag_compound + * @throw std::out_of_range if given key does not exist + * @sa tag_compound::at + */ + value& at(const std::string& key); + const value& at(const std::string& key) const; + + /** * @brief In case of a tag_compound, accesses a tag by key * @throw std::bad_cast if the tag type is not tag_compound * @sa tag_compound::operator[] diff --git a/test/nbttest.cpp b/test/nbttest.cpp index 8b4329d64f..60f090dd43 100644 --- a/test/nbttest.cpp +++ b/test/nbttest.cpp @@ -86,7 +86,7 @@ void test_tag_compound() ASSERT(comp["foo"].get_type() == tag_type::Short); ASSERT(int(comp["foo"]) == 12); - ASSERT(int16_t(comp["foo"]) == int16_t(12)); + ASSERT(int16_t(comp.at("foo")) == int16_t(12)); ASSERT(comp["bar"].get_type() == tag_type::String); ASSERT(std::string(comp["bar"]) == "baz"); @@ -96,8 +96,8 @@ void test_tag_compound() ASSERT(float(comp["baz"]) == -2.0f); comp["quux"] = tag_compound{/*{"Hello", "World"}, {"zero", 0}*/}; - ASSERT(comp["quux"].get_type() == tag_type::Compound); - ASSERT(std::string(comp["quux"]["Hello"]) == "World"); + ASSERT(comp.at("quux").get_type() == tag_type::Compound); + ASSERT(std::string(comp["quux"].at("Hello")) == "World"); tag_compound comp2/*{ {"foo", int16_t(12)}, |
