RLLib  0.1
Public Member Functions | List of all members
rl::ByteStream Class Reference

This class represents a data stream containing a variable number of bytes. More...

#include <ByteStream.hpp>

Public Member Functions

 ByteStream ()=default
 Creates an empty data stream.
 
 ByteStream (std::size_t size)
 Creates a data stream containing a specific number of bytes. More...
 
std::size_t size () const noexcept
 Returns the number of bytes in the data stream. More...
 
void resize (std::size_t size)
 Sets the number of bytes in the data stream. More...
 
Byte * data () noexcept
 Returns a raw pointer to the first byte. More...
 
const Byte * data () const noexcept
 Returns a raw pointer to the first byte (const). More...
 
std::vector< Byte >::iterator begin () noexcept
 
std::vector< Byte >::const_iterator cbegin () const noexcept
 
std::vector< Byte >::iterator end () noexcept
 
std::vector< Byte >::const_iterator cend () const noexcept
 
std::size_t tell () const noexcept
 Returns the position of the stream cursor. More...
 
void seek (std::size_t pos) noexcept
 Sets the position of the stream cursor. More...
 
template<typename T , EnableIfNumeric< T > * = nullptr>
get ()
 Reads an numeric value from the stream. More...
 
template<typename T , EnableIfSerializable< T > * = nullptr>
get ()
 Extracts an serializable object from the stream. More...
 
template<typename T , EnableIfArray< T > * = nullptr>
get ()
 Reads an array from the stream. More...
 
template<typename T , EnableIfByteStream< T > * = nullptr>
get ()
 Reads raw data from the stream. More...
 
template<typename T >
get (std::size_t pos)
 Reads a value from a specific position in the stream. More...
 
template<typename T >
ByteStreamoperator>> (T &value)
 Reads a value from the stream and stores it into a variable. More...
 
template<typename T , EnableIfNumeric< T > * = nullptr>
void put (const T &value)
 Writes an arithmetic value into the stream. More...
 
template<typename T , EnableIfSerializable< T > * = nullptr>
void put (const T &value)
 Serializes an object into the stream. More...
 
template<typename T , EnableIfArray< T > * = nullptr>
void put (const T &value)
 Writes a array into the stream. More...
 
void put (const char *value)
 Writes a string into the stream. More...
 
void put (const ByteStream &value)
 Writes raw data into the stream. More...
 
template<typename T >
void put (const T &value, std::size_t pos)
 Writes a value into a specific position in the stream. More...
 
template<typename T >
ByteStreamoperator<< (const T &value)
 Writes a value into the stream. More...
 

Detailed Description

This class represents a data stream containing a variable number of bytes.

It provides features to extract and write values from and into the stream.

Constructor & Destructor Documentation

◆ ByteStream()

rl::ByteStream::ByteStream ( std::size_t  size)
explicit

Creates a data stream containing a specific number of bytes.

Parameters
sizeThe initial number of bytes in the data stream

Member Function Documentation

◆ begin()

std::vector<Byte>::iterator rl::ByteStream::begin ( )
noexcept
Returns
An iterator pointing to the first byte

◆ cbegin()

std::vector<Byte>::const_iterator rl::ByteStream::cbegin ( ) const
noexcept
Returns
An iterator pointing to the first byte (const)

◆ cend()

std::vector<Byte>::const_iterator rl::ByteStream::cend ( ) const
noexcept
Returns
An iterator pointing to the last byte (const)

◆ data() [1/2]

Byte* rl::ByteStream::data ( )
noexcept

Returns a raw pointer to the first byte.

Returns
The pointer to the first byte

◆ data() [2/2]

const Byte* rl::ByteStream::data ( ) const
noexcept

Returns a raw pointer to the first byte (const).

Returns
The pointer to the first byte (const)

◆ end()

std::vector<Byte>::iterator rl::ByteStream::end ( )
noexcept
Returns
An iterator pointing to the last byte

