diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2015-02-01 05:18:51 +0100 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2015-02-01 05:18:51 +0100 |
commit | d9226363114d446f5af0f53345be8811a3ed8d42 (patch) | |
tree | fe4db2843123cbf4ca1dbc317a104e6c2c1f2351 /src/NBT | |
parent | 8403a4e71c1c3557646c9f0d019bc53e014134a0 (diff) | |
download | MinedMap-d9226363114d446f5af0f53345be8811a3ed8d42.tar MinedMap-d9226363114d446f5af0f53345be8811a3ed8d42.zip |
Don't throw an exception when a compound field is not found
Diffstat (limited to 'src/NBT')
-rw-r--r-- | src/NBT/CompoundTag.hpp | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/src/NBT/CompoundTag.hpp b/src/NBT/CompoundTag.hpp index 28efc41..39fa25d 100644 --- a/src/NBT/CompoundTag.hpp +++ b/src/NBT/CompoundTag.hpp @@ -54,13 +54,15 @@ public: return Type::Compound; } - template<typename T> - std::shared_ptr<const T> get(const std::string &key) const { - return std::dynamic_pointer_cast<const T>(at(key)); + template<typename T> std::shared_ptr<const T> get(const std::string &key) const { + auto it = find(key); + if (it == end()) + return std::shared_ptr<const T>(); + + return std::dynamic_pointer_cast<const T>(it->second); } - template<typename T, typename... Args> - std::shared_ptr<const T> get(const std::string &key, const Args &...args) const { + template<typename T, typename... Args> std::shared_ptr<const T> get(const std::string &key, const Args &...args) const { std::shared_ptr<const CompoundTag> tag = get<CompoundTag>(key); if (!tag) return std::shared_ptr<const T>(); |