libpromeki main
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
StringList Class Reference

Manages a list of strings. More...

#include <stringlist.h>

Inheritance diagram for StringList:
Collaboration diagram for StringList:

Public Member Functions

 StringList (size_t ct, const char **list)
 Constructs a StringList from a C-style string array.
 
String join (const String &delimiter) const
 Joins all strings using the given delimiter.
 
StringList filter (TestFunc func) const
 Returns a new StringList containing only strings that match the predicate.
 
int indexOf (const String &val) const
 Returns the index of the first occurrence of a string, or -1 if not found.
 
 List ()=default
 Default constructor. Creates an empty list.
 
 List (size_t size)
 Constructs a list with a given number of default-constructed elements.
 
 List (size_t size, const T &defaultValue)
 Constructs a list with a given number of copies of a value.
 
 List (const List &other)
 Copy constructor.
 
 List (List &&other) noexcept
 Move constructor.
 
 List (std::initializer_list< T > initList)
 Constructs a list from an initializer list.
 
Listoperator+= (const T &item)
 Appends a single item to the back of the list.
 
Listoperator+= (T &&item)
 Appends a single item to the back of the list (move overload).
 
Listoperator+= (const List &list)
 Appends all items from another list to the back of this list.
 
Listoperator+= (List &&list)
 Appends all items from another list (move overload).
 
Listoperator= (const List &other)
 Copy assignment operator.
 
Listoperator= (List &&other) noexcept
 Move assignment operator.
 
Listoperator= (std::initializer_list< T > initList)
 Assigns from an initializer list, replacing all contents.
 
- Public Member Functions inherited from List< String >
 List ()=default
 Default constructor. Creates an empty list.
 
 List (size_t size)
 Constructs a list with a given number of default-constructed elements.
 
 List (size_t size, const String &defaultValue)
 Constructs a list with a given number of copies of a value.
 
 List (const List &other)
 Copy constructor.
 
 List (List &&other) noexcept
 Move constructor.
 
 List (std::initializer_list< String > initList)
 Constructs a list from an initializer list.
 
 ~List ()=default
 Destructor.
 
Listoperator= (const List &other)
 Copy assignment operator.
 
Listoperator= (List &&other) noexcept
 Move assignment operator.
 
Listoperator= (std::initializer_list< String > initList)
 Assigns from an initializer list, replacing all contents.
 
Listoperator+= (const String &item)
 Appends a single item to the back of the list.
 
Listoperator+= (String &&item)
 Appends a single item to the back of the list (move overload).
 
Listoperator+= (const List &list)
 Appends all items from another list to the back of this list.
 
Listoperator+= (List &&list)
 Appends all items from another list (move overload).
 
Iterator begin () noexcept
 Returns a mutable iterator to the first element.
 
ConstIterator begin () const noexcept
 Returns a const iterator to the first element.
 
ConstIterator cbegin () const noexcept
 Returns a const iterator to the first element.
 
ConstIterator constBegin () const noexcept
 Returns a const iterator to the first element.
 
RevIterator rbegin () noexcept
 Returns a mutable reverse iterator to the last element.
 
RevIterator revBegin () noexcept
 Returns a mutable reverse iterator to the last element.
 
ConstRevIterator crbegin () const noexcept
 Returns a const reverse iterator to the last element.
 
ConstRevIterator constRevBegin () const noexcept
 Returns a const reverse iterator to the last element.
 
Iterator end () noexcept
 Returns a mutable iterator to one past the last element.
 
ConstIterator end () const noexcept
 Returns a const iterator to one past the last element.
 
ConstIterator cend () const noexcept
 Returns a const iterator to one past the last element.
 
ConstIterator constEnd () const noexcept
 Returns a const iterator to one past the last element.
 
RevIterator rend () noexcept
 Returns a mutable reverse iterator to one before the first element.
 
RevIterator revEnd () noexcept
 Returns a mutable reverse iterator to one before the first element.
 
ConstRevIterator crend () const noexcept
 Returns a const reverse iterator to one before the first element.
 
ConstRevIterator constRevEnd () const noexcept
 Returns a const reverse iterator to one before the first element.
 
Stringat (size_t index)
 Returns a reference to the element at index with bounds checking.
 
const Stringat (size_t index) const
 Returns a reference to the element at index with bounds checking.
 
Stringoperator[] (size_t index)
 Returns a reference to the element at index without bounds checking.
 
const Stringoperator[] (size_t index) const
 Returns a reference to the element at index without bounds checking.
 
Stringfront ()
 Returns a reference to the first element.
 
const Stringfront () const
 Returns a reference to the first element.
 
Stringback ()
 Returns a reference to the last element.
 
const Stringback () const
 Returns a reference to the last element.
 
Stringdata () noexcept
 Returns a pointer to the underlying contiguous storage.
 
const Stringdata () const noexcept
 Returns a pointer to the underlying contiguous storage.
 
bool isEmpty () const noexcept
 Returns true if the list has no elements.
 
size_t size () const noexcept
 Returns the number of elements in the list.
 
size_t maxSize () const noexcept
 Returns the maximum number of elements the list can theoretically hold.
 
void reserve (size_t newCapacity)
 Pre-allocates storage for at least newCapacity elements.
 
size_t capacity () const noexcept
 Returns the number of elements the list can hold without reallocating.
 
void shrink ()
 Releases unused memory by shrinking capacity to fit the current size.
 
void clear () noexcept
 Removes all elements from the list.
 
Iterator insert (ConstIterator pos, const String &value)
 Inserts a value before the position given by an iterator.
 
Iterator insert (ConstIterator pos, String &&value)
 Inserts a value before the position given by an iterator (move overload).
 
