nfx-stringbuilderpool 1.0.0
High-performance C++20 library for zero-allocation string building with thread-safe pooling
Loading...
Searching...
No Matches
nfx::string::DynamicStringBuffer Class Referencefinal

High-performance dynamic string buffer with efficient memory management. More...

#include <nfx/string/StringBuilderPool.h>

Public Types

using value_type = char
 Character type for iterator compatibility.
 
using iterator = char *
 Mutable iterator type for buffer traversal.
 
using const_iterator = const char *
 Immutable iterator type for buffer traversal.
 

Public Member Functions

 DynamicStringBuffer (const DynamicStringBuffer &other)
 Copy constructor.
 
 DynamicStringBuffer (DynamicStringBuffer &&other) noexcept
 Move constructor.
 
 ~DynamicStringBuffer ()=default
 Destructor.
 
DynamicStringBufferoperator= (const DynamicStringBuffer &other)
 Copy assignment operator.
 
DynamicStringBufferoperator= (DynamicStringBuffer &&other) noexcept
 Move assignment operator.
 
size_t size () const noexcept
 Get current buffer size in bytes.
 
size_t capacity () const noexcept
 Get current buffer capacity in bytes.
 
bool isEmpty () const noexcept
 Check if buffer is empty.
 
void clear () noexcept
 Clear buffer content without deallocating memory.
 
void reserve (size_t newCapacity)
 Reserve minimum capacity for buffer.
 
void resize (size_t newSize)
 Resize buffer to specified size.
 
char * data () noexcept
 Get mutable pointer to buffer data.
 
const char * data () const noexcept
 Get immutable pointer to buffer data.
 
char & operator[] (size_t index)
 Access buffer element by index (mutable)
 
const char & operator[] (size_t index) const
 Access buffer element by index (immutable)
 
void append (std::string_view str)
 Append string_view content to buffer.
 
void append (const std::string &str)
 Append std::string content to buffer.
 
void append (const char *str)
 Append null-terminated C string to buffer.
 
void push_back (char c)
 Append single character to buffer.
 
std::string toString () const
 Convert buffer content to std::string.
 
std::string_view toStringView () const noexcept
 Get string_view of buffer content.
 
iterator begin () noexcept
 Get mutable iterator to beginning of buffer.
 
const_iterator begin () const noexcept
 Get immutable iterator to beginning of buffer.
 
iterator end () noexcept
 Get mutable iterator to end of buffer.
 
const_iterator end () const noexcept
 Get immutable iterator to end of buffer.
 

Friends

class DynamicStringBufferPool
 

Detailed Description

High-performance dynamic string buffer with efficient memory management.

Provides a growable character buffer optimized for string building operations. Features automatic capacity management, iterator support, and zero-copy string_view access. Designed for internal use by StringBuilderPool.

Warning
Not thread-safe - external synchronization required for concurrent access.
See also
StringBuilderPool for the recommended high-level interface
StringBuilder for a more convenient wrapper around this buffer

Definition at line 103 of file StringBuilderPool.h.

Member Typedef Documentation

◆ const_iterator

Immutable iterator type for buffer traversal.

Definition at line 315 of file StringBuilderPool.h.

◆ iterator

Mutable iterator type for buffer traversal.

Definition at line 312 of file StringBuilderPool.h.

◆ value_type

Character type for iterator compatibility.

Definition at line 309 of file StringBuilderPool.h.

Constructor & Destructor Documentation

◆ DynamicStringBuffer() [1/2]

nfx::string::DynamicStringBuffer::DynamicStringBuffer ( const DynamicStringBuffer other)

Copy constructor.

Parameters
otherThe DynamicStringBuffer to copy from

◆ DynamicStringBuffer() [2/2]

nfx::string::DynamicStringBuffer::DynamicStringBuffer ( DynamicStringBuffer &&  other)
noexcept

Move constructor.

Parameters
otherThe DynamicStringBuffer to move from

Member Function Documentation

◆ append() [1/3]

void nfx::string::DynamicStringBuffer::append ( const char *  str)

Append null-terminated C string to buffer.

Parameters
strNull-terminated string to append

Safe handling of nullptr (no-op)

Exceptions
std::bad_allocif buffer expansion fails

◆ append() [2/3]

void nfx::string::DynamicStringBuffer::append ( const std::string &  str)

Append std::string content to buffer.

Parameters
strString to append

Convenience overload for std::string

Exceptions
std::bad_allocif buffer expansion fails

◆ append() [3/3]

void nfx::string::DynamicStringBuffer::append ( std::string_view  str)

Append string_view content to buffer.

Parameters
strString view to append

Efficient append without copying string data

Exceptions
std::bad_allocif buffer expansion fails

◆ begin() [1/2]

const_iterator nfx::string::DynamicStringBuffer::begin ( ) const
noexcept

