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::StringBuilder Class Referencefinal

High-performance string builder with fluent interface and efficient memory management. More...

#include <nfx/string/StringBuilderPool.h>

Classes

class  Enumerator
 Forward-only iterator for character-by-character enumeration of StringBuilder content. More...
 

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

 StringBuilder ()=delete
 Default constructor.
 
 StringBuilder (const StringBuilder &)=default
 Copy constructor.
 
 StringBuilder (StringBuilder &&) noexcept=delete
 Move constructor.
 
 ~StringBuilder ()=default
 Destructor.
 
StringBuilderoperator= (const StringBuilder &)=delete
 Copy assignment operator.
 
StringBuilderoperator= (StringBuilder &&) noexcept=delete
 Move assignment operator.
 
char & operator[] (size_t index)
 Provides read-write access to character at specified index.
 
const char & operator[] (size_t index) const
 Provides read-only access to character at specified index.
 
void append (std::string_view str)
 Appends string_view contents to the buffer efficiently.
 
void append (const std::string &str)
 Appends std::string contents to the buffer.
 
void append (const char *str)
 Appends null-terminated C-string to the buffer.
 
void push_back (char c)
 Appends single character to the buffer.
 
StringBuilderoperator<< (std::string_view str)
 Stream operator for string_view.
 
StringBuilderoperator<< (const std::string &str)
 Stream operator for std::string.
 
StringBuilderoperator<< (const char *str)
 Stream operator for C-string.
 
StringBuilderoperator<< (char c)
 Stream operator for single character.
 
size_t length () const noexcept
 Returns current buffer size in characters.
 
void resize (size_t newSize)
 Resizes buffer to specified character count.
 
iterator begin ()
 Returns mutable iterator to beginning of character sequence.
 
const_iterator begin () const
 Returns const iterator to beginning of character sequence.
 
iterator end ()
 Returns mutable iterator to end of character sequence.
 
const_iterator end () const
 Returns const iterator to end of character sequence.
 

Friends

class StringBuilderLease
 

Detailed Description

High-performance string builder with fluent interface and efficient memory management.

Provides a convenient wrapper around DynamicStringBuffer with stream-like operators for intuitive string construction. Features efficient append operations, iterator support, and automatic memory management through the underlying buffer.

Note
This class is a lightweight wrapper that references an underlying DynamicStringBuffer. It does not own the buffer memory - use StringBuilderPool::lease() for proper RAII management.
Warning
Not thread-safe - external synchronization required for concurrent access. Multiple StringBuilder instances should not reference the same buffer concurrently.
See also
StringBuilderPool for the recommended way to obtain StringBuilder instances
StringBuilderLease for RAII management of pooled buffers
DynamicStringBuffer for the underlying buffer implementation

Definition at line 422 of file StringBuilderPool.h.

Member Typedef Documentation

◆ const_iterator

Immutable iterator type for buffer traversal.

Definition at line 565 of file StringBuilderPool.h.

◆ iterator

Mutable iterator type for buffer traversal.

Definition at line 562 of file StringBuilderPool.h.

◆ value_type

Character type for iterator compatibility.

Definition at line 559 of file StringBuilderPool.h.

Member Function Documentation

◆ append() [1/3]

void nfx::string::StringBuilder::append ( const char *  str)
inline

Appends null-terminated C-string to the buffer.

Parameters
strNull-terminated C-string to append (null pointer handled gracefully)

◆ append() [2/3]

void nfx::string::StringBuilder::append ( const std::string &  str)
inline

Appends std::string contents to the buffer.

Parameters
strString to append

◆ append() [3/3]

void nfx::string::StringBuilder::append ( std::string_view  str)
inline

Appends string_view contents to the buffer efficiently.

Parameters
strString view to append

◆ begin() [1/2]

iterator nfx::string::StringBuilder::begin ( )
inline

Returns mutable iterator to beginning of character sequence.

Returns
Iterator pointing to the first character in the buffer

◆ begin() [2/2]

const_iterator nfx::string::StringBuilder::begin ( ) const
inline

Returns const iterator to beginning of character sequence.

Returns
Const iterator pointing to the first character in the buffer

◆ end() [1/2]

iterator nfx::string::StringBuilder::end ( )
inline

Returns mutable iterator to end of character sequence.

Returns
Iterator pointing one past the last character in the buffer

◆ end() [2/2]

const_iterator nfx::string::StringBuilder::end ( ) const
inline

Returns const iterator to end of character sequence.

Returns
Const iterator pointing one past the last character in the buffer

◆ length()

size_t nfx::string::StringBuilder::length ( ) const
inlinenoexcept

Returns current buffer size in characters.

Returns
Number of characters currently stored in the buffer

◆ operator<<() [1/4]

StringBuilder & nfx::string::StringBuilder::operator<< ( char  c)
inline

Stream operator for single character.

Parameters
cCharacter to append
Returns
Reference to this StringBuilder for chaining

◆ operator<<() [2/4]

StringBuilder & nfx::string::StringBuilder::operator<< ( const char *  str)
inline

Stream operator for C-string.

Parameters
strNull-terminated C-string to append
Returns
Reference to this StringBuilder for chaining

◆ operator<<() [3/4]

StringBuilder & nfx::string::StringBuilder::operator<< ( const std::string &  str)
inline

Stream operator for std::string.

Parameters
strString to append
Returns
Reference to this StringBuilder for chaining

◆ operator<<() [4/4]

StringBuilder & nfx::string::StringBuilder::operator<< ( std::string_view  str)
inline

Stream operator for string_view.

Parameters
strString view to append
Returns
Reference to this StringBuilder for chaining

◆ operator[]() [1/2]

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

Provides read-write access to character at specified index.

Parameters
indexZero-based character index
Returns
Reference to character at the specified position

◆ operator[]() [2/2]

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

Provides read-only access to character at specified index.

Parameters
indexZero-based character index
Returns
Const reference to character at the specified position

◆ push_back()

void nfx::string::StringBuilder::push_back ( char  c)
inline

Appends single character to the buffer.

Parameters
cCharacter to append

◆ resize()

void nfx::string::StringBuilder::resize ( size_t  newSize)
inline

Resizes buffer to specified character count.

Parameters
newSizeNew buffer size in characters

Friends And Related Symbol Documentation

◆ StringBuilderLease

friend class StringBuilderLease
friend

Definition at line 424 of file StringBuilderPool.h.


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