From f1f783877f0f8338a225244faff4e40efe10a4ce Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sat, 21 Jul 2018 18:07:45 +0200 Subject: NBT: rework type system --- src/NBT/ListTag.hpp | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) (limited to 'src/NBT/ListTag.hpp') 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> { +private: + const TagType *subtype; -class ListTagBase : public Tag { public: - virtual Type getType() const { - return Type::List; - } + static const MakeType Type; - virtual Type getSubtype() const = 0; -}; + ListTag(Buffer *buffer) { + subtype = &getTypeById(buffer->get8()); -template -class ListTag : public ListTagBase, public std::vector> { -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(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 { -- cgit v1.2.3