Devel Lib
Devel::IO::CWriteStream Class Reference

A class for writing data to a buffer. This class provides functionality to write data to a buffer. It allows pushing strings, raw data, and numeric values to the buffer. More...

#include <WriteStream.h>

Public Member Functions

 CWriteStream ()
 Default constructor.
 
 CWriteStream (const size_t i_nSize)
 Constructor with initial size. More...
 
 CWriteStream (const CWriteStream &i_oOther)
 Copy constructor. More...
 
 CWriteStream (CWriteStream &&i_oWriteStream) noexcept
 Move constructor. More...
 
virtual ~CWriteStream ()
 Destructor.
 
void clear ()
 Clears the stream by setting the size to 0.
 
void reallocate (size_t i_nSize)
 Reallocates the buffer to the given size. More...
 
void push (const void *i_pBuffer, size_t i_nSize)
 Pushes the specified data to the buffer. More...
 
void push (const CWriteStream &i_oStream)
 Pushes the data from another CWriteStream to the buffer. More...
 
void push (const char *i_szString)
 Pushes a null-terminated string to the buffer. More...
 
void push (const std::string &i_oString, const bool i_fZeroTerminated=true)
 Pushes a std::string to the buffer. More...
 
void push (const std::wstring &i_oString, const bool i_fZeroTerminated=true)
 Pushes a std::wstring to the buffer. More...
 
template<typename T , typename std::enable_if_t< std::is_arithmetic_v< T >> * = nullptr>
void push (const T &i_oValue)
 Pushes a numeric value to the buffer. More...
 
template<typename T , typename std::enable_if_t< std::is_enum_v< T >> * = nullptr>
void push (const T &i_oValue)
 Pushes an enum value to the buffer. More...
 
template<size_t TSize>
void push (const CCharArray< TSize > &i_oValue, const bool i_bMaxLength=true)
 Pushes a CCharArray to the buffer. More...
 
void replace (const size_t i_nPosition, const void *i_pBuffer, const size_t i_nSize) const
 Replaces a portion of the buffer with the specified data. More...
 
void replace (const size_t i_nPosition, const CWriteStream &i_oStream) const
 Replaces a portion of the buffer with the data from another CWriteStream. More...
 
void replace (const size_t i_nPosition, const char *i_szString) const
 Replaces a portion of the buffer with a null-terminated string. More...
 
void replace (const size_t i_nPosition, const std::string &i_oString) const
 Replaces a portion of the buffer with a std::string. More...
 
template<typename T , typename std::enable_if_t< std::is_arithmetic_v< T >> * = nullptr>
void replace (const size_t i_nPosition, const T &i_oValue)
 Replaces a portion of the buffer with a numeric value. More...
 
template<typename T , typename std::enable_if_t< std::is_enum_v< T >> * = nullptr>
void replace (const size_t i_nPosition, const T &i_oValue)
 Replaces a portion of the buffer with an enum value. More...
 
size_t allocatedSize () const
 Gets the allocated size of the buffer. More...
 
size_t size () const
 Gets the current size of the buffer. More...
 
const char * buffer () const
 Gets a const pointer to the buffer. More...
 
CWriteStreamoperator= (const CWriteStream &i_oOther)
 Copy assignment operator. More...
 
CWriteStreamoperator= (CWriteStream &&i_oOther) noexcept
 Move assignment operator. More...
 

Detailed Description

A class for writing data to a buffer. This class provides functionality to write data to a buffer. It allows pushing strings, raw data, and numeric values to the buffer.

Example

// Create a write stream
// Push a string to the stream
stream.push("Hello, World!");
// Push raw data to the stream
char rawData[] = { 'R', 'a', 'w', 'D', 'a', 't', 'a' };
stream.push(rawData, sizeof(rawData));
// Push a numeric value to the stream
int num = 42;
stream.push(num);
// Get the buffer and its size
const char* buffer = stream.buffer();
size_t bufferSize = stream.size();
// Print the buffer
std::cout << "Buffer: ";
for (size_t i = 0; i < bufferSize; ++i) {
std::cout << buffer[i];
}
std::cout << std::endl;
A class for writing data to a buffer. This class provides functionality to write data to a buffer....
Definition: WriteStream.h:42
void push(const void *i_pBuffer, size_t i_nSize)
Pushes the specified data to the buffer.
Definition: WriteStream.cpp:30
const char * buffer() const
Gets a const pointer to the buffer.
Definition: WriteStream.h:234
size_t size() const
Gets the current size of the buffer.
Definition: WriteStream.h:228

Constructor & Destructor Documentation

◆ CWriteStream() [1/3]

Devel::IO::CWriteStream::CWriteStream ( const size_t  i_nSize)
inlineexplicit

Constructor with initial size.

Parameters
i_nSizeThe initial size of the buffer.

◆ CWriteStream() [2/3]

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

Copy constructor.

Parameters
i_oOtherThe CWriteStream object to be copied.

◆ CWriteStream() [3/3]

Devel::IO::CWriteStream::CWriteStream ( CWriteStream &&  i_oWriteStream)
inlinenoexcept

Move constructor.

Parameters
i_oWriteStreamThe CWriteStream object to be moved.

Member Function Documentation

◆ allocatedSize()

size_t Devel::IO::CWriteStream::allocatedSize ( ) const
inline

Gets the allocated size of the buffer.

Returns
The allocated size of the buffer.

◆ buffer()

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

Gets a const pointer to the buffer.

Returns
A const pointer to the buffer.

