diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2018-07-21 18:07:45 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2018-07-21 18:11:59 +0200 |
commit | f1f783877f0f8338a225244faff4e40efe10a4ce (patch) | |
tree | e071d5df7024fbc3c72713517672f217096ea47f /src/NBT/ListTag.hpp | |
parent | 315bb38444b8e363b4d8f2702d45d42fa585f619 (diff) | |
download | MinedMap-f1f783877f0f8338a225244faff4e40efe10a4ce.tar MinedMap-f1f783877f0f8338a225244faff4e40efe10a4ce.zip |
NBT: rework type system
Diffstat (limited to 'src/NBT/ListTag.hpp')
-rw-r--r-- | src/NBT/ListTag.hpp | 31 |
1 files changed, 13 insertions, 18 deletions
diff --git a/src/NBT/ListTag.hpp b/src/NBT/ListTag.hpp index d86abdb..7276923 100644 --- a/src/NBT/ListTag.hpp +++ b/src/NBT/ListTag.hpp @@ -34,34 +34,29 @@ namespace MinedMap { namespace NBT { +class ListTag : public Tag, public std::vector<std::shared_ptr<const Tag>> { +private: + const TagType *subtype; -class ListTagBase : public Tag { public: - virtual Type getType() const { - return Type::List; - } + static const MakeType<ListTag> Type; - virtual Type getSubtype() const = 0; -}; + ListTag(Buffer *buffer) { + subtype = &getTypeById(buffer->get8()); -template<typename T> -class ListTag : public ListTagBase, public std::vector<std::shared_ptr<const T>> { -private: - Type type; - -public: - ListTag(Type type0, Buffer *buffer) : type(type0) { uint32_t len = buffer->get32(); - this->resize(len); - for (uint32_t i = 0; i < len; i++) - (*this)[i] = std::static_pointer_cast<const T>(Tag::readTag(type, buffer)); + push_back(subtype->read(buffer)); + } + + virtual const TagType & getType() const { + return Type; } - virtual Type getSubtype() const { - return type; + virtual const TagType & getSubtype() const { + return *subtype; } virtual void print(std::ostream& os, const std::string &indent) const { |