Arduino List Library  3.0.1
The Ultimate Collection of Lists
Data Structures | Public Member Functions | Protected Member Functions
AbstractList< T > Class Template Referenceabstract

Abstract class from which all lists can be derived. More...

#include <AbstractList.hpp>

Inheritance diagram for AbstractList< T >:
DoubleLinkedList< T > SingleLinkedList< T > List< T >

Data Structures

class  AbstractEntry
 

Public Member Functions

void add (T &value)
 Add a new entry at the end of the list. More...
 
virtual void addAtIndex (int index, T &value)=0
 Add the value to the list at the given index. The original entry at this index, and followings, will be placed directly after the new entry. More...
 
void addAll (int index, AbstractList< T > &list)
 Add all entries from the given list to this list at a specified index. The original entry at this index, and followings, will be placed directly after the entries of the given list. More...
 
void addAll (AbstractList< T > &list)
 Add all entries from the given list at the end of the list. More...
 
void addAll (int index, T *arr, const size_t arrSize)
 Add all entries from an array to this list at a specified index. The original entry at this index, and followings, will be placed directly after the entries of the given list. More...
 
void addAll (T *arr, const size_t arrSize)
 Add all entries from an array. More...
 
void addFirst (T &value)
 Add a new entry at the beginning of the list. More...
 
void addLast (T &value)
 Add a new entry at the end of the list. More...
 
get (const int index)
 Get the raw value at a specified index. More...
 
T * getMutableValue (const int index)
 Get the pointer to the mutable object at a specified index. More...
 
virtual void clear ()=0
 Remove all elements from the List.
 
virtual void remove (int index)=0
 Remove the entry at the given index. More...
 
virtual void removeFirst ()
 Remove the first entry from the list.
 
virtual void removeLast ()
 Remove the las entry from the list.
 
void removeAll ()
 Remove all elements from the List. More...
 
int getSize () const
 Get the number how many elements are saved in the list. More...
 
bool isMutable () const
 Check if the list is mutable. More...
 
bool isEmpty () const
 Check if the list is empty. More...
 
bool equals (AbstractList< T > &other)
 Compare two lists whether their attributes and entries are equal. More...
 
operator[] (const int index)
 Get the raw value at a specified index. More...
 
bool operator== (AbstractList< T > &other)
 Compare two lists whether their attributes and entries are equal. More...
 
bool operator!= (AbstractList< T > &other)
 Opposite of '=='. More...
 
void operator+ (T &value)
 Add a new entry at the end of the list. More...
 
void operator+ (AbstractList< T > &list)
 Add all entries from the given list at the end of the list. More...
 

Protected Member Functions

 AbstractList (const bool mutableList)
 Constructor of an AbstractList Object. More...
 
virtual T * getPointer (int index)=0
 Get a pointer to the element, stored at specific index. More...
 
void increaseSize ()
 Increase the size of the list by one. Should only be called after an insertion!
 
void decreaseSize ()
 Decrease the size of the list by one. Should only be called after an deletion!
 
void resetSize ()
 Reset the size to zero.
 
bool isIndexOutOfBounds (const int index) const
 Method to verify if the given index is out of the range of the list size. More...
 

Detailed Description

template<typename T>
class AbstractList< T >

Abstract class from which all lists can be derived.

Template Parameters
TData Type of entries, that should be stored in the list.

Constructor & Destructor Documentation

◆ AbstractList()

template<typename T>
AbstractList< T >::AbstractList ( const bool  mutableList)
inlineexplicitprotected

Constructor of an AbstractList Object.

Parameters
mutableListtrue if the list should be mutable; false otherwise.

Member Function Documentation

◆ getPointer()

template<typename T>
virtual T* AbstractList< T >::getPointer ( int  index)
protectedpure virtual

Get a pointer to the element, stored at specific index.

Parameters
indexThe index of the element to retrieve.
Returns
The nullptr, if the index is out of bounds, otherwise the address of the element.
Note
This is independent from the mutability of the list. It will always return the correct address (pointer) to the element.
Allowed indices are 0 to getSize() -1. If the index is out of bounds, a nullptr will be returned.

