Monado OpenXR Runtime
xrt::auxiliary::util::StringList Class Reference

A collection of strings (const char *), like a list of extensions to enable. More...

#include <util/u_string_list.hpp>

Public Member Functions

 StringList ()=default
 Construct a string list. More...
 
 StringList (uint32_t capacity)
 Construct a string list with the given capacity. More...
 
 StringList (StringList &&)=default
 
 StringList (StringList const &)=default
 
StringListoperator= (StringList &&)=default
 
StringListoperator= (StringList const &)=default
 
template<uint32_t N>
 StringList (const char *(&arr)[N])
 Construct a string list with the given items. More...
 
uint32_t size () const noexcept
 Get the size of the array (the number of strings) More...
 
const char *const * data () const noexcept
 Get the data pointer of the array. More...
 
void push_back (const char *str)
 Append a new string to the list. More...
 
template<uint32_t N>
void push_back_all (const char *(&arr)[N])
 Add all given items. More...
 
bool contains (const char *str)
 Check if the string is in the list. More...
 
bool push_back_unique (const char *str)
 Append a new string to the list if it doesn't match any existing string. More...
 

Detailed Description

A collection of strings (const char *), like a list of extensions to enable.

This version is only for use with strings that will outlive this object, preferably string literals.

Size is limited to one less than the max value of uint32_t which shouldn't be a problem, the size really should be much smaller (especially if you use push_back_unique()).

Constructor & Destructor Documentation

◆ StringList() [1/3]

xrt::auxiliary::util::StringList::StringList ( )
default

Construct a string list.

◆ StringList() [2/3]

xrt::auxiliary::util::StringList::StringList ( uint32_t  capacity)
inline

Construct a string list with the given capacity.

◆ StringList() [3/3]

template<uint32_t N>
xrt::auxiliary::util::StringList::StringList ( const char *(&)  arr[N])
inline

Construct a string list with the given items.

References push_back().

Member Function Documentation

◆ contains()

bool xrt::auxiliary::util::StringList::contains ( const char *  str)
inline

Check if the string is in the list.

(Comparing string contents, not pointers)

Parameters
stra non-null, null-terminated string.
Returns
true if the string is in the list.

Referenced by u_string_list_contains().

◆ data()

const char *const * xrt::auxiliary::util::StringList::data ( ) const
inlinenoexcept

Get the data pointer of the array.

Referenced by u_string_list::u_string_list_get_data().

◆ push_back()

void xrt::auxiliary::util::StringList::push_back ( const char *  str)
inline

Append a new string to the list.

Parameters
stra non-null, null-terminated string that must live at least as long as the list, preferably a string literal.
Exceptions
std::out_of_rangeif you have a ridiculous number of strings in your list already, std::invalid_argument if you pass a null pointer.

Referenced by push_back_all(), StringList(), u_string_list::u_string_list_append(), and u_string_list::u_string_list_append_array().

◆ push_back_all()

template<uint32_t N>
void xrt::auxiliary::util::StringList::push_back_all ( const char *(&)  arr[N])
inline

Add all given items.

Exceptions
thesame as what push_back() throws

References push_back().

◆ push_back_unique()

bool xrt::auxiliary::util::StringList::push_back_unique ( const char *  str)
inline

Append a new string to the list if it doesn't match any existing string.

(Comparing string contents, not pointers)

This does a simple linear search, because it is assumed that the size of this list is fairly small.

Parameters
stra non-null, null-terminated string that must live at least as long as the list, preferably a string literal.
Returns
true if we added it
Exceptions
std::out_of_rangeif you have a ridiculous number of strings in your list already, std::invalid_argument if you pass a null pointer.

Referenced by u_string_list::u_string_list_append_unique().

◆ size()

uint32_t xrt::auxiliary::util::StringList::size ( ) const
inlinenoexcept

Get the size of the array (the number of strings)

Referenced by u_string_list::u_string_list_get_size().


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