◆ operator=() [1/2]

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

Copy assignment operator.

Parameters
i_oOtherThe CWriteStream object to be assigned.
Returns
Reference to the assigned CWriteStream object.

◆ operator=() [2/2]

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

Move assignment operator.

Parameters
i_oOtherThe CWriteStream object to be moved.
Returns
Reference to the moved CWriteStream object.

◆ push() [1/8]

template<size_t TSize>
void Devel::IO::CWriteStream::push ( const CCharArray< TSize > &  i_oValue,
const bool  i_bMaxLength = true 
)
inline

Pushes a CCharArray to the buffer.

Template Parameters
TSizeThe size of the CCharArray.
Parameters
i_oValueThe CCharArray to be pushed.
i_bMaxLengthWhether to push the maximum length of the CCharArray or its current length.

◆ push() [2/8]

void Devel::IO::CWriteStream::push ( const char *  i_szString)
inline

Pushes a null-terminated string to the buffer.

Parameters
i_szStringThe null-terminated string to be pushed.

◆ push() [3/8]

void Devel::IO::CWriteStream::push ( const CWriteStream i_oStream)
inline

Pushes the data from another CWriteStream to the buffer.

Parameters
i_oStreamThe CWriteStream object to be pushed.

◆ push() [4/8]

void Devel::IO::CWriteStream::push ( const std::string &  i_oString,
const bool  i_fZeroTerminated = true 
)
inline

Pushes a std::string to the buffer.

Parameters
i_oStringThe std::string to be pushed.
i_fZeroTerminatedWhether to include a null-terminator at the end of the string.

◆ push() [5/8]

void Devel::IO::CWriteStream::push ( const std::wstring &  i_oString,
const bool  i_fZeroTerminated = true 
)
inline

Pushes a std::wstring to the buffer.

Parameters
i_oStringThe std::wstring to be pushed.
i_fZeroTerminatedWhether to include a null-terminator at the end of the string.

◆ push() [6/8]

template<typename T , typename std::enable_if_t< std::is_arithmetic_v< T >> * = nullptr>
void Devel::IO::CWriteStream::push ( const T &  i_oValue)
inline

Pushes a numeric value to the buffer.

Template Parameters
TThe type of the numeric value.
Parameters
i_oValueThe numeric value to be pushed.

◆ push() [7/8]

template<typename T , typename std::enable_if_t< std::is_enum_v< T >> * = nullptr>
void Devel::IO::CWriteStream::push ( const T &  i_oValue)
inline

Pushes an enum value to the buffer.

Template Parameters
TThe type of the enum.
Parameters
i_oValueThe enum value to be pushed.

◆ push() [8/8]

void Devel::IO::CWriteStream::push ( const void *  i_pBuffer,
size_t  i_nSize 
)

Pushes the specified data to the buffer.

Parameters
i_pBufferPointer to the data to be pushed.
i_nSizeThe size of the data to be pushed.

◆ reallocate()

void Devel::IO::CWriteStream::reallocate ( size_t  i_nSize)

Reallocates the buffer to the given size.

Parameters
i_nSizeThe new size of the buffer.

◆ replace() [1/6]

void Devel::IO::CWriteStream::replace ( const size_t  i_nPosition,
const char *  i_szString 
) const
inline

Replaces a portion of the buffer with a null-terminated string.

Parameters
i_nPositionThe position in the buffer to start replacing.
i_szStringThe null-terminated string to be replaced.

◆ replace() [2/6]

void Devel::IO::CWriteStream::replace ( const size_t  i_nPosition,
const CWriteStream i_oStream 
) const
inline

Replaces a portion of the buffer with the data from another CWriteStream.

Parameters
i_nPositionThe position in the buffer to start replacing.
i_oStreamThe CWriteStream object whose data will replace the buffer portion.

◆ replace() [3/6]

void Devel::IO::CWriteStream::replace ( const size_t  i_nPosition,
const std::string &  i_oString 
) const
inline

Replaces a portion of the buffer with a std::string.

Parameters
i_nPositionThe position in the buffer to start replacing.
i_oStringThe std::string to be replaced.

◆ replace() [4/6]

template<typename T , typename std::enable_if_t< std::is_arithmetic_v< T >> * = nullptr>
void Devel::IO::CWriteStream::replace ( const size_t  i_nPosition,
const T &  i_oValue 
)
inline

Replaces a portion of the buffer with a numeric value.

Template Parameters
TThe type of the numeric value.
Parameters
i_nPositionThe position in the buffer to start replacing.
i_oValueThe numeric value to be replaced.

◆ replace() [5/6]

template<typename T , typename std::enable_if_t< std::is_enum_v< T >> * = nullptr>
void Devel::IO::CWriteStream::replace ( const size_t  i_nPosition,
const T &  i_oValue 
)
inline

Replaces a portion of the buffer with an enum value.

Template Parameters
TThe type of the enum.
Parameters
i_nPositionThe position in the buffer to start replacing.
i_oValueThe enum value to be replaced.

◆ replace() [6/6]

void Devel::IO::CWriteStream::replace ( const size_t  i_nPosition,
const void *  i_pBuffer,
const size_t  i_nSize 
) const
inline

Replaces a portion of the buffer with the specified data.

Parameters
i_nPositionThe position in the buffer to start replacing.
i_pBufferPointer to the data to be replaced.
i_nSizeThe size of the data to be replaced.

◆ size()

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

Gets the current size of the buffer.

Returns
The current size of the buffer.

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