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

Dynamic list of strings. More...

#include <string_list.h>

Inheritance diagram for roc::core::StringList:
Collaboration diagram for roc::core::StringList:

Public Member Functions

 StringList (IArena &arena)
 Initialize empty string list. More...
 
size_t size () const
 Get number of elements. More...
 
bool is_empty () const
 Check if list is empty. More...
 
const char * front () const
 Get first string. More...
 
const char * back () const
 Get last string. More...
 
const char * nextof (const char *str) const
 Get next string. More...
 
const char * prevof (const char *str) const
 Get previous string. More...
 
void clear ()
 Clear the list. More...
 
ROC_ATTR_NODISCARD bool push_back (const char *str)
 Append string to the list. More...
 
ROC_ATTR_NODISCARD bool push_back (const char *str_begin, const char *str_end)
 Append string from a range to the list. More...
 
ROC_ATTR_NODISCARD const char * find (const char *str)
 Find string in the list. More...
 
ROC_ATTR_NODISCARD const char * find (const char *str_begin, const char *str_end)
 Find string in the list. More...
 

Detailed Description

Dynamic list of strings.

Strings are stored in a countinous dynamically-growing array. Each string is stored in a block with a header and footer, which both store block length. This allow fast iteration in both directions.

++--------+--------+---------+--------++-----------
|| Header | string | padding | Footer || Header ...
++--------+--------+---------+--------++-----------
@ Header
PayloadID comes before payload.
Definition: headers.h:32
@ Footer
PayloadID comes after payload.
Definition: headers.h:33

Definition at line 36 of file string_list.h.

Constructor & Destructor Documentation

◆ StringList()

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

Initialize empty string list.

Member Function Documentation

◆ back()

const char* roc::core::StringList::back ( ) const

Get last string.

Returns
the last string in the list or NULL if it is empty.

◆ clear()

void roc::core::StringList::clear ( )

Clear the list.

◆ find() [1/2]

ROC_ATTR_NODISCARD const char* roc::core::StringList::find ( const char *  str)

Find string in the list.

Returns
the string in the list or NULL if it is not found.

◆ find() [2/2]

ROC_ATTR_NODISCARD const char* roc::core::StringList::find ( const char *  str_begin,
const char *  str_end 
)

Find string in the list.

Returns
the string in the list or NULL if it is not found.

◆ front()

const char* roc::core::StringList::front ( ) const

Get first string.

Returns
the first string in the list or NULL if it is empty.

◆ is_empty()

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

Check if list is empty.

◆ nextof()

const char* roc::core::StringList::nextof ( const char *  str) const

Get next string.

Returns
the first string of the given string or NULL if it is the last string.
Remarks
str should be a pointer returned by front(), nextof(), or prevof(). These pointers are invalidated by methods that modify the list.

◆ prevof()

const char* roc::core::StringList::prevof ( const char *  str) const

Get previous string.

Returns
the last string of the given string or NULL if it is the first string.
Remarks
str should be a pointer returned by back(), nextof(), or prevof(). These pointers are invalidated by methods that modify the list.

◆ push_back() [1/2]

ROC_ATTR_NODISCARD bool roc::core::StringList::push_back ( const char *  str)

Append string to the list.

Remarks
Reallocates memory if necessary.
Returns
false if allocation failed.

◆ push_back() [2/2]

ROC_ATTR_NODISCARD bool roc::core::StringList::push_back ( const char *  str_begin,
const char *  str_end 
)

Append string from a range to the list.

Remarks
Reallocates memory if necessary.
Returns
false if allocation failed.

◆ size()

size_t roc::core::StringList::size ( ) const

Get number of elements.


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