CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
CeresEngine::BufferedDataStream Class Referencefinal

A filtered DataStream that caches read and write operations to it's underlying DataStream. More...

#include <CeresEngine/Foundation/IO/Stream.Buffered.hpp>

Inheritance diagram for CeresEngine::BufferedDataStream:
CeresEngine::FilteredDataStream CeresEngine::IDataStream CeresEngine::IInputStream CeresEngine::IOutputStream CeresEngine::IStream CeresEngine::IStream

Public Member Functions

 BufferedDataStream (DataStream &&dataStream, size_t readBufferSize=1024, size_t writeBufferSize=1024)
 Creates a new buffer data stream.
 
 BufferedDataStream (const BufferedDataStream &)=delete
 
 BufferedDataStream (BufferedDataStream &&) noexcept
 
 ~BufferedDataStream () final
 Destroys the buffered data stream.
 
void seek (std::streamsize position, Seek mode=Seek::Start) final
 Changes the position of the data stream.
 
bool isTellable () const noexcept final
 Checks if the stream knows it's current absolute position.
 
size_t tell () final
 Gets the absolute stream position, in bytes.
 
size_t read (void *data, size_t n) final
 Reads data from the data stream to a buffer of raw memory data with length n.
 
bool invalidate () final
 In the stream is buffered, invalidates any buffered read data from the stream.
 
size_t write (const void *data, size_t n) final
 Writes data to the data stream from a buffer of raw memory data with length n.
 
bool flush () final
 In the stream is buffered, invalidates any buffered write data from to stream.
 
- Public Member Functions inherited from CeresEngine::FilteredDataStream
 FilteredDataStream (DataStream &&dataStream)
 Creates a new filtered data stream.
 
 FilteredDataStream (FilteredDataStream &&) noexcept=default
 
 ~FilteredDataStream () override=default
 
DataStreamgetDataStream () noexcept
 The data stream being filtered.
 
const DataStreamgetDataStream () const noexcept
 The data stream being filtered.
 
bool isSeekable (const Seek mode=Seek::Start) const noexcept override
 Checks if the stream is seekable.
 
void seek (const std::streamsize position, const Seek mode=Seek::Start) override
 Changes the position of the data stream.
 
bool isTellable () const noexcept override
 Checks if the stream knows it's current absolute position.
 
size_t tell () override
 Gets the absolute stream position, in bytes.
 
bool isSizeKnown () const noexcept override
 Checks if the stream knows the size of the data.
 
size_t size () override
 Gets the number of bytes available on the stream.
 
bool isReadable () const noexcept override
 Checks if the stream is readable.
 
size_t read (void *data, const size_t n) override
 Reads data from the data stream to a buffer of raw memory data with length n.
 
bool invalidate () override
 In the stream is buffered, invalidates any buffered read data from the stream.
 
bool isWritable () const noexcept override
 Checks if the stream is writable.
 
size_t write (const void *data, const size_t n) override
 Writes data to the data stream from a buffer of raw memory data with length n.
 
bool flush () override
 In the stream is buffered, invalidates any buffered write data from to stream.
 
- Public Member Functions inherited from CeresEngine::IInputStream
template<typename T >
size_t read (const MemoryView< T > &memoryView)
 Reads data from the strea into a memory view.
 
template<typename T >
size_t read (const StridedMemoryView< T > &memoryView)
 Reads data from the stream into a strided memory view.
 
Optional< StringreadString ()
 Reads data from the buffer as a C++ String.
 
template<typename T >
requires std::is_trivially_copyable_v<T>
Optional< Tread ()
 Reads a trivially copyable obhect from the stream.
 
- Public Member Functions inherited from CeresEngine::IStream
 IStream ()=default
 
 IStream (const IStream &) noexcept=delete
 
IStreamoperator= (const IStream &) noexcept=delete
 
 IStream (IStream &&) noexcept=default
 
IStreamoperator= (IStream &&) noexcept=default
 
virtual ~IStream () noexcept=default
 
