Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
roc::core::StringBuffer Class Reference

String buffer. More...

#include <string_buffer.h>

Inheritance diagram for roc::core::StringBuffer:
Collaboration diagram for roc::core::StringBuffer:

Public Member Functions

 StringBuffer (IArena &arena)
 Initialize empty buffer. More...
 
bool is_empty () const
 Check if buffer is empty. More...
 
size_t len () const
 Get string length, excluding terminating zero. More...
 
const char * c_str () const
 Get zero-terminated string. More...
 
void clear ()
 Set buffer to empty string. More...
 
ROC_ATTR_NODISCARD bool assign (const char *str)
 Copy given string into buffer. str should be zero-terminated. More...
 
ROC_ATTR_NODISCARD bool assign (const char *str_begin, const char *str_end)
 Copy given range into buffer. Buffer will be automatically zero-terminated. More...
 
ROC_ATTR_NODISCARD char * extend (size_t n_chars)
 Extend buffer by requested number of characters. More...
 
ROC_ATTR_NODISCARD bool grow (size_t desired_len)
 Grow capacity to be able to hold desired number of characters. Capacity is increased linearly. More...
 
ROC_ATTR_NODISCARD bool grow_exp (size_t desired_len)
 Grow capacity to be able to hold desired number of characters. Capacity is increased exponentionally. More...
 

Detailed Description

String buffer.

Dynamic array storing zero-terminated string. Works on top of Array, but guarantees that the string is always zero-terminated.

Template Parameters
EmbeddedCapacityis the same as for Array.

Definition at line 30 of file string_buffer.h.

Constructor & Destructor Documentation

◆ StringBuffer()

roc::core::StringBuffer::StringBuffer ( IArena arena)
explicit

Initialize empty buffer.

Member Function Documentation

◆ assign() [1/2]

ROC_ATTR_NODISCARD bool roc::core::StringBuffer::assign ( const char *  str)

Copy given string into buffer. str should be zero-terminated.

Returns
false if allocation failed.

◆ assign() [2/2]

ROC_ATTR_NODISCARD bool roc::core::StringBuffer::assign ( const char *  str_begin,
const char *  str_end 
)

Copy given range into buffer. Buffer will be automatically zero-terminated.

Returns
false if allocation failed.

◆ c_str()

const char* roc::core::StringBuffer::c_str ( ) const

Get zero-terminated string.

◆ clear()

void roc::core::StringBuffer::clear ( )

Set buffer to empty string.

◆ extend()

ROC_ATTR_NODISCARD char* roc::core::StringBuffer::extend ( size_t  n_chars)

Extend buffer by requested number of characters.

Remarks
Characters are appended to the buffer and filled with zeros. It's the caller responsibility to fill them.
Returns
NULL if allocation failed.

◆ grow()

ROC_ATTR_NODISCARD bool roc::core::StringBuffer::grow ( size_t  desired_len)

Grow capacity to be able to hold desired number of characters. Capacity is increased linearly.

Returns
false if allocation failed.

◆ grow_exp()

ROC_ATTR_NODISCARD bool roc::core::StringBuffer::grow_exp ( size_t  desired_len)

Grow capacity to be able to hold desired number of characters. Capacity is increased exponentionally.

Returns
false if allocation failed.

◆ is_empty()

bool roc::core::StringBuffer::is_empty ( ) const

Check if buffer is empty.

◆ len()

size_t roc::core::StringBuffer::len ( ) const

Get string length, excluding terminating zero.


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