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