void skip (const size_t n)
 Skips n bytes from the data stream.
 
- Public Member Functions inherited from CeresEngine::IOutputStream
template<typename T >
size_t write (const MemoryView< const T > &memoryView)
 Writes data from a memory view to the stream.
 
template<typename T >
size_t write (const StridedMemoryView< const T > &memoryView)
 Writes data from a strided memory view to the stream.
 
size_t writeString (const StringView string)
 Writes a string to the data stream.
 
template<typename T >
requires std::is_trivially_copyable_v<T>
bool write (T value)
 Writes a trivially copyable object to the stream.
 

Static Public Member Functions

static BufferedDataStream createReadBufferedStream (DataStream &&dataStream, const size_t readBufferSize=1024)
 Creates a new buffered DataStream that only buffers read operations.
 
static BufferedDataStream createWriteBufferedStream (DataStream &&dataStream, const size_t writeBufferSize=1024)
 Creates a new buffered DataStream that only buffers write operations.
 

Private Types

using super = FilteredDataStream
 

Private Member Functions

void invalidateReadBuffer ()
 
void flushWriteBuffer ()
 

Private Attributes

size_t mPosition = 0
 The current stream position.
 
voidmReadBuffer = nullptr
 A pointer to the read buffer memory.
 
const size_t mReadBufferSize = 0
 The size of the allocated read buffer.
 
TRange< size_tmReadBufferRange
 The current read buffer range.
 
voidmWriteBuffer = nullptr
 A pointer to the write buffer memory.
 
const size_t mWriteBufferSize = 0
 The size of the allocated write buffer.
 
TRange< size_tmWriteBufferRange
 The current write buffer range.
 

Additional Inherited Members

- Public Types inherited from CeresEngine::IStream
enum class  Seek { Start = SEEK_SET , Current = SEEK_CUR , End = SEEK_END }
 An enumeration that describes how a data stream should be seeked. More...
 
- Protected Attributes inherited from CeresEngine::FilteredDataStream
DataStream mDataStream
 The data stream being filtered.
 

Detailed Description

A filtered DataStream that caches read and write operations to it's underlying DataStream.

Member Typedef Documentation

◆ super

Constructor & Destructor Documentation

◆ BufferedDataStream() [1/3]

CeresEngine::BufferedDataStream::BufferedDataStream ( DataStream &&  dataStream,
size_t  readBufferSize = 1024,
size_t  writeBufferSize = 1024 
)
explicit

Creates a new buffer data stream.

Parameters
sizeSize of the memory chunk in bytes.

◆ BufferedDataStream() [2/3]

CeresEngine::BufferedDataStream::BufferedDataStream ( const BufferedDataStream )
delete

◆ BufferedDataStream() [3/3]

CeresEngine::BufferedDataStream::BufferedDataStream ( BufferedDataStream &&  )
noexcept

◆ ~BufferedDataStream()

CeresEngine::BufferedDataStream::~BufferedDataStream ( )
final

Destroys the buffered data stream.

Member Function Documentation

◆ createReadBufferedStream()

static BufferedDataStream CeresEngine::BufferedDataStream::createReadBufferedStream ( DataStream &&  dataStream,
const size_t  readBufferSize = 1024 
)
inlinestatic

Creates a new buffered DataStream that only buffers read operations.

Writes are pass-through operations.

Parameters
dataStreamThe data stream to be buffered.
readBufferSizeThe size of the read buffers to be kept internally. All reads performed using this stream will be of this size.

◆ createWriteBufferedStream()

static BufferedDataStream CeresEngine::BufferedDataStream::createWriteBufferedStream ( DataStream &&  dataStream,
const size_t  writeBufferSize = 1024 
)
inlinestatic

Creates a new buffered DataStream that only buffers write operations.

Reads are pass-through operations.

Parameters
dataStreamThe data stream to be buffered.
writeBufferSizeThe size of the write buffers to be kept internally. All writes performed using this stream will be of this size.

◆ flush()

bool CeresEngine::BufferedDataStream::flush ( )
finalvirtual

