Devel Lib
Devel::IO::CReadStream Class Reference

A class for reading data from a buffer. This class provides functionality to read data from a buffer. It allows reading strings, raw data, and numeric values from the buffer. Example More...

#include <ReadStream.h>

Public Member Functions

 CReadStream ()
 Default constructor for CReadStream. More...
 
 CReadStream (const char *i_pBuffer, const size_t i_nSize, const bool i_fCopyBuffer)
 Constructor for CReadStream with a buffer. More...
 
 CReadStream (const CReadStream &i_oOther)
 Copy constructor for CReadStream. More...
 
 CReadStream (CReadStream &&i_oOther) noexcept
 Move constructor for CReadStream. More...
 
virtual ~CReadStream ()=default
 Destructor for CReadStream.
 
void setBuffer (const char *i_pBuffer, size_t i_nSize, bool i_fCopyBuffer=false)
 Sets the buffer for the CReadStream. More...
 
void setPosition (const size_t i_nPosition)
 Sets the current position of the CReadStream. More...
 
void seek (const size_t i_nBytes)
 Moves the current position of the CReadStream. More...
 
void clear ()
 Clears the CReadStream.
 
const char * buffer () const
 Returns the buffer of the CReadStream. More...
 
size_t size () const
 Returns the size of the buffer. More...
 
size_t position () const
 Returns the current position of the CReadStream. More...
 
size_t leftBytes (const size_t i_nPosition) const
 Returns the number of bytes left from the current position to the end of the buffer. More...
 
size_t leftBytes () const
 Returns the number of bytes left from the current position to the end of the buffer. More...
 
bool isEndOfBuffer () const
 Checks if the current position is at the end of the buffer. More...
 
bool isEoB () const
 Checks if the current position is at the end of the buffer. More...
 
std::string getString (const size_t i_nPosition, const size_t i_nLength, const bool i_fIsZeroTerminated, const bool i_fSetPosition)
 Reads a string from the buffer. More...
 
std::string getString (const size_t i_nPosition, const size_t i_nLength, const bool i_fSetPosition=true)
 Reads a string from the buffer. More...
 
std::string getString (const size_t i_nLength, const bool i_fSetPosition=true)
 Reads a string from the buffer. More...
 
std::string getString (const bool i_fSetPosition=true)
 Reads a null-terminated string from the buffer. More...
 
std::wstring getWString (const size_t i_nPosition, const size_t i_nLength, const bool i_fIsZeroTerminated, const bool i_fSetPosition)
 Reads a wide string from the buffer. More...
 
std::wstring getWString (const size_t i_nPosition, const size_t i_nLength, const bool i_fSetPosition=true)
 Reads a wide string from the buffer. More...
 
std::wstring getWString (const size_t i_nLength, const bool i_fSetPosition=true)
 Reads a wide string from the buffer. More...
 
std::wstring getWString (const bool i_fSetPosition=true)
 Reads a null-terminated wide string from the buffer. More...
 
void getRaw (void *i_pDestination, size_t i_nReadBytes, size_t i_nPosition, bool i_fSetPosition)
 Reads raw data from the buffer. More...
 
void getRaw (void *i_pDestination, const size_t i_nReadBytes, const bool i_fSetPosition)
 Reads raw data from the buffer. More...
 
void getRaw (void *i_pDestination, const size_t i_nReadBytes)
 Reads raw data from the buffer. More...
 
template<typename T , typename std::enable_if_t< std::is_arithmetic_v< T >> * = nullptr>
get (const size_t i_nPosition, const bool i_fSetPosition)
 Reads a value of type T from the buffer. More...
 
template<typename T , typename std::enable_if_t< std::is_arithmetic_v< T >> * = nullptr>
get (const size_t i_nPosition)
 Reads a value of type T from the buffer. More...
 
template<typename T , typename std::enable_if_t< std::is_arithmetic_v< T >> * = nullptr>
get ()
 Reads a value of type T from the buffer. More...
 
template<typename T , typename std::enable_if_t< std::is_enum_v< T >> * = nullptr>
get (const size_t i_nPosition)
 Reads an enum value from the buffer. More...
 
template<typename T , typename std::enable_if_t< std::is_enum_v< T >> * = nullptr>
get ()
 Reads an enum value from the buffer. More...
 
