104 class DynamicStringBuffer final
106 friend class DynamicStringBufferPool;
114 DynamicStringBuffer();
121 explicit DynamicStringBuffer(
size_t initialCapacity );
152 DynamicStringBuffer&
operator=(
const DynamicStringBuffer& other );
159 DynamicStringBuffer&
operator=( DynamicStringBuffer&& other )
noexcept;
171 [[nodiscard]]
size_t size() const noexcept;
224 [[nodiscard]]
char*
data() noexcept;
232 [[nodiscard]] const
char*
data() const noexcept;
240 char& operator[](
size_t index );
248 const
char& operator[](
size_t index ) const;
362 static constexpr
size_t STACK_BUFFER_SIZE = 256;
365 static constexpr auto GROWTH_FACTOR = 1.5;
372 alignas(
char )
char m_stackBuffer[STACK_BUFFER_SIZE];
375 std::unique_ptr<
char[]> m_heapBuffer;
394 void ensureCapacity(
size_t needed_capacity );
400 char* currentBuffer() noexcept;
406 const
char* currentBuffer() const noexcept;
429 class StringBuilder final
431 friend class StringBuilderLease;
432 friend class std::back_insert_iterator<StringBuilder>;
456 ~StringBuilder() = default;
463 StringBuilder& operator=( const StringBuilder& ) = delete;
466 StringBuilder& operator=( StringBuilder&& ) noexcept = delete;
477 inline
char& operator[](
size_t index );
484 inline const
char& operator[](
size_t index ) const;
494 inline
void append( std::string_view str );
500 inline
void append( const std::
string& str );
523 inline StringBuilder& operator<<( std::string_view str );
530 inline StringBuilder& operator<<( const std::
string& str );
537 inline StringBuilder& operator<<( const
char* str );
544 inline StringBuilder& operator<<(
char c );
551 inline StringBuilder& operator<<( std::int32_t value );
558 inline StringBuilder& operator<<( std::uint32_t value );
565 inline StringBuilder& operator<<( std::int64_t value );
572 inline StringBuilder& operator<<( std::uint64_t value );
579 inline StringBuilder& operator<<(
float value );
586 inline StringBuilder& operator<<(
double value );
602 template <typename... Args>
603 inline StringBuilder&
format( std::format_string<Args...> fmt, Args&&... args );
674 inline
void push_back(
char c ) {
append( c ); }
705 class StringBuilderLease final
707 friend class StringBuilderPool;
741 StringBuilderLease&
operator=(
const StringBuilderLease& ) =
delete;
748 inline StringBuilderLease&
operator=( StringBuilderLease&& other )
noexcept;
784 [[noreturn]]
void throwInvalidOperation()
const;
867 class StringBuilderPool final
899 StringBuilderPool() =
default;
983#include "nfx/detail/string/StringBuilder.inl"
High-performance dynamic string buffer with efficient memory management.
Iterator iterator
Type alias for iterator.
Iterator begin() noexcept
Get mutable iterator to beginning of buffer.
void append(std::string_view str)
Append string_view content to buffer.
bool isEmpty() const noexcept
Check if buffer is empty.
DynamicStringBuffer(const DynamicStringBuffer &other)
Copy constructor.
Iterator end() noexcept
Get mutable iterator to end of buffer.
char * data() noexcept
Get mutable pointer to buffer data.
void reserve(size_t newCapacity)
Reserve minimum capacity for buffer.
char value_type
Character type for iterator compatibility.
DynamicStringBuffer & operator=(DynamicStringBuffer &&other) noexcept
Move assignment operator.
void resize(size_t newSize)
Resize buffer to specified size.
DynamicStringBuffer & operator=(const DynamicStringBuffer &other)
Copy assignment operator.
~DynamicStringBuffer()=default
Destructor.
std::string toString() const
Convert buffer content to std::string.
void clear() noexcept
Clear buffer content without deallocating memory.
ConstIterator const_iterator
Type alias for const iterator.
DynamicStringBuffer(DynamicStringBuffer &&other) noexcept
Move constructor.
const char * ConstIterator
Immutable iterator type for buffer traversal.
char * Iterator
Mutable iterator type for buffer traversal.
size_t size() const noexcept
Get current buffer size in bytes.
std::string_view toStringView() const noexcept
Get string_view of buffer content.
size_t capacity() const noexcept
Get current buffer capacity in bytes.
High-performance string builder with fluent interface and efficient memory management.
char * Iterator
Mutable iterator type for buffer traversal.
Iterator end()
Returns mutable iterator to end of character sequence.
StringBuilder & format(std::format_string< Args... > fmt, Args &&... args)
Format and append text using std::format.
ConstIterator const_iterator
Type alias for const iterator.
const char * ConstIterator
Immutable iterator type for buffer traversal.
void append(std::string_view str)
Appends string_view contents to the buffer efficiently.
StringBuilder(StringBuilder &&) noexcept=delete
Move constructor.
StringBuilder(const StringBuilder &)=default
Copy constructor.
char value_type
Character type for iterator compatibility.
void resize(size_t newSize)
Resizes buffer to specified character count.
size_t length() const noexcept
Returns current buffer size in characters.
Iterator begin()
Returns mutable iterator to beginning of character sequence.
Iterator iterator
Type alias for iterator.
StringBuilder()=delete
Default constructor.
RAII lease wrapper for pooled StringBuilder buffers with automatic resource management.
std::string toString() const
Converts buffer contents to std::string.
StringBuilderLease & operator=(const StringBuilderLease &)=delete
Copy assignment operator.
StringBuilderLease(const StringBuilderLease &)=delete
Copy constructor.
StringBuilderLease()=delete
Default constructor.
StringBuilderLease & operator=(StringBuilderLease &&other) noexcept
Move assignment operator.
DynamicStringBuffer & buffer()
Provides direct access to underlying memory buffer.
StringBuilderLease(StringBuilderLease &&other) noexcept
Move constructor.
~StringBuilderLease()
Destructor.
StringBuilder create()
Creates StringBuilder wrapper for buffer manipulation.
static StringBuilderLease lease(size_t capacityHint)
Creates a new StringBuilder lease with pre-allocated capacity hint.
static size_t clear()
Clears all buffers from the pool and returns the count of cleared buffers.
static PoolStatistics stats() noexcept
Gets current pool statistics.
static void resetStats() noexcept
Resets pool statistics.
static StringBuilderLease lease()
Creates a new StringBuilder lease with an optimally sourced memory buffer.
static size_t size() noexcept
Gets current number of buffers stored in the pool.
Pool performance statistics for external access.
uint64_t dynamicStringBufferPoolHits
Number of successful buffer retrievals from shared cross-thread pool.
uint64_t totalRequests
Total number of buffer requests made to the pool.
double hitRate
Cache hit rate as a percentage (0.0 to 1.0).
uint64_t newAllocations
Number of new buffer allocations when pools were empty.
uint64_t threadLocalHits
Number of successful buffer retrievals from thread-local cache.