diff --git a/src/lib/nbt.cpp b/src/lib/nbt.cpp index 97a1a9d..676f45e 100644 --- a/src/lib/nbt.cpp +++ b/src/lib/nbt.cpp @@ -873,7 +873,8 @@ namespace NBT { } Helper::writeInt32(rawData, this->tags.size()); - for (int32_t i=0; itags.size(); i++) { + // unsigned integer bc of compiler warning (shouldn't matter) + for (uint32_t i=0; itags.size(); i++) { ErrorOrVoid result = this->tags.at(i)->serializeWithoutHeader(rawData); if (result.isError) { return result; @@ -884,28 +885,47 @@ namespace NBT { } ErrorOr List::getElementPointer(uint64_t position) { - #pragma message("TODO: Implement.") - return ErrorOr(true, ErrorCodes::UNIMPLEMENTED); + if (this->tags.size() <= position) { + return ErrorOr(true, ErrorCodes::OUT_OF_RANGE); + } + return ErrorOr(this->tags.at(position)); } - ErrorOrVoid List::setElementPointerAt(uint64_t position, Generic*) { - #pragma message("TODO: Implement.") - return ErrorOrVoid(true, ErrorCodes::UNIMPLEMENTED); + ErrorOrVoid List::setElementPointerAt(uint64_t position, Generic* pointer) { + if (this->tags.size() <= position) { + return ErrorOrVoid(true, ErrorCodes::OUT_OF_RANGE); + } + + if (pointer->getTagType() != this->containedType) { + return ErrorOrVoid(true, ErrorCodes::INVALID_TYPE); + } + + delete this->tags[position]; + this->tags[position] = pointer; + return ErrorOrVoid(); } - ErrorOrVoid List::appendPointer(Generic*) { - #pragma message("TODO: Implement.") - return ErrorOrVoid(true, ErrorCodes::UNIMPLEMENTED); + ErrorOrVoid List::appendPointer(Generic* pointer) { + if (pointer->getTagType() != this->containedType) { + return ErrorOrVoid(true, ErrorCodes::INVALID_TYPE); + } + + this->tags.push_back(pointer); + + return ErrorOrVoid(); } ErrorOrVoid List::deleteElement(uint64_t position) { #pragma message("TODO: Implement.") + + // Step 1) delete pointer + // Step 2) remove element from vector + return ErrorOrVoid(true, ErrorCodes::UNIMPLEMENTED); } uint64_t List::length() { - #pragma message("TODO: Implement.") - return 0; + return this->tags.size(); } } diff --git a/src/lib/nbt.hpp b/src/lib/nbt.hpp index 2938c14..ed3993c 100644 --- a/src/lib/nbt.hpp +++ b/src/lib/nbt.hpp @@ -235,8 +235,8 @@ namespace NBT { ErrorOrVoid serializeWithoutHeader(std::vector* rawData) override; ErrorOr getElementPointer(uint64_t position); - ErrorOrVoid setElementPointerAt(uint64_t position, Generic*); - ErrorOrVoid appendPointer(Generic*); + ErrorOrVoid setElementPointerAt(uint64_t position, Generic* pointer); + ErrorOrVoid appendPointer(Generic* pointer); ErrorOrVoid deleteElement(uint64_t position); uint64_t length(); };