Devel Lib
Devel::IO::CDynamicBuffer Class Reference

A dynamic implementation of the IBuffer interface. More...

#include <DynamicBuffer.h>

Inheritance diagram for Devel::IO::CDynamicBuffer:
Collaboration diagram for Devel::IO::CDynamicBuffer:

Public Member Functions

 CDynamicBuffer ()
 Default constructor.
 
 CDynamicBuffer (const size_t i_nSize)
 Overloaded constructor. More...
 
 CDynamicBuffer (const CDynamicBuffer &i_oOther)
 Copy constructor. More...
 
 CDynamicBuffer (CDynamicBuffer &&i_oOther) noexcept
 Move constructor. More...
 
virtual ~CDynamicBuffer ()
 Virtual destructor.
 
void reallocate (const size_t i_nSize)
 Reallocate the buffer to a new size. More...
 
const char * buffer () const override
 Get a constant pointer to the start of the buffer. More...
 
char * rawBuffer () const override
 Get a mutable pointer to the start of the buffer. More...
 
size_t size () const override
 Get the size of the buffer. More...
 
size_t allocatedSize () const
 Get the total allocated size of the buffer. More...
 
const char & operator[] (const size_t i_nIndex)
 Array access operator. More...
 
void operator= (const CDynamicBuffer &i_oOther)
 Copy assignment operator. More...
 
void operator= (CDynamicBuffer &&i_oOther) noexcept
 Move assignment operator. More...
 

Detailed Description

A dynamic implementation of the IBuffer interface.

This class represents a buffer of bytes that can be resized dynamically, providing a flexible way to interact with variable-sized data.

Example

Here's an example of how you might use a CDynamicBuffer:

Devel::IO::CDynamicBuffer buf(1024); // Creating a dynamic buffer of 1024 bytes
// Fill the buffer...
const char *buffer = buf.buffer();
size_t bufferSize = buf.size();
// Resize the buffer...
buf.reallocate(2048);
bufferSize = buf.size();
A dynamic implementation of the IBuffer interface.
Definition: DynamicBuffer.h:27
const char * buffer() const override
Get a constant pointer to the start of the buffer.
Definition: DynamicBuffer.h:75

Constructor & Destructor Documentation

◆ CDynamicBuffer() [1/3]

Devel::IO::CDynamicBuffer::CDynamicBuffer ( const size_t  i_nSize)

Overloaded constructor.

Parameters
i_nSizeThe initial size of the buffer.

◆ CDynamicBuffer() [2/3]

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

Copy constructor.

Parameters
i_oOtherThe object to copy from.

◆ CDynamicBuffer() [3/3]

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

Move constructor.

Parameters
i_oOtherThe object to move from.

Member Function Documentation

◆ allocatedSize()

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

Get the total allocated size of the buffer.

Returns
The total allocated size of the buffer.

◆ buffer()

const char* Devel::IO::CDynamicBuffer::buffer ( ) const
inlineoverridevirtual

Get a constant pointer to the start of the buffer.

Returns
A const char pointer to the buffer.

Implements Devel::IO::IBuffer.

◆ operator=() [1/2]

void Devel::IO::CDynamicBuffer::operator= ( CDynamicBuffer &&  i_oOther)
inlinenoexcept

Move assignment operator.

Parameters
i_oOtherThe object to move from.

This function will take over the state of another CDynamicBuffer, leaving the other object in a safe, but undefined state.

◆ operator=() [2/2]

void Devel::IO::CDynamicBuffer::operator= ( const CDynamicBuffer i_oOther)
inline

Copy assignment operator.

Parameters
i_oOtherThe object to copy from.

This function will copy the state of another CDynamicBuffer, allocating memory as necessary.

◆ operator[]()

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

Array access operator.

Parameters
i_nIndexThe index of the byte to retrieve.
Exceptions
IndexOutOfRangeExceptionIf the provided index is greater than the size of the buffer, this function will throw an IndexOutOfRangeException.
Returns
The byte at the specified index.

◆ rawBuffer()

char* Devel::IO::CDynamicBuffer::rawBuffer ( ) const
inlineoverridevirtual

Get a mutable pointer to the start of the buffer.

Returns
A char pointer to the buffer.

Implements Devel::IO::IBuffer.

◆ reallocate()

void Devel::IO::CDynamicBuffer::reallocate ( const size_t  i_nSize)

Reallocate the buffer to a new size.

Parameters
i_nSizeThe new size for the buffer.

◆ size()

size_t Devel::IO::CDynamicBuffer::size ( ) const
inlineoverridevirtual

Get the size of the buffer.

Returns
The size of the buffer.

Implements Devel::IO::IBuffer.


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