Mountain
1.0.0
Simple C++ 2D Game Framework
|
A dynamic array implementation. Wrapper around the std::vector
class.
More...
#include <list.hpp>
Public Types | |
using | Iterator = typename std::vector< T >::iterator |
using | ConstIterator = typename std::vector< T >::const_iterator |
using | ReverseIterator = typename std::vector< T >::reverse_iterator |
using | ConstReverseIterator = typename std::vector< T >::const_reverse_iterator |
using | Type = T |
The type of the List<T>, refers to T. | |
Public Member Functions | |
List ()=default | |
Creates an empty list with a capacity of 0. | |
List (size_t size) | |
Creates a list with the specified size, and fills it with the default value of T. More... | |
List (size_t size, const T &defaultValue) | |
Creates a list with the specified size, and fills it with the provided value. More... | |
List (size_t size, const T *values) | |
Creates a list with the specified size, and fills it with the provided values. More... | |
template<size_t Size> | |
List (const std::array< T, Size > &array) | |
Creates a list with the specified array. More... | |
List (const std::vector< T > &vector) | |
Creates a list with the specified vector. This creates a copy of the given vector. More... | |
List (std::vector< T > &&vector) | |
Creates a list with the specified vector. More... | |
List (Iterator b, Iterator e) | |
Creates a list with the specified vector. | |
List (const std::initializer_list< T > &values) | |
Creates a list with the specified values. More... | |
~List ()=default | |
Destroys the list. | |
void | Resize (size_t size) |
Resizes a specified amount of elements in the list. More... | |
void | Clear () |
Clears the list. | |
bool_t | Empty () const |
Returns whether the list is empty. This is equivalent to doing GetSize() == 0 . | |
T & | Add () |
Adds a default element to the end of the list (calls the default constructor of T) | |
void | Add (const T &element) |
Adds a specified element to the end of the list. More... | |
void | Add (T &&element) |
Adds a specified element to the end of the list. More... | |
void | AddRange (const T *data, size_t count) |
Adds a range of elements to the end of the list. More... | |
void | AddRange (const std::initializer_list< T > &values) |
Adds a range of elements to the end of the list. More... | |
void | Fill (const T &value) |
Fills the list with a specified value. More... | |
void | Fill (T &&value) |
Fills the list with a specified value. More... | |
template<class... Args> | |
void | Emplace (Args &&... args) |
Constructs a new element and adds it to the end of the list. More... | |
void | PopBack () |
Removes the last element of the list. | |
void | Insert (size_t index) |
Inserts an element at the given position using the default constructor. More... | |
void | Insert (const T &element, size_t index) |
Inserts an element in the list at the given position. More... | |
void | Insert (T &&element, size_t index) |
Inserts an element in the list at the given position. More... | |
void | Remove (const T &element) |
Removes an element from the list (only removes the first occurence it finds) More... | |
void | RemoveAt (size_t index) |
Removes an element from the list at a given index. More... | |
void | RemoveAt (ConstIterator iterator) |
Removes an element from the list at a given iterator. More... | |
void | RemoveRange (size_t start, size_t end) |
Removes a range of elements from the list. More... | |
bool_t | Contains (const T &element) const |
Checks if the list contains a specified element. More... | |
void | Iterate (const std::function< void(T *)> &lambda) |
Allows iteration over the list with a lambda. More... | |
void | Iterate (const std::function< void(const T *)> &lambda) const |
Allows iteration over the list with a lambda. More... | |
bool_t | Exists (const std::function< bool_t(const T *)> &lambda) const |
Checks if an element exists that fulfills the requirements provided in a lambda. More... | |
T * | Find (const std::function< bool_t(const T *)> &lambda) |
Tries to find an element that fulfills the requirements provided in a lambda. More... | |
const T * | Find (const std::function< bool_t(const T *)> &lambda) const |
Tries to find an element that fulfills the requirements provided in a lambda. More... | |
List< T * > | FindAll (const std::function< bool_t(const T *)> &lambda) |
Tries to find all elements that fulfill the requirements provided in a lambda. More... | |
List< const T * > | FindAll (const std::function< bool_t(const T *)> &lambda) const |
Tries to find all elements that fulfill the requirements provided in a lambda. More... | |
size_t | FindPosition (const std::function< bool_t(const T *)> &lambda) const |
Tries to find an element that fulfills the requirements provided in a lambda. More... | |
T * | Find (const std::function< bool_t(const T *, size_t)> &lambda) |
void | Sort (std::function< bool_t(const T &left, const T &right)> predicate=std::less()) |
T * | GetData () |
Gets the underlying pointer to the list. More... | |
const T * | GetData () const |
Gets the underlying pointer to the list. More... | |
size_t | GetSize () const |
Gets the size of the list. More... | |
size_t | GetCapacity () const |
Gets the capacity of the list. More... | |
std::vector< T >::reference | operator[] (size_t index) |
Gets an element of the list at a specified index. More... | |
std::vector< T >::const_reference | operator[] (size_t index) const |
Gets an element of the list at a specified index. More... | |
const T & | Front () const |
T & | Front () |
const T & | Back () const |
T & | Back () |
Iterator | Begin () |
Iterator | End () |
ConstIterator | CBegin () const |
ConstIterator | CEnd () const |
ReverseIterator | RBegin () |
ReverseIterator | REnd () |
ConstReverseIterator | CrBegin () const |
ConstReverseIterator | CrEnd () const |
A dynamic array implementation. Wrapper around the std::vector
class.
A more user-friendly list than std::vector
, based on how List
is done in C# The internal structure and workings are similar to how std::vector works, it uses a capacity that grows exponentially based on powers of 2
T | Type stored |
|
explicit |
Creates a list with the specified size, and fills it with the default value of T.
size | List size |
|
explicit |
Creates a list with the specified size, and fills it with the provided value.
size | List size |
defaultValue | Default value |
|
explicit |
Creates a list with the specified size, and fills it with the provided values.
size | List size |
values | Provided values |
|
explicit |
Creates a list with the specified array.
Size | The array size |
array | Array |
|
explicit |
Creates a list with the specified vector. This creates a copy of the given vector.
vector | Vector |
|
explicit |
Creates a list with the specified vector.
vector | Vector |
Mountain::List< T >::List | ( | const std::initializer_list< T > & | values | ) |
Creates a list with the specified values.
values | Values |
void Mountain::List< T >::Add | ( | const T & | element | ) |
Adds a specified element to the end of the list.
element | Element |
void Mountain::List< T >::Add | ( | T && | element | ) |
Adds a specified element to the end of the list.
element | Element |
void Mountain::List< T >::AddRange | ( | const T * | data, |
size_t | count | ||
) |
Adds a range of elements to the end of the list.
data | Data |
count | Number of elements (array size of data) |
void Mountain::List< T >::AddRange | ( | const std::initializer_list< T > & | values | ) |
Adds a range of elements to the end of the list.
values | Values |
bool_t Mountain::List< T >::Contains | ( | const T & | element | ) | const |
Checks if the list contains a specified element.
element | Element |
Constructs a new element and adds it to the end of the list.
Args | Constructor element types |
args | Arguments |
bool_t Mountain::List< T >::Exists | ( | const std::function< bool_t(const T *)> & | lambda | ) | const |
Checks if an element exists that fulfills the requirements provided in a lambda.
The lambda returns bool_t, and has a pointer to the current element as a parameters
lambda | Function lambda |
void Mountain::List< T >::Fill | ( | const T & | value | ) |
Fills the list with a specified value.
value | Value |
void Mountain::List< T >::Fill | ( | T && | value | ) |
Fills the list with a specified value.
value | Value |
T* Mountain::List< T >::Find | ( | const std::function< bool_t(const T *)> & | lambda | ) |
Tries to find an element that fulfills the requirements provided in a lambda.
The lambda returns bool_t, and has a pointer to the current element as a parameter
lambda | Function lambda |
const T* Mountain::List< T >::Find | ( | const std::function< bool_t(const T *)> & | lambda | ) | const |
Tries to find an element that fulfills the requirements provided in a lambda.
The lambda returns bool_t, and has a pointer to the current element as a parameter
lambda | Function lambda |
T* Mountain::List< T >::Find | ( | const std::function< bool_t(const T *, size_t)> & | lambda | ) |
The lambda returns bool_t, and has a pointer to the current element and its index as parameters
lambda | Function lambda |
List<T*> Mountain::List< T >::FindAll | ( | const std::function< bool_t(const T *)> & | lambda | ) |
Tries to find all elements that fulfill the requirements provided in a lambda.
The lambda returns bool_t, and has a pointer to the current element as a parameter
lambda | Function lambda |
List<const T*> Mountain::List< T >::FindAll | ( | const std::function< bool_t(const T *)> & | lambda | ) | const |
Tries to find all elements that fulfill the requirements provided in a lambda.
The lambda returns bool_t, and has a pointer to the current element as a parameter
lambda | Function lambda |
size_t Mountain::List< T >::FindPosition | ( | const std::function< bool_t(const T *)> & | lambda | ) | const |
Tries to find an element that fulfills the requirements provided in a lambda.
lambda | Function lambda |
size_t Mountain::List< T >::GetCapacity | ( | ) | const |
Gets the capacity of the list.
T* Mountain::List< T >::GetData | ( | ) |
Gets the underlying pointer to the list.
const T* Mountain::List< T >::GetData | ( | ) | const |
Gets the underlying pointer to the list.
size_t Mountain::List< T >::GetSize | ( | ) | const |
Gets the size of the list.
void Mountain::List< T >::Insert | ( | size_t | index | ) |
Inserts an element at the given position using the default constructor.
index | Index |
void Mountain::List< T >::Insert | ( | const T & | element, |
size_t | index | ||
) |
Inserts an element in the list at the given position.
element | Element |
index | Index |
void Mountain::List< T >::Insert | ( | T && | element, |
size_t | index | ||
) |
Inserts an element in the list at the given position.
element | Element |
index | Index |
void Mountain::List< T >::Iterate | ( | const std::function< void(T *)> & | lambda | ) |
Allows iteration over the list with a lambda.
The lambda returns void, and has a pointer to the current element as a parameters
lambda | Function lambda |
void Mountain::List< T >::Iterate | ( | const std::function< void(const T *)> & | lambda | ) | const |
Allows iteration over the list with a lambda.
The lambda returns void, and has a pointer to the current element as a parameters
lambda | Function lambda |
std::vector<T>::reference Mountain::List< T >::operator[] | ( | size_t | index | ) |
Gets an element of the list at a specified index.
index | Index |
std::out_of_range | If index >= list size |
std::vector<T>::const_reference Mountain::List< T >::operator[] | ( | size_t | index | ) | const |
Gets an element of the list at a specified index.
index | Index |
std::out_of_range | If index >= list size |
void Mountain::List< T >::Remove | ( | const T & | element | ) |
Removes an element from the list (only removes the first occurence it finds)
element | Element |
void Mountain::List< T >::RemoveAt | ( | size_t | index | ) |
Removes an element from the list at a given index.
index | Index |
void Mountain::List< T >::RemoveAt | ( | ConstIterator | iterator | ) |
Removes an element from the list at a given iterator.
iterator | Iterator |
void Mountain::List< T >::RemoveRange | ( | size_t | start, |
size_t | end | ||
) |
Removes a range of elements from the list.
start | Starting index |
end | End index |
void Mountain::List< T >::Resize | ( | size_t | size | ) |
Resizes a specified amount of elements in the list.
size | New size |