Compare commits
No commits in common. "7be73f86d4c1bbc99a3764dedad1231f8dba92c6" and "f8dd10d301ff4cb0bd8596844557b1e775cf501f" have entirely different histories.
7be73f86d4
...
f8dd10d301
|
@ -70,10 +70,13 @@ namespace ErrorCodes {
|
|||
// Ahh yes, very useful.
|
||||
const uint8_t SUCCESS = 0;
|
||||
|
||||
// IndexOutOfRangeException equivalent
|
||||
const uint8_t OUT_OF_RANGE = 1;
|
||||
// like OUT_OF_RANGE but when going out of bounds in a non-predetermined way
|
||||
|
||||
// when going out of bounds in a non-predetermined way
|
||||
const uint8_t OVERRUN = 2;
|
||||
|
||||
// when checking for presence of something, for example CLI arguments
|
||||
const uint8_t NOT_PRESENT = 3;
|
||||
|
||||
const uint8_t WRONG_USAGE = 4;
|
||||
|
@ -91,10 +94,6 @@ namespace ErrorCodes {
|
|||
const uint8_t FILE_NOT_OPEN = 9;
|
||||
const uint8_t FILE_NOT_FOUND = 10;
|
||||
|
||||
// when performing an operation that would technically be valid but must
|
||||
// never be performed (like deleting an end tag from an NBT compound)
|
||||
const uint8_t NOT_ALLOWED = 11;
|
||||
|
||||
const uint8_t UNIMPLEMENTED = 254;
|
||||
|
||||
const uint8_t UNKNOWN = 255;
|
||||
|
|
|
@ -940,27 +940,23 @@ namespace NBT {
|
|||
|
||||
Compound::Compound() {
|
||||
this->type = TagType::COMPOUND;
|
||||
this->endPointer = new End();
|
||||
}
|
||||
|
||||
Compound::Compound(tiny_utf8::string name) {
|
||||
this->type = TagType::COMPOUND;
|
||||
this->name = name;
|
||||
this->endPointer = new End();
|
||||
}
|
||||
|
||||
Compound::Compound(tiny_utf8::string name, std::vector<Generic*> data) {
|
||||
this->type = TagType::COMPOUND;
|
||||
this->name = name;
|
||||
this->tags = data;
|
||||
this->endPointer = new End();
|
||||
}
|
||||
|
||||
Compound::~Compound() {
|
||||
for (uint64_t i=0; i<this->tags.size(); i++) {
|
||||
delete this->tags.at(i);
|
||||
}
|
||||
delete this->endPointer;
|
||||
}
|
||||
|
||||
ErrorOrVoid Compound::serializeWithoutHeader(std::vector<uint8_t>* rawData) {
|
||||
|
@ -970,36 +966,20 @@ namespace NBT {
|
|||
return result;
|
||||
}
|
||||
}
|
||||
this->endPointer->serialize(rawData);
|
||||
|
||||
return ErrorOrVoid();
|
||||
}
|
||||
|
||||
ErrorOr<Generic*> Compound::getElementPointer(uint64_t position) {
|
||||
if (position > this->tags.size()) {
|
||||
if (position >= this->tags.size()) {
|
||||
return ErrorOr<Generic*>(true, ErrorCodes::OUT_OF_RANGE);
|
||||
}
|
||||
|
||||
if (position == this->tags.size()) {
|
||||
return this->endPointer;
|
||||
}
|
||||
|
||||
return ErrorOr<Generic*>(this->tags.at(position));
|
||||
}
|
||||
|
||||
ErrorOrVoid Compound::setElementPointerAt(uint64_t position, Generic* pointer) {
|
||||
if (position == this->tags.size() || pointer->getTagType() == TagType::END) {
|
||||
if (position == this->tags.size() && pointer->getTagType() == TagType::END) {
|
||||
delete pointer;
|
||||
// do nothing, already have one of those
|
||||
} else {
|
||||
delete pointer;
|
||||
// End tags may only go at the end and
|
||||
// the end may only hold an end tag.
|
||||
return ErrorOrVoid(true, ErrorCodes::NOT_ALLOWED);
|
||||
}
|
||||
}
|
||||
if (position > this->tags.size()) {
|
||||
if (position >= this->tags.size()) {
|
||||
return ErrorOrVoid(true, ErrorCodes::OUT_OF_RANGE);
|
||||
}
|
||||
|
||||
|
@ -1009,20 +989,12 @@ namespace NBT {
|
|||
return ErrorOrVoid();
|
||||
}
|
||||
|
||||
ErrorOrVoid Compound::appendPointer(Generic* pointer) {
|
||||
if (pointer->getTagType() == TagType::END) {
|
||||
return ErrorOrVoid(true, ErrorCodes::NOT_ALLOWED);
|
||||
}
|
||||
void Compound::appendPointer(Generic* pointer) {
|
||||
this->tags.push_back(pointer);
|
||||
return ErrorOrVoid();
|
||||
}
|
||||
|
||||
ErrorOrVoid Compound::deleteElement(uint64_t position) {
|
||||
// built-in end tag
|
||||
if (position == this->tags.size()) {
|
||||
return ErrorOrVoid(true, ErrorCodes::NOT_ALLOWED);
|
||||
}
|
||||
if (position > this->tags.size()) {
|
||||
if (position >= this->tags.size()) {
|
||||
return ErrorOrVoid(true, ErrorCodes::OUT_OF_RANGE);
|
||||
}
|
||||
|
||||
|
@ -1033,8 +1005,7 @@ namespace NBT {
|
|||
}
|
||||
|
||||
uint64_t Compound::length() {
|
||||
// account for built-in end tag
|
||||
return this->tags.size()+1;
|
||||
return this->tags.size();
|
||||
}
|
||||
|
||||
Int32Array::Int32Array() {
|
||||
|
|
|
@ -244,8 +244,6 @@ namespace NBT {
|
|||
class Compound: public Generic {
|
||||
private:
|
||||
std::vector<Generic*> tags;
|
||||
// built-in end tag
|
||||
End* endPointer;
|
||||
public:
|
||||
Compound();
|
||||
Compound(tiny_utf8::string name);
|
||||
|
@ -257,7 +255,7 @@ namespace NBT {
|
|||
|
||||
ErrorOr<Generic*> getElementPointer(uint64_t position);
|
||||
ErrorOrVoid setElementPointerAt(uint64_t position, Generic* pointer);
|
||||
ErrorOrVoid appendPointer(Generic* pointer);
|
||||
void appendPointer(Generic* pointer);
|
||||
ErrorOrVoid deleteElement(uint64_t position);
|
||||
uint64_t length();
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue