nfx-stringbuilder 0.1.1
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/StringBuilder.h>

Public Types

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

Public Member Functions

 DynamicStringBuffer (const DynamicStringBuffer &other)
 Copy constructor.
 DynamicStringBuffer (DynamicStringBuffer &&other) noexcept
 Move constructor.
 ~DynamicStringBuffer ()=default
 Destructor.
DynamicStringBuffer & operator= (const DynamicStringBuffer &other)
 Copy assignment operator.
DynamicStringBuffer & operator= (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 append (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.
ConstIterator begin () const noexcept
 Get immutable iterator to beginning of buffer.
Iterator end () noexcept
 Get mutable iterator to end of buffer.
ConstIterator 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 104 of file StringBuilder.h.

Member Typedef Documentation

◆ const_iterator

Type alias for const iterator.

Definition at line 322 of file StringBuilder.h.

◆ ConstIterator

Immutable iterator type for buffer traversal.

Definition at line 316 of file StringBuilder.h.

◆ Iterator

Mutable iterator type for buffer traversal.

Definition at line 313 of file StringBuilder.h.

◆ iterator

Type alias for iterator.

Definition at line 319 of file StringBuilder.h.

◆ value_type

Character type for iterator compatibility.

Definition at line 310 of file StringBuilder.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/4]

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

Append single character to buffer.

Parameters
cCharacter to append

Efficient single-character append

Exceptions
std::bad_allocif buffer expansion fails
Here is the call graph for this function:

◆ append() [2/4]

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
Here is the call graph for this function:

◆ append() [3/4]

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
Here is the call graph for this function:

◆ append() [4/4]

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
Here is the call graph for this function:
Here is the caller graph for this function:

◆ begin() [1/2]

ConstIterator nfx::string::DynamicStringBuffer::begin ( ) const
nodiscardnoexcept

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
Here is the call graph for this function:

◆ begin() [2/2]

Iterator nfx::string::DynamicStringBuffer::begin ( )
nodiscardnoexcept

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
Here is the call graph for this function:
Here is the caller graph for this function:

◆ capacity()

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

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
Here is the call graph for this function:
Here is the caller graph for this function:

◆ clear()

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

Clear buffer content without deallocating memory.

Sets size to 0 but preserves allocated capacity for reuse

Here is the call graph for this function:
Here is the caller graph for this function:

◆ data() [1/2]

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

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
Here is the call graph for this function:

◆ data() [2/2]

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

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
Here is the call graph for this function:
Here is the caller graph for this function:

◆ end() [1/2]

ConstIterator nfx::string::DynamicStringBuffer::end ( ) const
nodiscardnoexcept

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
Here is the call graph for this function:

◆ end() [2/2]

Iterator nfx::string::DynamicStringBuffer::end ( )
nodiscardnoexcept

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
Here is the call graph for this function:
Here is the caller graph for this function:

◆ isEmpty()

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

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
Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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()

◆ 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
Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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
Here is the call graph for this function:
Here is the caller graph for this function:

◆ size()

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

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
nodiscard

Convert buffer content to std::string.

Returns
String copy of buffer content

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ toStringView()

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

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
Here is the call graph for this function:
Here is the caller graph for this function:

◆ DynamicStringBufferPool

friend class DynamicStringBufferPool
friend

Definition at line 106 of file StringBuilder.h.


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