template<size_t TSize>
CCharArray< TSize > getArray (const size_t i_nPosition, const bool i_fSetPosition)
 Reads an array from the buffer. More...
 
template<size_t TSize>
CCharArray< TSize > getArray ()
 Reads an array from the buffer. More...
 
const char & operator[] (const size_t i_nIndex) const
 Overload of the subscript operator. More...
 
CReadStreamoperator= (const CReadStream &i_oOther)
 Assignment operator. More...
 
CReadStreamoperator= (CReadStream &&i_oOther) noexcept
 Move assignment operator. More...
 

Detailed Description

A class for reading data from a buffer. This class provides functionality to read data from a buffer. It allows reading strings, raw data, and numeric values from the buffer. Example

// Create a buffer
const char* buffer = "Hello, World!";
size_t bufferSize = strlen(buffer) + 1; // Including the null terminator
// Create a read stream
Devel::IO::CReadStream stream(buffer, bufferSize);
// Read a string from the stream
std::string str = stream.getString();
std::cout << "String: " << str << std::endl;
// Read raw data from the stream
char rawData[6];
stream.getRaw(rawData, 6);
std::cout << "Raw Data: ";
for (int i = 0; i < 6; ++i) {
std::cout << rawData[i];
}
std::cout << std::endl;
// Read a numeric value from the stream
int num = stream.get<int>();
std::cout << "Numeric Value: " << num << std::endl;
A class for reading data from a buffer. This class provides functionality to read data from a buffer....
Definition: ReadStream.h:37
const char * buffer() const
Returns the buffer of the CReadStream.
Definition: ReadStream.h:145

Constructor & Destructor Documentation

◆ CReadStream() [1/4]

Devel::IO::CReadStream::CReadStream ( )
inline

Default constructor for CReadStream.

Initializes an empty CReadStream.

◆ CReadStream() [2/4]

Devel::IO::CReadStream::CReadStream ( const char *  i_pBuffer,
const size_t  i_nSize,
const bool  i_fCopyBuffer 
)
inline

Constructor for CReadStream with a buffer.

Parameters
i_pBuffer- The buffer to read data from.
i_nSize- The size of the buffer.
i_fCopyBuffer- Whether to make a copy of the buffer or use it directly.

◆ CReadStream() [3/4]

Devel::IO::CReadStream::CReadStream ( const CReadStream i_oOther)
inline

Copy constructor for CReadStream.

Parameters
i_oOther- The CReadStream to copy.

◆ CReadStream() [4/4]

Devel::IO::CReadStream::CReadStream ( CReadStream &&  i_oOther)
inlinenoexcept

Move constructor for CReadStream.

Parameters
i_oOther- The CReadStream to move.

Member Function Documentation

◆ buffer()

const char* Devel::IO::CReadStream::buffer ( ) const
inline

Returns the buffer of the CReadStream.

Returns
The buffer of the CReadStream.

◆ get() [1/5]

template<typename T , typename std::enable_if_t< std::is_arithmetic_v< T >> * = nullptr>
T Devel::IO::CReadStream::get ( )
inline

Reads a value of type T from the buffer.

Template Parameters
T- The type of the value to read.
Returns
The value read from the buffer.

◆ get() [2/5]

template<typename T , typename std::enable_if_t< std::is_enum_v< T >> * = nullptr>
T Devel::IO::CReadStream::get ( )
inline

Reads an enum value from the buffer.

Template Parameters
T- The enum type.
Returns
The enum value read from the buffer.

◆ get() [3/5]

template<typename T , typename std::enable_if_t< std::is_arithmetic_v< T >> * = nullptr>
T Devel::IO::CReadStream::get ( const size_t  i_nPosition)
inline

Reads a value of type T from the buffer.

Template Parameters
T- The type of the value to read.
Parameters
i_nPosition- The position in the buffer to start reading from.
Returns
The value read from the buffer.

◆ get() [4/5]

template<typename T , typename std::enable_if_t< std::is_enum_v< T >> * = nullptr>
T Devel::IO::CReadStream::get ( const size_t  i_nPosition)
inline

Reads an enum value from the buffer.

Template Parameters
T- The enum type.
Parameters
i_nPosition- The position in the buffer to start reading from.
Returns
The enum value read from the buffer.

◆ get() [5/5]