In the stream is buffered, invalidates any buffered write data from to stream.

Non-buffered streams are free to ignore this method.

Returns
True if the flushing finished successfully; false otherwise.

Reimplemented from CeresEngine::IOutputStream.

◆ flushWriteBuffer()

void CeresEngine::BufferedDataStream::flushWriteBuffer ( )
private

◆ invalidate()

bool CeresEngine::BufferedDataStream::invalidate ( )
finalvirtual

In the stream is buffered, invalidates any buffered read data from the stream.

Non-buffered streams are free to ignore this method.

Returns
True if the invalidation finished successfully; false otherwise.

Reimplemented from CeresEngine::IInputStream.

◆ invalidateReadBuffer()

void CeresEngine::BufferedDataStream::invalidateReadBuffer ( )
private

◆ isTellable()

bool CeresEngine::BufferedDataStream::isTellable ( ) const
inlinefinalvirtualnoexcept

Checks if the stream knows it's current absolute position.

If this method returns true, tell() is safe to be called on this stream.

Reimplemented from CeresEngine::IStream.

◆ read()

size_t CeresEngine::BufferedDataStream::read ( void data,
size_t  n 
)
finalvirtual

Reads data from the data stream to a buffer of raw memory data with length n.

Note
This method is only callable if isReadable() returns true.
Parameters
dataThe memory location to which read data should be placed.
nThe maximum number of bytes to be read from the data stream.
Returns
The number of bytes actually read. Can be smaller than n. If 0, indicates that the stream has ended.

Reimplemented from CeresEngine::IInputStream.

◆ seek()

void CeresEngine::BufferedDataStream::seek ( std::streamsize  position,
Seek  mode = Seek::Start 
)
finalvirtual

Changes the position of the data stream.

Note
This method is only callable if isSeekable() returns true.
Parameters
positionThe position to set the data stream to.
modeThe mode to change the data stream position.

Reimplemented from CeresEngine::IStream.

◆ tell()

size_t CeresEngine::BufferedDataStream::tell ( )
inlinefinalvirtual

Gets the absolute stream position, in bytes.

Note
This method is only callable if isTellable() returns true.

Reimplemented from CeresEngine::IStream.

◆ write()

size_t CeresEngine::BufferedDataStream::write ( const void data,
size_t  n 
)
finalvirtual

Writes data to the data stream from a buffer of raw memory data with length n.

Note
This method is only callable if isWritable() returns true.
Parameters
dataThe memory location to which written data should be copied from.
nThe maximum number of bytes to be write to the data stream.
Returns
The number of bytes actually written. Can be smaller than n, in that case the write operation must be repeated to ensure that all data was written. If 0, indicates that the stream has ended.

Reimplemented from CeresEngine::IOutputStream.

Member Data Documentation

◆ mPosition

size_t CeresEngine::BufferedDataStream::mPosition = 0
private

The current stream position.

◆ mReadBuffer

void* CeresEngine::BufferedDataStream::mReadBuffer = nullptr
private

A pointer to the read buffer memory.

Can be null if read operations are unbuffered.

◆ mReadBufferRange

TRange<size_t> CeresEngine::BufferedDataStream::mReadBufferRange
private

The current read buffer range.

This represents the range of data that is available in mReadBuffer.

◆ mReadBufferSize

const size_t CeresEngine::BufferedDataStream::mReadBufferSize = 0
private

The size of the allocated read buffer.

◆ mWriteBuffer

void* CeresEngine::BufferedDataStream::mWriteBuffer = nullptr
private

A pointer to the write buffer memory.

Can be null if write operations are unbuffered.

◆ mWriteBufferRange

TRange<size_t> CeresEngine::BufferedDataStream::mWriteBufferRange
private

The current write buffer range.

This represents the range of data that is pending a flush.

◆ mWriteBufferSize

const size_t CeresEngine::BufferedDataStream::mWriteBufferSize = 0
private

The size of the allocated write buffer.


The documentation for this class was generated from the following file: