Commanders
Arduino buttons/bus library
|
#include "Chain.hpp"
Public Member Functions | |
CMDRSCHAINEDLIST () | |
void | AddItem (T *input) |
void | NextCurrent () |
Public Attributes | |
CMDRSCHAINEDLISTITEM< T > * | pFirst |
CMDRSCHAINEDLISTITEM< T > * | pCurrentItem |
This class describes a chained list of items (https://en.wikipedia.org/wiki/Linked_list). It can be called also a linked list. This is an elegant way to build a list without any big allocation, bypassing the needs to estimate a minimum size and to increase or decrease this size during execution. The disadvantage is a slower and more complex way to access to an item on the list, and a more complex way to add a new item.
To start, a chained list needs a starting pointer referencing the first item of the list. After that, each item have a pointer to the next item. If this pointer is NULL, this is the end of the list !
The 'T' type can be of any type, including base types like int or char. But keep in mind that each item must save a pointer to the next item. If the size of the pointer is greater than the size of the item itself, consider using a true array...
A notion of 'current item' is used, to let the user of the list to move through the list without doing a loop itself...
|
inline |
Default constructor.
void CMDRSCHAINEDLIST< T >::AddItem | ( | T * | input | ) |
Add a new item to the list.
input | Address of the item to add. |
void CMDRSCHAINEDLIST< T >::NextCurrent | ( | ) |
Move the current pointer to the next one in the list. If the current was the last one, the current pointer will be set to the start of the list, its first item.
CMDRSCHAINEDLISTITEM<T>* CMDRSCHAINEDLIST< T >::pCurrentItem |
Address of current item in the chain, or NULL for none.
CMDRSCHAINEDLISTITEM<T>* CMDRSCHAINEDLIST< T >::pFirst |
Address of next element in chain, or NULL for none. In this case the list is empty.