◆ get() [1/5]

template<typename T , EnableIfByteStream< T > * >
T rl::ByteStream::get ( )

Reads an numeric value from the stream.

If the data to read is out of bound, the behavior is undefined.

Template Parameters
TThe type of the numeric value
Returns
The value extracted from the stream

◆ get() [2/5]

template<typename T , EnableIfSerializable< T > * = nullptr>
T rl::ByteStream::get ( )

Extracts an serializable object from the stream.

If the data to read is out of bound, the behavior is undefined.

Template Parameters
TThe type of the serializable object
Returns
The object deserialized from the stream

◆ get() [3/5]

template<typename T , EnableIfArray< T > * = nullptr>
T rl::ByteStream::get ( )

Reads an array from the stream.

If the data to read is out of bound, the behavior is undefined.

Template Parameters
TThe type of the array
Returns
The array extracted from the stream

◆ get() [4/5]

template<typename T , EnableIfByteStream< T > * = nullptr>
T rl::ByteStream::get ( )

Reads raw data from the stream.

If the data to read is out of bound, the behavior is undefined.

Template Parameters
TThe type of the raw data
Returns
The data extracted from the stream

◆ get() [5/5]

template<typename T >
T rl::ByteStream::get ( std::size_t  pos)

Reads a value from a specific position in the stream.

If the data to read is out of bound, the behavior is undefined.

Template Parameters
TThe type of the value that is to be read
Parameters
posThe position of the stream cursor
Returns
The value extracted from the stream

◆ operator<<()

template<typename T >
ByteStream & rl::ByteStream::operator<< ( const T &  value)

Writes a value into the stream.

Template Parameters
T
Parameters
value
Returns

◆ operator>>()

template<typename T >
ByteStream & rl::ByteStream::operator>> ( T &  value)

Reads a value from the stream and stores it into a variable.

If the data to read is out of bound, the behavior is undefined.

Template Parameters
TThe type of the value that is to be read
Parameters
valueA reference to the variable where the result will be stored
Returns
The current data stream

◆ put() [1/6]

template<typename T , EnableIfArray< T > * >
void rl::ByteStream::put ( const T &  value)

Writes an arithmetic value into the stream.

Parameters
valueThe value that is to be written

◆ put() [2/6]

template<typename T , EnableIfSerializable< T > * = nullptr>
void rl::ByteStream::put ( const T &  value)

Serializes an object into the stream.

Parameters
valueThe serializable object that is to be written

◆ put() [3/6]

template<typename T , EnableIfArray< T > * = nullptr>
void rl::ByteStream::put ( const T &  value)

Writes a array into the stream.

Parameters
valueThe array that is to be written

◆ put() [4/6]

void rl::ByteStream::put ( const char *  value)

Writes a string into the stream.

Parameters
valueThe string that is to be written

◆ put() [5/6]

void rl::ByteStream::put ( const ByteStream value)

Writes raw data into the stream.

Parameters
valueA byte stream containing the data

◆ put() [6/6]

template<typename T >
void rl::ByteStream::put ( const T &  value,
std::size_t  pos 
)

Writes a value into a specific position in the stream.

Template Parameters
TThe type of the value that is to be written
Parameters
valueThe value that is to be written
posThe position of the stream cursor

◆ resize()

void rl::ByteStream::resize ( std::size_t  size)

Sets the number of bytes in the data stream.

Parameters
sizeThe number of bytes

◆ seek()

void rl::ByteStream::seek ( std::size_t  pos)
noexcept

Sets the position of the stream cursor.

Parameters
posThe new stream position

◆ size()

std::size_t rl::ByteStream::size ( ) const
noexcept

Returns the number of bytes in the data stream.

Returns
The number of bytes

◆ tell()

std::size_t rl::ByteStream::tell ( ) const
noexcept

Returns the position of the stream cursor.

Returns
The stream position

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