/*** Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved. File: ByteBufferPushReadState.hpp Date: 2022-2-15 Author: Reece ***/ #pragma once namespace Aurora::Memory { struct ByteBufferPushReadState { ByteBuffer &bytebuffer; ByteBufferPushReadState(ByteBuffer &bytebuffer, bool pushError = false) : bytebuffer(bytebuffer), shouldPopError_(pushError) { this->readPos_ = this->bytebuffer.readPtr - this->bytebuffer.base; this->readErrorFlag_ = bytebuffer.flagReadError; } ~ByteBufferPushReadState() { if (this->readErrorFlag_ != bytebuffer.flagReadError) { if (this->shouldPopError_) { this->bytebuffer.flagReadError = this->readErrorFlag_; } this->bytebuffer.readPtr = this->bytebuffer.base + this->readPos_; } } private: bool readErrorFlag_; AuUInt readPos_; const bool shouldPopError_; }; }