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

A writer that writes data to an underlying output stream as binary data. More...

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

Public Types

using Seek = Stream::Seek
 

Public Member Functions

 AsyncBinaryWriter (AsyncOutputStream outputStream)
 
 AsyncBinaryWriter (IAsyncOutputStream &outputStream)
 
template<typename T , typename... Args>
Async write (const T &value, Args &&... args)
 Writes a binary representation of T to the stream.
 
template<typename T , typename... Args>
Async< booltryWrite (const T &value, Args &&... args)
 Tries to write a data type to the stream.
 
Async< size_twrite (const void *data, const size_t n)
 Writes data to the data stream from a buffer of raw memory data with length n.
 
bool isSeekable (const Seek mode=Seek::Start) const noexcept
 Checks if the stream is seekable.
 
Async seek (const std::streamsize position, const Seek mode=Seek::Start)
 Changes the position of the data stream.
 
Async skip (const size_t n)
 Skips n bytes from the data stream.
 
bool isTellable () const noexcept
 Checks if the stream knows it's current absolute position.
 
Async< size_ttell ()
 Gets the absolute stream position, in bytes.
 
bool isSizeKnown () const noexcept
 Checks if the stream knows the size of the data.
 
Async< size_tsize ()
 Gets the number of bytes available on the stream.
 
AsyncOutputStreamgetOutputStream ()
 The output stream to which data will be written to.
 
const AsyncOutputStreamgetOutputStream () const
 The output stream to which data will be written to.
 

Private Attributes

AsyncOutputStream mOutputStream
 The output stream to which data will be written to.
 

Detailed Description

A writer that writes data to an underlying output stream as binary data.

Member Typedef Documentation

◆ Seek

Constructor & Destructor Documentation

◆ AsyncBinaryWriter() [1/2]

CeresEngine::AsyncBinaryWriter::AsyncBinaryWriter ( AsyncOutputStream  outputStream)
inlineexplicit

◆ AsyncBinaryWriter() [2/2]

CeresEngine::AsyncBinaryWriter::AsyncBinaryWriter ( IAsyncOutputStream outputStream)
inlineexplicit

Member Function Documentation

◆ getOutputStream() [1/2]

AsyncOutputStream & CeresEngine::AsyncBinaryWriter::getOutputStream ( )
inline

The output stream to which data will be written to.

◆ getOutputStream() [2/2]

const AsyncOutputStream & CeresEngine::AsyncBinaryWriter::getOutputStream ( ) const
inline

The output stream to which data will be written to.

◆ isSeekable()

bool CeresEngine::AsyncBinaryWriter::isSeekable ( const Seek  mode = Seek::Start) const
inlinenoexcept

Checks if the stream is seekable.

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

◆ isSizeKnown()

bool CeresEngine::AsyncBinaryWriter::isSizeKnown ( ) const
inlinenoexcept

Checks if the stream knows the size of the data.

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

◆ isTellable()

bool CeresEngine::AsyncBinaryWriter::isTellable ( ) const
inlinenoexcept

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

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

◆ seek()

Async CeresEngine::AsyncBinaryWriter::seek ( const std::streamsize  position,
const Seek  mode = Seek::Start 
)
inline

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.

◆ size()

Async< size_t > CeresEngine::AsyncBinaryWriter::size ( )
inline

Gets the number of bytes available on the stream.

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

◆ skip()

Async CeresEngine::AsyncBinaryWriter::skip ( const size_t  n)
inline

Skips n bytes from the data stream.

◆ tell()

Async< size_t > CeresEngine::AsyncBinaryWriter::tell ( )
inline

Gets the absolute stream position, in bytes.

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

◆ tryWrite()

template<typename T , typename... Args>
Async< bool > CeresEngine::AsyncBinaryWriter::tryWrite ( const T value,
Args &&...  args 
)
inline

Tries to write a data type to the stream.

If the write fails, returns false.

◆ write() [1/2]

template<typename T , typename... Args>
Async CeresEngine::AsyncBinaryWriter::write ( const T value,
Args &&...  args 
)
inline

Writes a binary representation of T to the stream.

Note
The actual encoding of the data is done by BinaryCodec.

◆ write() [2/2]

Async< size_t > CeresEngine::AsyncBinaryWriter::write ( const void data,
const size_t  n 
)
inline

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.

Member Data Documentation

◆ mOutputStream

AsyncOutputStream CeresEngine::AsyncBinaryWriter::mOutputStream
private

The output stream to which data will be written to.


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