High-performance dynamic string buffer with efficient memory management.
More...
#include <nfx/string/StringBuilder.h>
|
| | 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.
|
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.
◆ const_iterator
◆ 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
◆ value_type
Character type for iterator compatibility.
Definition at line 310 of file StringBuilder.h.
◆ DynamicStringBuffer() [1/2]
| nfx::string::DynamicStringBuffer::DynamicStringBuffer |
( |
const DynamicStringBuffer & | other | ) |
|
Copy constructor.
- Parameters
-
| other | The DynamicStringBuffer to copy from |
◆ DynamicStringBuffer() [2/2]
| nfx::string::DynamicStringBuffer::DynamicStringBuffer |
( |
DynamicStringBuffer && | other | ) |
|
|
noexcept |
Move constructor.
- Parameters
-
| other | The DynamicStringBuffer to move from |
◆ append() [1/4]
| void nfx::string::DynamicStringBuffer::append |
( |
char | c | ) |
|
Append single character to buffer.
- Parameters
-
Efficient single-character append
- Exceptions
-
| std::bad_alloc | if buffer expansion fails |
◆ append() [2/4]
| void nfx::string::DynamicStringBuffer::append |
( |
const char * | str | ) |
|
Append null-terminated C string to buffer.
- Parameters
-
| str | Null-terminated string to append |
Safe handling of nullptr (no-op)
- Exceptions
-
| std::bad_alloc | if buffer expansion fails |
◆ append() [3/4]
| void nfx::string::DynamicStringBuffer::append |
( |
const std::string & | str | ) |
|
Append std::string content to buffer.
- Parameters
-
Convenience overload for std::string
- Exceptions
-
| std::bad_alloc | if buffer expansion fails |
◆ append() [4/4]
| void nfx::string::DynamicStringBuffer::append |
( |
std::string_view | str | ) |
|
Append string_view content to buffer.
- Parameters
-
Efficient append without copying string data
- Exceptions
-
| std::bad_alloc | if buffer expansion fails |
◆ begin() [1/2]
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 |
( |
| ) |
|
|
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
◆ 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
◆ 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 |
|
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
◆ 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
◆ end() [1/2]
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 |
( |
| ) |
|
|
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
◆ 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
◆ operator=() [1/2]
| DynamicStringBuffer & nfx::string::DynamicStringBuffer::operator= |
( |
const DynamicStringBuffer & | other | ) |
|
Copy assignment operator.
- Parameters
-
| other | The 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
-
| other | The 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
-
| index | Zero-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
-
| index | Zero-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
-
| newCapacity | Minimum desired capacity in bytes |
May allocate more than requested for efficiency
- Exceptions
-
| std::bad_alloc | if memory allocation fails |
◆ resize()
| void nfx::string::DynamicStringBuffer::resize |
( |
size_t | newSize | ) |
|
Resize buffer to specified size.
- Parameters
-
| newSize | New buffer size in bytes |
May truncate content or extend with undefined bytes
- Exceptions
-
| std::bad_alloc | if memory allocation fails |
◆ 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
◆ 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
◆ DynamicStringBufferPool
| friend class DynamicStringBufferPool |
|
friend |
The documentation for this class was generated from the following file: