Compare commits
	
		
			4 Commits 
		
	
	
		
			f8dd10d301
			...
			7be73f86d4
		
	
	| Author | SHA1 | Date | 
|---|---|---|
|  BodgeMaster | 7be73f86d4 | |
|  BodgeMaster | 71834e1018 | |
|  BodgeMaster | ccce564219 | |
|  BodgeMaster | 53279c6905 | 
|  | @ -70,13 +70,10 @@ namespace ErrorCodes { | |||
|     // Ahh yes, very useful.
 | ||||
|     const uint8_t SUCCESS = 0; | ||||
| 
 | ||||
|     // IndexOutOfRangeException equivalent
 | ||||
|     const uint8_t OUT_OF_RANGE = 1; | ||||
| 
 | ||||
|     // when going out of bounds in a non-predetermined way
 | ||||
|     // like OUT_OF_RANGE but 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; | ||||
|  | @ -94,6 +91,10 @@ 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,23 +940,27 @@ 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) { | ||||
|  | @ -966,20 +970,36 @@ 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()) { | ||||
|             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()) { | ||||
|                 return ErrorOrVoid(true, ErrorCodes::OUT_OF_RANGE); | ||||
|             } | ||||
| 
 | ||||
|  | @ -989,12 +1009,20 @@ namespace NBT { | |||
|             return ErrorOrVoid(); | ||||
|         } | ||||
| 
 | ||||
|         void Compound::appendPointer(Generic* pointer) { | ||||
|         ErrorOrVoid Compound::appendPointer(Generic* pointer) { | ||||
|             if (pointer->getTagType() == TagType::END) { | ||||
|                 return ErrorOrVoid(true, ErrorCodes::NOT_ALLOWED); | ||||
|             } | ||||
|             this->tags.push_back(pointer); | ||||
|             return ErrorOrVoid(); | ||||
|         } | ||||
| 
 | ||||
|         ErrorOrVoid Compound::deleteElement(uint64_t position) { | ||||
|             if (position >= this->tags.size()) { | ||||
|             // built-in end tag
 | ||||
|             if (position == this->tags.size()) { | ||||
|                 return ErrorOrVoid(true, ErrorCodes::NOT_ALLOWED); | ||||
|             } | ||||
|             if (position > this->tags.size()) { | ||||
|                 return ErrorOrVoid(true, ErrorCodes::OUT_OF_RANGE); | ||||
|             } | ||||
| 
 | ||||
|  | @ -1005,7 +1033,8 @@ namespace NBT { | |||
|         } | ||||
| 
 | ||||
|         uint64_t Compound::length() { | ||||
|             return this->tags.size(); | ||||
|             // account for built-in end tag
 | ||||
|             return this->tags.size()+1; | ||||
|         } | ||||
| 
 | ||||
|         Int32Array::Int32Array() { | ||||
|  |  | |||
|  | @ -244,6 +244,8 @@ namespace NBT { | |||
|         class Compound: public Generic { | ||||
|             private: | ||||
|                 std::vector<Generic*> tags; | ||||
|                 // built-in end tag
 | ||||
|                 End* endPointer; | ||||
|             public: | ||||
|                 Compound(); | ||||
|                 Compound(tiny_utf8::string name); | ||||
|  | @ -255,7 +257,7 @@ namespace NBT { | |||
| 
 | ||||
|                 ErrorOr<Generic*> getElementPointer(uint64_t position); | ||||
|                 ErrorOrVoid setElementPointerAt(uint64_t position, Generic* pointer); | ||||
|                 void appendPointer(Generic* pointer); | ||||
|                 ErrorOrVoid appendPointer(Generic* pointer); | ||||
|                 ErrorOrVoid deleteElement(uint64_t position); | ||||
|                 uint64_t length(); | ||||
|         }; | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue