diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2015-02-01 03:21:57 +0100 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2015-02-01 03:21:57 +0100 |
commit | fc1fc8fbbc9dd9534f40de348210ea66b6defe42 (patch) | |
tree | 3cfa5fae12050f49df5cc6bc0482d4e5a45711d1 /src/NBT/ListTag.hpp | |
parent | a6a2a6281218688de7a74a9cd2a426aad3fe2da2 (diff) | |
download | MinedMap-fc1fc8fbbc9dd9534f40de348210ea66b6defe42.tar MinedMap-fc1fc8fbbc9dd9534f40de348210ea66b6defe42.zip |
Use template argument for list subtype, extract further information from chunks
Diffstat (limited to 'src/NBT/ListTag.hpp')
-rw-r--r-- | src/NBT/ListTag.hpp | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/src/NBT/ListTag.hpp b/src/NBT/ListTag.hpp index 67ba619..1a48062 100644 --- a/src/NBT/ListTag.hpp +++ b/src/NBT/ListTag.hpp @@ -34,30 +34,39 @@ namespace MinedMap { namespace NBT { -class ListTag : public Tag { -private: - friend class Tag; - std::vector<std::shared_ptr<const Tag>> value; +class ListTagBase : public Tag { +public: + virtual Type getType() const { + return Type::List; + } + virtual Type getSubtype() const = 0; +}; - ListTag(Buffer *buffer) { - Type type = static_cast<Type>(buffer->get()); +template<typename T> +class ListTag : public ListTagBase, public std::vector<std::shared_ptr<const T>> { +private: + friend class Tag; + + Type type; + + ListTag(Type type0, Buffer *buffer) : type(type0) { uint32_t len = uint32_t(buffer->get()) << 24; len |= uint32_t(buffer->get()) << 16; len |= uint32_t(buffer->get()) << 8; len |= uint32_t(buffer->get()); - value.resize(len); + this->resize(len); for (uint32_t i = 0; i < len; i++) - value[i] = Tag::readTag(type, buffer); + (*this)[i] = std::static_pointer_cast<const T>(Tag::readTag(type, buffer)); } public: - virtual Type getType() const { - return Type::List; + virtual Type getSubtype() const { + return type; } }; |