Implemented in DoubleLinkedList< T >, and SingleLinkedList< T >.

◆ isIndexOutOfBounds()

template<typename T>
bool AbstractList< T >::isIndexOutOfBounds ( const int  index) const
inlineprotected

Method to verify if the given index is out of the range of the list size.

Parameters
indexIndex to check.
Returns
true if the given index is in the range of the list; false otherwise

◆ add()

template<typename T>
void AbstractList< T >::add ( T &  value)
inline

Add a new entry at the end of the list.

Note
If this list is mutable, ensure, that all variables added to the lists do not go out-of-scope during all operations of the list.
Parameters
valueValue to add.
Note
Alias of addLast().
If this list is mutable, ensure, that all variables added to the lists do not go out-of-scope during all operations of the list.
See also
addLast()

◆ addAtIndex()

template<typename T>
virtual void AbstractList< T >::addAtIndex ( int  index,
T &  value 
)
pure virtual

Add the value to the list at the given index. The original entry at this index, and followings, will be placed directly after the new entry.

Note
Allowed indices are 0 to getSize(). If the index is out of bounds, nothing will happen.
If this list is mutable, ensure, that all variables added to the lists do not go out-of-scope during all operations of the list.
Parameters
indexIndex of the entry, where the value should be added.
valueValue of the new entry.

Implemented in DoubleLinkedList< T >, and SingleLinkedList< T >.

◆ addAll() [1/4]

template<typename T>
void AbstractList< T >::addAll ( int  index,
AbstractList< T > &  list 
)
inline

Add all entries from the given list to this list at a specified index. The original entry at this index, and followings, will be placed directly after the entries of the given list.

Note
The elements from the other list, remain untouched.
If the other list is mutable and the values saved in the lists are primitives, nothing happens.
Parameters
indexIndex of this list, at which all entries should be added.
listOther list from where to copy the entries.

◆ addAll() [2/4]

template<typename T>
void AbstractList< T >::addAll ( AbstractList< T > &  list)
inline

Add all entries from the given list at the end of the list.

Note
The elements from the other list, remain untouched.
If the other list is mutable and the values saved in the lists are primitives, nothing happens.
Parameters
listOther list to copy from.

◆ addAll() [3/4]

template<typename T>
void AbstractList< T >::addAll ( int  index,
T *  arr,
const size_t  arrSize 
)
inline

Add all entries from an array to this list at a specified index. The original entry at this index, and followings, will be placed directly after the entries of the given list.

Note
The elements from the other list, remain untouched.
If this list is mutable, ensure, that the other lists do not go out-of-scope during all operations of this list. If the other list is mutable, all values added to this lists are immutable.
Parameters
indexIndex of this list, at which all entries should be added.
arrArray.
arrSizeSize of the array.

◆ addAll() [4/4]

template<typename T>
void AbstractList< T >::addAll ( T *  arr,
const size_t  arrSize 
)
inline

Add all entries from an array.

Note
The elements from the other list, remain untouched.
Parameters
arrArray.
arrSizeSize of array.

◆ addFirst()

template<typename T>
void AbstractList< T >::addFirst ( T &  value)
inline

Add a new entry at the beginning of the list.

Note
If this list is mutable, ensure, that all variables added to the lists do not go out-of-scope during all operations of the list.
Parameters
valueValue to add.

◆ addLast()

template<typename T>
void AbstractList< T >::addLast ( T &  value)
inline

Add a new entry at the end of the list.

Note
If this list is mutable, ensure, that all variables added to the lists do not go out-of-scope during all operations of the list.
Parameters
valueValue to add.

◆ get()

template<typename T>
T AbstractList< T >::get ( const int  index)
inline

Get the raw value at a specified index.

Note
Allowed indices are 0 to getSize() - 1. If the index is out of bounds, undefined behaviour will happen. Please ne sure, that the index is valid!
This will method will always return an immutable object. If you want to get the mutable object from your mutable list, please use getMutableValue().
Parameters
indexIndex of the element to get.
Returns
Immutable object.

