Add stream buffering (WIP)

This commit is contained in:
SirLynix
2022-04-09 18:22:57 +02:00
parent 2b66ea1e90
commit 22f58fdbf5
14 changed files with 291 additions and 189 deletions

View File

@@ -11,6 +11,7 @@
#include <Nazara/Core/Endianness.hpp>
#include <Nazara/Core/Enums.hpp>
#include <filesystem>
#include <memory>
#include <string>
namespace Nz
@@ -26,27 +27,29 @@ namespace Nz
virtual bool EndOfStream() const = 0;
inline void EnableBuffering(bool buffering, std::size_t bufferSize = DefaultBufferSize);
inline void EnableTextMode(bool textMode);
inline void Flush();
virtual UInt64 GetCursorPos() const = 0;
virtual std::filesystem::path GetDirectory() const;
virtual std::filesystem::path GetPath() const;
inline OpenModeFlags GetOpenMode() const;
inline StreamOptionFlags GetStreamOptions() const;
UInt64 GetCursorPos() const;
virtual UInt64 GetSize() const = 0;
inline std::size_t Read(void* buffer, std::size_t size);
std::size_t Read(void* buffer, std::size_t size);
virtual std::string ReadLine(unsigned int lineSize = 0);
inline bool IsBufferingEnabled() const;
inline bool IsReadable() const;
inline bool IsSequential() const;
inline bool IsTextModeEnabled() const;
inline bool IsWritable() const;
virtual bool SetCursorPos(UInt64 offset) = 0;
bool SetCursorPos(UInt64 offset);
bool Write(const ByteArray& byteArray);
bool Write(const std::string_view& string);
@@ -55,15 +58,24 @@ namespace Nz
Stream& operator=(const Stream&) = default;
Stream& operator=(Stream&&) noexcept = default;
static constexpr std::size_t DefaultBufferSize = 0xFFFF;
protected:
inline Stream(StreamOptionFlags streamOptions = StreamOption::None, OpenModeFlags openMode = OpenMode::NotOpen);
virtual void FlushStream() = 0;
virtual std::size_t ReadBlock(void* buffer, std::size_t size) = 0;
virtual bool SeekStreamCursor(UInt64 offset) = 0;
virtual UInt64 TellStreamCursor() const = 0;
virtual std::size_t WriteBlock(const void* buffer, std::size_t size) = 0;
std::size_t m_bufferCapacity;
std::size_t m_bufferOffset;
std::size_t m_bufferSize;
std::unique_ptr<UInt8[]> m_buffer;
OpenModeFlags m_openMode;
StreamOptionFlags m_streamOptions;
UInt64 m_bufferCursor;
};
}