Commanders
Arduino buttons/bus library
CMDRSCHAINEDLIST< T > Class Template Reference

#include "Chain.hpp"

Public Member Functions

 CMDRSCHAINEDLIST ()
 
void AddItem (T *input)
 
void NextCurrent ()
 

Public Attributes

CMDRSCHAINEDLISTITEM< T > * pFirst
 
CMDRSCHAINEDLISTITEM< T > * pCurrentItem
 

Detailed Description

template<class T>
class CMDRSCHAINEDLIST< T >

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...

Definition at line 33 of file Chain.hpp.

Constructor & Destructor Documentation

template<class T >
CMDRSCHAINEDLIST< T >::CMDRSCHAINEDLIST ( )
inline

Default constructor.

Definition at line 42 of file Chain.hpp.

Member Function Documentation

template<class T >
void CMDRSCHAINEDLIST< T >::AddItem ( T *  input)

Add a new item to the list.

Parameters
inputAddress of the item to add.

Definition at line 61 of file Chain.hpp.

template<class T >
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.

Definition at line 85 of file Chain.hpp.

Member Data Documentation

template<class T >
CMDRSCHAINEDLISTITEM<T>* CMDRSCHAINEDLIST< T >::pCurrentItem

Address of current item in the chain, or NULL for none.

Definition at line 39 of file Chain.hpp.

template<class T >
CMDRSCHAINEDLISTITEM<T>* CMDRSCHAINEDLIST< T >::pFirst

Address of next element in chain, or NULL for none. In this case the list is empty.

Definition at line 37 of file Chain.hpp.


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