template<typename T , typename std::enable_if_t< std::is_arithmetic_v< T >> * = nullptr>
T Devel::IO::CReadStream::get ( const size_t  i_nPosition,
const bool  i_fSetPosition 
)
inline

Reads a value of type T from the buffer.

Template Parameters
T- The type of the value to read.
Parameters
i_nPosition- The position in the buffer to start reading from.
i_fSetPosition- Whether to set the current position after reading the value.
Returns
The value read from the buffer.

◆ getArray() [1/2]

template<size_t TSize>
CCharArray<TSize> Devel::IO::CReadStream::getArray ( )
inline

Reads an array from the buffer.

Template Parameters
TSize- The size of the array.
Returns
The array read from the buffer.

◆ getArray() [2/2]

template<size_t TSize>
CCharArray<TSize> Devel::IO::CReadStream::getArray ( const size_t  i_nPosition,
const bool  i_fSetPosition 
)
inline

Reads an array from the buffer.

Template Parameters
TSize- The size of the array.
Parameters
i_nPosition- The position in the buffer to start reading from.
i_fSetPosition- Whether to set the current position after reading the array.
Returns
The array read from the buffer.

◆ getRaw() [1/3]

void Devel::IO::CReadStream::getRaw ( void *  i_pDestination,
const size_t  i_nReadBytes 
)
inline

Reads raw data from the buffer.

Parameters
i_pDestination- The destination buffer to copy the raw data to.
i_nReadBytes- The number of bytes to read.

◆ getRaw() [2/3]

void Devel::IO::CReadStream::getRaw ( void *  i_pDestination,
const size_t  i_nReadBytes,
const bool  i_fSetPosition 
)
inline

Reads raw data from the buffer.

Parameters
i_pDestination- The destination buffer to copy the raw data to.
i_nReadBytes- The number of bytes to read.
i_fSetPosition- Whether to set the current position after reading the raw data.

◆ getRaw() [3/3]

void Devel::IO::CReadStream::getRaw ( void *  i_pDestination,
size_t  i_nReadBytes,
size_t  i_nPosition,
bool  i_fSetPosition 
)

Reads raw data from the buffer.

Parameters
i_pDestination- The destination buffer to copy the raw data to.
i_nReadBytes- The number of bytes to read.
i_nPosition- The position in the buffer to start reading from.
i_fSetPosition- Whether to set the current position after reading the raw data.

◆ getString() [1/4]

std::string Devel::IO::CReadStream::getString ( const bool  i_fSetPosition = true)
inline

Reads a null-terminated string from the buffer.

Parameters
i_fSetPosition- Whether to set the current position after reading the string.
Returns
The string read from the buffer.

◆ getString() [2/4]

std::string Devel::IO::CReadStream::getString ( const size_t  i_nLength,
const bool  i_fSetPosition = true 
)
inline

Reads a string from the buffer.

Parameters
i_nLength- The length of the string to read.
i_fSetPosition- Whether to set the current position after reading the string.
Returns
The string read from the buffer.

◆ getString() [3/4]

std::string Devel::IO::CReadStream::getString ( const size_t  i_nPosition,
const size_t  i_nLength,
const bool  i_fIsZeroTerminated,
const bool  i_fSetPosition 
)
inline

Reads a string from the buffer.

Parameters
i_nPosition- The position in the buffer to start reading from.
i_nLength- The length of the string to read.
i_fIsZeroTerminated- Whether the string is zero-terminated.
i_fSetPosition- Whether to set the current position after reading the string.
Returns
The string read from the buffer.

◆ getString() [4/4]

std::string Devel::IO::CReadStream::getString ( const size_t  i_nPosition,
const size_t  i_nLength,
const bool  i_fSetPosition = true 
)
inline

Reads a string from the buffer.

Parameters
i_nPosition- The position in the buffer to start reading from.
i_nLength- The length of the string to read.
i_fSetPosition- Whether to set the current position after reading the string.
Returns
The string read from the buffer.

◆ getWString() [1/4]

std::wstring Devel::IO::CReadStream::getWString ( const bool  i_fSetPosition = true)
inline

Reads a null-terminated wide string from the buffer.

Parameters
i_fSetPosition- Whether to set the current position after reading the wide string.
Returns
The wide string read from the buffer.

