diff options
| -rw-r--r-- | include/io/stream_reader.h | 1 | ||||
| -rw-r--r-- | include/tag.h | 7 | ||||
| -rw-r--r-- | src/io/stream_reader.cpp | 7 | ||||
| -rw-r--r-- | test/io/read_test.cpp | 2 |
4 files changed, 16 insertions, 1 deletions
diff --git a/include/io/stream_reader.h b/include/io/stream_reader.h index 07eb36192d..056d14e9dd 100644 --- a/include/io/stream_reader.h +++ b/include/io/stream_reader.h @@ -23,6 +23,7 @@ #include "endian_str.h" #include "tag.h" #include <iosfwd> +#include <memory> #include <stdexcept> namespace nbt diff --git a/include/tag.h b/include/tag.h index ae84891c76..4b547e013c 100644 --- a/include/tag.h +++ b/include/tag.h @@ -51,6 +51,10 @@ enum class tag_type : int8_t */ bool is_valid_type(int type, bool allow_end = false); +//Forward declaration +namespace io +{ class stream_reader; } + ///Base class for all NBT tag classes class tag { @@ -72,6 +76,9 @@ public: */ virtual tag& assign(tag&& rhs) = 0; + ///Reads the tag's payload from the stream + virtual void read_payload(io::stream_reader& reader) = 0; + /** * @brief Default-constructs a new tag of the given type * @throw std::invalid_argument if the type is not valid (e.g. End or Null) diff --git a/src/io/stream_reader.cpp b/src/io/stream_reader.cpp index 7605d62776..ff0fe183ea 100644 --- a/src/io/stream_reader.cpp +++ b/src/io/stream_reader.cpp @@ -39,6 +39,13 @@ endian::endian stream_reader::get_endian() const return endian; } +std::unique_ptr<tag> stream_reader::read_payload(tag_type type) +{ + std::unique_ptr<tag> t = tag::create(type); + t->read_payload(*this); + return t; +} + tag_type stream_reader::read_type(bool allow_end) { int type = is.get(); diff --git a/test/io/read_test.cpp b/test/io/read_test.cpp index 9e70387f2e..78a6ea345f 100644 --- a/test/io/read_test.cpp +++ b/test/io/read_test.cpp @@ -122,7 +122,7 @@ void test_read_bigtest() //From bigtest.nbt: "the first 1000 values of (n*n*255+n*7)%100, starting with n=0 (0, 62, 34, 16, 8, ...)" tag_byte_array byteArrayTest; for(int n = 0; n < 1000; ++n) - byteArrayTest.get().push_back((n*n*255 + n*7) % 100); + byteArrayTest.push_back((n*n*255 + n*7) % 100); ASSERT(comp.at("byteArrayTest") == byteArrayTest); ASSERT(comp.at("stringTest") == tag_string("HELLO WORLD THIS IS A TEST STRING \u00C5\u00C4\u00D6!")); |