Iterator insert (size_t pos, const String &value)
 Inserts a value before the given index.
 
Iterator insert (size_t pos, String &&value)
 Inserts a value before the given index (move overload).
 
Iterator emplace (ConstIterator pos, Args &&...args)
 Emplaces an object right before the given position.
 
Iterator emplace (size_t pos, Args &&...args)
 Emplaces an object right before the given index.
 
Iterator remove (ConstIterator pos)
 Removes the element at the given iterator position.
 
Iterator remove (size_t index)
 Removes the element at the given index.
 
Iterator erase (ConstIterator first, ConstIterator last)
 Removes elements in the range [first, last).
 
void removeIf (TestFunc func)
 Runs a test function on all the items and removes them if it returns true.
 
bool removeFirst (const String &value)
 Removes the first instance of value from the list.
 
void pushToBack (const String &value)
 Pushes an item onto the back of the list.
 
void pushToBack (const List< String > &list)
 Pushes all items from another list to the back of this list.
 
void pushToBack (String &&value)
 Moves an item onto the back of the list.
 
void pushToBack (List< String > &&list)
 Moves all items from another list to the back of this list.
 
StringemplaceToBack (Args &&...args)
 Emplaces an object on the back of the list.
 
void popFromBack ()
 Removes the last element from the list.
 
void resize (size_t newSize)
 Resizes the list.
 
void resize (size_t newSize, const String &value)
 Resizes the list, constructs any new items with the given value.
 
void swap (List< String > &other) noexcept
 Swaps the list data with another list of the same type.
 
bool set (size_t index, const String &val)
 Sets an item in the list by index.
 
List< Stringsort () const
 Returns a sorted copy of this list.
 
List< Stringreverse () const
 Returns a reversed copy of this list.
 
List< Stringunique ()
 Returns a list of all the unique items in this list.
 
void forEach (Func &&func) const
 Calls func for every element.
 
bool contains (const String &val) const
 Returns true if the list contains the given value.
 
ssize_t indexOf (const String &value) const
 Returns the index of the first occurrence of value.
 
ssize_t lastIndexOf (const String &value) const
 Returns the index of the last occurrence of value.
 
size_t count (const String &value) const
 Returns the number of occurrences of value.
 
List< Stringmid (size_t pos, size_t length) const
 Returns a sublist starting at pos with length elements.
 

Additional Inherited Members

- Public Types inherited from List< String >
using Ptr = SharedPtr< List >
 Shared pointer type for List.
 
using Data = typename std::vector< String >
 Underlying std::vector storage type.
 
using Iterator = typename std::vector< String >::iterator
 Mutable forward iterator.
 
using ConstIterator = typename std::vector< String >::const_iterator
 Const forward iterator.
 
using RevIterator = typename std::vector< String >::reverse_iterator
 Mutable reverse iterator.
 
using ConstRevIterator = typename std::vector< String >::const_reverse_iterator
 Const reverse iterator.
 
using TestFunc = std::function< bool(const String &)>
 Predicate function type used by removeIf().
 

Detailed Description

Manages a list of strings.

Constructor & Destructor Documentation

◆ StringList()

StringList::StringList ( size_t  ct,
const char **  list 
)
inline

Constructs a StringList from a C-style string array.

Parameters
ctNumber of strings in the array.
listArray of C-string pointers.

Member Function Documentation

◆ filter()

StringList StringList::filter ( TestFunc  func) const
inline

Returns a new StringList containing only strings that match the predicate.

Parameters
funcA callable that takes a const String & and returns true to keep the item.
Returns
A new StringList with matching strings.

◆ indexOf()

int StringList::indexOf ( const String val) const
inline

Returns the index of the first occurrence of a string, or -1 if not found.

Parameters
valThe string to search for.
Returns
The zero-based index, or -1 if not found.

◆ join()

String StringList::join ( const String delimiter) const
inline

Joins all strings using the given delimiter.

Parameters
delimiterThe separator to place between each string.
Returns
A single String with all elements joined.

◆ List() [1/3]

List< T >::List ( size_t  size)
inlineexplicit

Constructs a list with a given number of default-constructed elements.

Parameters
sizeNumber of elements to create.

◆ List() [2/3]

List< T >::List ( size_t  size,
const T defaultValue 
)
inline

Constructs a list with a given number of copies of a value.

Parameters
sizeNumber of elements to create.
defaultValueValue to copy into each element.

◆ List() [3/3]

List< T >::List ( std::initializer_list< T initList)
inline

Constructs a list from an initializer list.

Parameters
initListBrace-enclosed list of values.

◆ operator+=() [1/4]

List & List< T >::operator+= ( const List list)
inline

Appends all items from another list to the back of this list.

Parameters
listThe list to append.
Returns
Reference to this list.

◆ operator+=() [2/4]

List & List< T >::operator+= ( const T item)
inline

Appends a single item to the back of the list.

Parameters
itemThe item to append.
Returns
Reference to this list.

◆ operator+=() [3/4]

List & List< T >::operator+= ( List &&  list)
inline

Appends all items from another list (move overload).

Parameters
listThe list to move-append.
Returns
Reference to this list.

◆ operator+=() [4/4]

List & List< T >::operator+= ( T &&  item)
inline

Appends a single item to the back of the list (move overload).

Parameters
itemThe item to move-append.
Returns
Reference to this list.

◆ operator=()

List & List< T >::operator= ( std::initializer_list< T initList)
inline

Assigns from an initializer list, replacing all contents.

Parameters
initListBrace-enclosed list of values.
Returns
Reference to this list.

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