◆ getWString() [2/4]

std::wstring Devel::IO::CReadStream::getWString ( const size_t  i_nLength,
const bool  i_fSetPosition = true 
)
inline

Reads a wide string from the buffer.

Parameters
i_nLength- The length of the wide string to read.
i_fSetPosition- Whether to set the current position after reading the wide string.
Returns
The wide string read from the buffer.

◆ getWString() [3/4]

std::wstring Devel::IO::CReadStream::getWString ( const size_t  i_nPosition,
const size_t  i_nLength,
const bool  i_fIsZeroTerminated,
const bool  i_fSetPosition 
)
inline

Reads a wide string from the buffer.

Parameters
i_nPosition- The position in the buffer to start reading from.
i_nLength- The length of the wide string to read.
i_fIsZeroTerminated- Whether the wide string is zero-terminated.
i_fSetPosition- Whether to set the current position after reading the wide string.
Returns
The wide string read from the buffer.

◆ getWString() [4/4]

std::wstring Devel::IO::CReadStream::getWString ( const size_t  i_nPosition,
const size_t  i_nLength,
const bool  i_fSetPosition = true 
)
inline

Reads a wide string from the buffer.

Parameters
i_nPosition- The position in the buffer to start reading from.
i_nLength- The length of the wide string to read.
i_fSetPosition- Whether to set the current position after reading the wide string.
Returns
The wide string read from the buffer.

◆ isEndOfBuffer()

bool Devel::IO::CReadStream::isEndOfBuffer ( ) const
inline

Checks if the current position is at the end of the buffer.

Returns
True if the current position is at the end of the buffer, false otherwise.

◆ isEoB()

bool Devel::IO::CReadStream::isEoB ( ) const
inline

Checks if the current position is at the end of the buffer.

Returns
True if the current position is at the end of the buffer, false otherwise.

◆ leftBytes() [1/2]

size_t Devel::IO::CReadStream::leftBytes ( ) const
inline

Returns the number of bytes left from the current position to the end of the buffer.

Returns
The number of bytes left from the current position to the end of the buffer.

◆ leftBytes() [2/2]

size_t Devel::IO::CReadStream::leftBytes ( const size_t  i_nPosition) const
inline

Returns the number of bytes left from the current position to the end of the buffer.

Parameters
i_nPosition- The position to calculate the number of bytes from.
Returns
The number of bytes left from the current position to the end of the buffer.

◆ operator=() [1/2]

CReadStream& Devel::IO::CReadStream::operator= ( const CReadStream i_oOther)
inline

Assignment operator.

Parameters
i_oOther- The CReadStream to assign.
Returns
A reference to the assigned CReadStream.

◆ operator=() [2/2]

CReadStream& Devel::IO::CReadStream::operator= ( CReadStream &&  i_oOther)
inlinenoexcept

Move assignment operator.

Parameters
i_oOther- The CReadStream to move.
Returns
A reference to the moved CReadStream.

◆ operator[]()

const char& Devel::IO::CReadStream::operator[] ( const size_t  i_nIndex) const
inline

Overload of the subscript operator.

Parameters
i_nIndex- The index in the buffer.
Returns
The character at the specified index in the buffer.

◆ position()

size_t Devel::IO::CReadStream::position ( ) const
inline

Returns the current position of the CReadStream.

Returns
The current position of the CReadStream.

◆ seek()

void Devel::IO::CReadStream::seek ( const size_t  i_nBytes)
inline

Moves the current position of the CReadStream.

Parameters
i_nBytes- The number of bytes to move the position.

◆ setBuffer()

void Devel::IO::CReadStream::setBuffer ( const char *  i_pBuffer,
size_t  i_nSize,
bool  i_fCopyBuffer = false 
)

Sets the buffer for the CReadStream.

Parameters
i_pBuffer- The buffer to set.
i_nSize- The size of the buffer.
i_fCopyBuffer- Whether to make a copy of the buffer or use it directly.

◆ setPosition()

void Devel::IO::CReadStream::setPosition ( const size_t  i_nPosition)
inline

Sets the current position of the CReadStream.

Parameters
i_nPosition- The position to set.

◆ size()

size_t Devel::IO::CReadStream::size ( ) const
inline

Returns the size of the buffer.

Returns
The size of the buffer.

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