BNM 2.4.0
 
Loading...
Searching...
No Matches
BNM::Structures::Mono::List< T > Struct Template Reference

System.Generic.List type implementation. More...

#include <BasicMonoStructures.hpp>

Classes

struct  Enumerator
 System.Generic.List.Enumerator struct implementation. More...
 

Public Member Functions

T * GetData () const
 Get list data pointer.
 
int GetSize () const
 Get list size.
 
int GetCapacity () const
 Get list capacity.
 
int GetVersion () const
 Get list version.
 
std::vector< T > ToVector () const
 Convert list to std::vector.
 
void Add (T val)
 Add element to list.
 
int IndexOf (T val) const
 Get element index.
 
void RemoveAt (int index)
 Remove element at index.
 
bool Remove (T val)
 Remove element.
 
bool Resize (int newCapacity)
 Resize list.
 
Utils::DataIterator< T > At (int index) const
 Get element at index.
 
Utils::DataIterator< T > operator[] (int index) const
 
bool CopyFrom (const std::vector< T > &vec)
 Copy data from vector to current array.
 
bool CopyFrom (T *arr, int arrSize)
 Copy data from pointer to current list.
 
void Clear ()
 Remove all list elements.
 
bool Contains (T item) const
 Check if element is in list.
 
Enumerator GetEnumerator ()
 
get_Item (int index) const
 Get element at index.
 
void set_Item (int index, T item)
 Set element at index.
 
void Insert (int index, T item)
 Insert element to index.
 
void CopyTo (Array< T > *arr, int arrIndex) const
 Copy data from current list to some array.
 
void GrowIfNeeded (int n)
 Check if list has capacity for n elements.
 
void Shift (int start, int delta)
 Shift data in list.
 
bool SelfCheck () const
 Check if list isn't null.
 
constexpr List ()
 Create empty list.
 

Public Attributes

Array< T > * items {}
 
int size {}
 
int version {}
 
void * syncRoot {}
 

Detailed Description

template<typename T>
struct BNM::Structures::Mono::List< T >

System.Generic.List type implementation.

Template Parameters
TElement type

Member Function Documentation

◆ At()

template<typename T>
Utils::DataIterator< T > BNM::Structures::Mono::List< T >::At ( int index) const
inlinenodiscard

Get element at index.

Parameters
indexElement index
Returns
DataIterator of target element if index isn't out of bounds, otherwise empty DataIterator.

◆ Contains()

template<typename T>
bool BNM::Structures::Mono::List< T >::Contains ( T item) const
inlinenodiscard

Check if element is in list.

It's not quite like in C# because of its features.

Parameters
itemElement to check
Returns
True if element was found.

◆ CopyFrom() [1/2]

template<typename T>
bool BNM::Structures::Mono::List< T >::CopyFrom ( const std::vector< T > & vec)
inline

Copy data from vector to current array.

Parameters
vecSource vector
Returns
True if vector size is the same or less than array's size.

◆ CopyFrom() [2/2]

template<typename T>
bool BNM::Structures::Mono::List< T >::CopyFrom ( T * arr,
int arrSize )
inline

Copy data from pointer to current list.

Parameters
arrSource pointer
sizeSource pointer size
Returns
True if list is valid.

◆ get_Item()

template<typename T>
T BNM::Structures::Mono::List< T >::get_Item ( int index) const
inlinenodiscard

Get element at index.

Parameters
indexElement index
Returns
Element if index isn't out of bounds, otherwise default value.

◆ GetCapacity()

template<typename T>
int BNM::Structures::Mono::List< T >::GetCapacity ( ) const
inlinenodiscard

Get list capacity.

Returns
List capacity if list is valid, otherwise zero.

◆ GetData()

template<typename T>
T * BNM::Structures::Mono::List< T >::GetData ( ) const
inlinenodiscard

Get list data pointer.

Returns
List data pointer if list is valid, otherwise null.

◆ GetSize()

template<typename T>
int BNM::Structures::Mono::List< T >::GetSize ( ) const
inlinenodiscard

Get list size.

Returns
List size

◆ GetVersion()

template<typename T>
int BNM::Structures::Mono::List< T >::GetVersion ( ) const
inlinenodiscard

Get list version.

Returns
List version

◆ GrowIfNeeded()

template<typename T>
void BNM::Structures::Mono::List< T >::GrowIfNeeded ( int n)
inline

Check if list has capacity for n elements.

Parameters
nNumber of additional elements

◆ Insert()

template<typename T>
void BNM::Structures::Mono::List< T >::Insert ( int index,
T item )
inline

Insert element to index.

Parameters
indexElement index
itemNew element value

◆ Remove()

template<typename T>
bool BNM::Structures::Mono::List< T >::Remove ( T val)
inline

Remove element.

Returns
True if element is removed.

◆ Resize()

template<typename T>
bool BNM::Structures::Mono::List< T >::Resize ( int newCapacity)
inline

Resize list.

Parameters
newCapacityNew capacity for target list.
Returns
True if newCapacity is bigger than list's capacity.

◆ SelfCheck()

template<typename T>
bool BNM::Structures::Mono::List< T >::SelfCheck ( ) const
inlinenodiscard

Check if list isn't null.

Checks if list is not null and logs if it's null. It's used mostly internally in debug builds to crash proof code.

Returns
True if list isn't null.

◆ set_Item()

template<typename T>
void BNM::Structures::Mono::List< T >::set_Item ( int index,
T item )
inline

Set element at index.

Parameters
indexElement index
itemNew element value

◆ Shift()

template<typename T>
void BNM::Structures::Mono::List< T >::Shift ( int start,
int delta )
inline

Shift data in list.

Parameters
startStart index
deltaMove delta

◆ ToVector()

template<typename T>
std::vector< T > BNM::Structures::Mono::List< T >::ToVector ( ) const
inlinenodiscard

Convert list to std::vector.

Returns
Vector of elements if list is valid, otherwise empty vector.