RNBO: RNBO::listbase< T > Class Template Reference
A container similar to a JavaScript array. More...
#include <RNBO_List.h>
Public Member Functions | |
listbase () | |
Default constructor. | |
template<typename... Ts> | |
listbase (Ts ... args) | |
Constructor. More... | |
listbase (const listbase &l) | |
Copy constructor. More... | |
listbase (listbase &&l) | |
Move constructor. | |
~listbase () | |
Destructor. | |
T & | operator[] (size_t i) |
Get a reference to the element at specified location with bounds checking. More... | |
T | operator[] (size_t i) const |
Get an element at a specified location with bounds checking. More... | |
listbase * | operator-> () |
const listbase * | operator-> () const |
listbase & | operator= (const listbase &l) |
Copy assignment operator. | |
void | push (T item) |
Append an item to the list. More... | |
T | pop () |
Remove an item from the end of the list and return it. More... | |
T | shift () |
Remove the first item from the list and return it. More... | |
listbase | concat (T item) const |
Create a new listbase by copying the original and appending an item. More... | |
listbase | concat (const listbase &item) const |
Concatenate a list with another. More... | |
listbase & | fill (T value, size_t start=0, size_t end=0) |
Fill a list with a value. More... | |
template<typename... Ts> | |
void | unshift (Ts ... args) |
Add one or more elements to the beginning of the list. More... | |
template<typename... Ts> | |
listbase< T > | splice (Int start, size_t deleteCount, Ts ... args) |
Modify part a list in place. More... | |
listbase | slice (int start=0, int end=0) const |
Get a shallow copy of a portion of a list. More... | |
bool | includes (T value, int fromIndex=0) const |
Determine whether an element is in the list. More... | |
int | indexOf (T value, int fromIndex=0) const |
Find the first index of an element's occurrence in the list. More... | |
listbase & | reverse () |
Reverse the list in place. More... | |
void | reserve (size_t size) |
Pre-allocate memory for a list. More... | |
T * | inner () const |
get a pointer to the internal values, for memcopy etc | |
Data Fields | |
size_t | length = 0 |
the number of elements in the list | |
Protected Member Functions | |
void | allocate (size_t size, bool keepValues) |
Protected Attributes | |
T * | _values |
the contents of the list | |
size_t | _allocatedLength |
how much memory has been allocated for the list | |
T | _dummy = static_cast<T>(0) |
a dummy variable to accept out of bounds array assignments rather than allow out of bounds memory acess | |
Detailed Description
template<typename T>
class RNBO::listbase< T >
A container similar to a JavaScript array.
Elements of listbase are stored contiguously in memory making this container more similar to std::vector than std::list. The listbase is resized only when adding elements; memory is allocated when elements are added, but memory is not freed when removing elements.
- Template Parameters
-
type of object stored in the container
Constructor & Destructor Documentation
◆ listbase() [1/2]
Constructor.
- Template Parameters
-
type of items in the listbase
◆ listbase() [2/2]
|
inline |
Copy constructor.
- Template Parameters
-
listbase the listbase to copy from
Member Function Documentation
◆ concat() [1/2]
|
inline |
Concatenate a list with another.
- Parameters
-
item the item to append to the list copy
- Returns
- a copy of the original list with
item
appended
◆ concat() [2/2]
|
inline |
Create a new listbase by copying the original and appending an item.
- Parameters
-
item the item to append to the list copy
- Returns
- a copy of the original list with
item
appended
◆ fill()
|
inline |
Fill a list with a value.
- Parameters
-
value the value to fill with start the index to begin filling from end the index to end filling at; end = 0
sets the endpoint to the last element
- Returns
- a reference to the list
◆ includes()
|
inline |
Determine whether an element is in the list.
- Parameters
-
value the element to search for fromIndex the position to begin searching from
- Returns
- true if the value is found, false otherwise
◆ indexOf()
|
inline |
Find the first index of an element's occurrence in the list.
- Parameters
-
value the element to locate fromIndex the index to begin searching from. If the value is negative, begins searching from 0.
- Returns
- the index of the first matching element in the list; -1 if the element is not found
◆ operator[]() [1/2]
|
inline |
Get a reference to the element at specified location with bounds checking.
◆ operator[]() [2/2]
|
inline |
Get an element at a specified location with bounds checking.
◆ pop()
|
inline |
Remove an item from the end of the list and return it.
- Returns
- the last item from the list
◆ push()
|
inline |
Append an item to the list.
- Parameters
-
item an item of the same type as other elements in the list
◆ reserve()
|
inline |
Pre-allocate memory for a list.
- Parameters
-
size the number of elements for which to reserve space
◆ reverse()
|
inline |
Reverse the list in place.
- Returns
- a reference to the list
◆ shift()
|
inline |
Remove the first item from the list and return it.
Note that this moves all items in memory from locations 1..n
to 0..n-1
.
- Returns
- the first item of the list if one exists, 0 otherwise
◆ slice()
|
inline |
Get a shallow copy of a portion of a list.
- Parameters
-
start the beginning index end the end index; 0 is the final element and negative values are offset from the end
- Returns
- a shallow copy of a portion of a list
◆ splice()
|
inline |
Modify part a list in place.
- Template Parameters
-
Ts
- Parameters
-
start the beginning index. If start
is greater than the length of the list, splice uses the length of the list.deleteCount the number of elements to remove from the beginning of the list args items to add to the list
◆ unshift()
|
inline |
Add one or more elements to the beginning of the list.
- Template Parameters
-
Ts type of elements to add to the list
- Parameters
-
args elements to add
The documentation for this class was generated from the following file:
- common/RNBO_List.h