Get immutable iterator to beginning of buffer.

Returns
Const iterator pointing to first element

Safe read-only iteration over buffer contents

Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ begin() [2/2]

iterator nfx::string::DynamicStringBuffer::begin ( )
noexcept

Get mutable iterator to beginning of buffer.

Returns
Iterator pointing to first element

Enables range-based for loops and STL algorithms

Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ capacity()

size_t nfx::string::DynamicStringBuffer::capacity ( ) const
noexcept

Get current buffer capacity in bytes.

Returns
Number of bytes allocated for buffer storage

Capacity may be larger than size to avoid frequent reallocations

Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ clear()

void nfx::string::DynamicStringBuffer::clear ( )
noexcept

Clear buffer content without deallocating memory.

Sets size to 0 but preserves allocated capacity for reuse

◆ data() [1/2]

const char * nfx::string::DynamicStringBuffer::data ( ) const
noexcept

Get immutable pointer to buffer data.

Returns
Const pointer to first byte of buffer data

Safe read-only access to buffer contents

Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ data() [2/2]

char * nfx::string::DynamicStringBuffer::data ( )
noexcept

Get mutable pointer to buffer data.

Returns
Pointer to first byte of buffer data

Provides direct memory access for high-performance operations

Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ end() [1/2]

const_iterator nfx::string::DynamicStringBuffer::end ( ) const
noexcept

Get immutable iterator to end of buffer.

Returns
Const iterator pointing one past last element

Standard STL end iterator semantics

Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ end() [2/2]

iterator nfx::string::DynamicStringBuffer::end ( )
noexcept

Get mutable iterator to end of buffer.

Returns
Iterator pointing one past last element

Standard STL end iterator semantics

Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ isEmpty()

bool nfx::string::DynamicStringBuffer::isEmpty ( ) const
noexcept

Check if buffer is empty.

Returns
true if buffer contains no data, false otherwise
Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ operator=() [1/2]

DynamicStringBuffer & nfx::string::DynamicStringBuffer::operator= ( const DynamicStringBuffer other)

Copy assignment operator.

Parameters
otherThe DynamicStringBuffer to copy from
Returns
Reference to this DynamicStringBuffer after assignment

◆ operator=() [2/2]

DynamicStringBuffer & nfx::string::DynamicStringBuffer::operator= ( DynamicStringBuffer &&  other)
noexcept

Move assignment operator.

Parameters
otherThe DynamicStringBuffer to move from
Returns
Reference to this DynamicStringBuffer after assignment

◆ operator[]() [1/2]

char & nfx::string::DynamicStringBuffer::operator[] ( size_t  index)

Access buffer element by index (mutable)

Parameters
indexZero-based index of element to access
Returns
Reference to element at specified index

No bounds checking - undefined behavior if index >= size()

◆ operator[]() [2/2]

const char & nfx::string::DynamicStringBuffer::operator[] ( size_t  index) const

Access buffer element by index (immutable)

Parameters
indexZero-based index of element to access
Returns
Const reference to element at specified index

No bounds checking - undefined behavior if index >= size()

◆ push_back()

void nfx::string::DynamicStringBuffer::push_back ( char  c)

Append single character to buffer.

Parameters
cCharacter to append

Efficient single-character append

Exceptions
std::bad_allocif buffer expansion fails

◆ reserve()

void nfx::string::DynamicStringBuffer::reserve ( size_t  newCapacity)

Reserve minimum capacity for buffer.

Parameters
newCapacityMinimum desired capacity in bytes

May allocate more than requested for efficiency

Exceptions
std::bad_allocif memory allocation fails

◆ resize()

void nfx::string::DynamicStringBuffer::resize ( size_t  newSize)

Resize buffer to specified size.

Parameters
newSizeNew buffer size in bytes

May truncate content or extend with undefined bytes

Exceptions
std::bad_allocif memory allocation fails

◆ size()

size_t nfx::string::DynamicStringBuffer::size ( ) const
noexcept

Get current buffer size in bytes.

Returns
Number of bytes currently stored in buffer

Returns actual content size, not allocated capacity

Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ toString()

std::string nfx::string::DynamicStringBuffer::toString ( ) const

Convert buffer content to std::string.

Returns
String copy of buffer content

Creates new string object - consider toStringView() for read-only access

◆ toStringView()

std::string_view nfx::string::DynamicStringBuffer::toStringView ( ) const
noexcept

Get string_view of buffer content.

Returns
String view referencing buffer data

Zero-copy access - view becomes invalid if buffer is modified

Note
This function is marked [[nodiscard]] - the return value should not be ignored

Friends And Related Symbol Documentation

◆ DynamicStringBufferPool

friend class DynamicStringBufferPool
friend

Definition at line 105 of file StringBuilderPool.h.


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