◆ getMutableValue()

template<typename T>
T* AbstractList< T >::getMutableValue ( const int  index)
inline

Get the pointer to the mutable object at a specified index.

Note
Allowed indices are 0 to getSize() -1. If the index is out of bounds, a nullptr will be returned.
This method will only return a valid object for a mutable list. A immutable list will return always the nullptr.
Parameters
indexIndex of teh element to get.
Returns
Mutable object, or nullptr if the index is out of bounds or the list is immutable.

◆ remove()

template<typename T>
virtual void AbstractList< T >::remove ( int  index)
pure virtual

Remove the entry at the given index.

Note
Allowed indices are 0 to getSize() - 1. If the index is out of bounds, nothing will happen.
Parameters
indexIndex of element to remove.

Implemented in DoubleLinkedList< T >, and SingleLinkedList< T >.

◆ removeAll()

template<typename T>
void AbstractList< T >::removeAll ( )
inline

Remove all elements from the List.

Note
Alias of clear().
See also
clear()

◆ getSize()

template<typename T>
int AbstractList< T >::getSize ( ) const
inline

Get the number how many elements are saved in the list.

Returns
Size of the list.

◆ isMutable()

template<typename T>
bool AbstractList< T >::isMutable ( ) const
inline

Check if the list is mutable.

Returns
true if the list is mutable; false otherwise.

◆ isEmpty()

template<typename T>
bool AbstractList< T >::isEmpty ( ) const
inline

Check if the list is empty.

Returns
true if the list is empty; false otherwise

◆ equals()

template<typename T>
bool AbstractList< T >::equals ( AbstractList< T > &  other)
inline

Compare two lists whether their attributes and entries are equal.

Note
If you use this list for non-primitive data types, check if the data type implements the != operator!
Parameters
otherSecond list to compare.
Returns
true if the lists are equal; false otherwise.

◆ operator[]()

template<typename T>
T AbstractList< T >::operator[] ( const int  index)
inline

Get the raw value at a specified index.

Note
Allowed indices are 0 to getSize() - 1. If the index is out of bounds, undefined behaviour will happen. Please ne sure, that the index is valid!
This will method will always return an immutable object. If you want to get the mutable object from your mutable list, please use getMutableValue().
Parameters
indexIndex of the element to get.
Returns
Immutable object.
See also
get()

◆ operator==()

template<typename T>
bool AbstractList< T >::operator== ( AbstractList< T > &  other)
inline

Compare two lists whether their attributes and entries are equal.

Note
If you use this list for non-primitive data types, check if the data type implements the != operator!
Parameters
otherSecond list to compare.
Returns
true if the lists are equal; false otherwise.
See also
equals()

◆ operator!=()

template<typename T>
bool AbstractList< T >::operator!= ( AbstractList< T > &  other)
inline

Opposite of '=='.

See also
equals()
Parameters
otherOther list to compare
Returns
true if the lists are not equal; false otherwise.

◆ operator+() [1/2]

template<typename T>
void AbstractList< T >::operator+ ( T &  value)
inline

Add a new entry at the end of the list.

Note
If this list is mutable, ensure, that all variables added to the lists do not go out-of-scope during all operations of the list.
Parameters
valueValue to add.
Note
Alias of addLast().
If this list is mutable, ensure, that all variables added to the lists do not go out-of-scope during all operations of the list.
See also
addLast()
Note
If this list is mutable, ensure, that all variables added to the lists do not go out-of-scope during all operations of the list.
See also
add()

◆ operator+() [2/2]

template<typename T>
void AbstractList< T >::operator+ ( AbstractList< T > &  list)
inline

Add all entries from the given list at the end of the list.

Note
The elements from the other list, remain untouched.
If the other list is mutable and the values saved in the lists are primitives, nothing happens.
Parameters
listOther list to copy from.
Note
If the other list is mutable and the values saved in the lists are primitives, nothing happens.
See also
addAll(AbstractList<T>&)

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