CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
CeresEngine::BinaryWriter 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

 BinaryWriter (OutputStream outputStream)
 
 BinaryWriter (IOutputStream &outputStream)
 
template<typename T , typename... Args>
void write (const T &value, Args &&... args)
 Writes a binary representation of T to the stream.
 
template<typename T , typename... Args>
bool tryWrite (const T &value, Args &&... args)
 Tries to write a data type to the stream.
 
size_t write (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.
 
void seek (const std::streamsize position, const Seek mode=Seek::Start)
 Changes the position of the data stream.
 
void 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.
 
size_t tell ()
 Gets the absolute stream position, in bytes.
 
bool isSizeKnown () const noexcept
 Checks if the stream knows the size of the data.
 
size_t size ()
 Gets the number of bytes available on the stream.
 
OutputStreamgetOutputStream ()
 The output stream to which data will be written to.
 
const OutputStreamgetOutputStream () const
 The output stream to which data will be written to.
 

Private Attributes

OutputStream 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

◆ BinaryWriter() [1/2]

CeresEngine::BinaryWriter::BinaryWriter ( OutputStream  outputStream)
inlineexplicit

◆ BinaryWriter() [2/2]

CeresEngine::BinaryWriter::BinaryWriter ( IOutputStream outputStream)
inlineexplicit

Member Function Documentation

◆ getOutputStream() [1/2]

OutputStream & CeresEngine::BinaryWriter::getOutputStream ( )
inline

The output stream to which data will be written to.

◆ getOutputStream() [2/2]

const OutputStream & CeresEngine::BinaryWriter::getOutputStream ( ) const
inline

The output stream to which data will be written to.

◆ isSeekable()

bool CeresEngine::BinaryWriter::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::BinaryWriter::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::BinaryWriter::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()

void CeresEngine::BinaryWriter::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()

size_t CeresEngine::BinaryWriter::size ( )
inline

Gets the number of bytes available on the stream.

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

◆ skip()

void CeresEngine::BinaryWriter::skip ( const size_t  n)
inline

Skips n bytes from the data stream.

◆ tell()

size_t CeresEngine::BinaryWriter::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>
bool CeresEngine::BinaryWriter::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>
void CeresEngine::BinaryWriter::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]

size_t CeresEngine::BinaryWriter::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

OutputStream CeresEngine::BinaryWriter::mOutputStream
private

The output stream to which data will be written to.


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