/*** Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved. File: BufferedCharacterConsumer.hpp Date: 2022-1-29 Author: Reece ***/ #pragma once namespace Aurora::IO::Character { class BufferedCharacterConsumer : public IBufferedCharacterConsumer { public: BufferedCharacterConsumer(const AuSPtr &provider); bool HasBufferedNext() const override; AuUInt8 NextBufferedByte() const override; bool PeekNext(AuUInt8 &out) override; AuUInt8 GetCurrent() override; bool Next(AuUInt8 &out) override; private: bool hasNext_ {}; AuUInt8 peeked_ {}; AuUInt8 cur_ {}; // It just came to me that it would be a really terrible for parsers making future predictions, // a stream capable of glitching itself, shouldn't be able to fail a try peak followed by a // successful get. This is extremely problematic considering ICharacterProvider is a mere // generic get byte from stream interface. External IO could in theory glitch peekaheads bool hasFailed_ {}; AuSPtr provider_; AuThreadPrimitives::SpinLock lock_; }; }