Accessories
Arduino for motors and lights library.
ACCSCHAINEDLIST< T > Class Template Reference

#include "Chain.hpp"

Public Member Functions

 ACCSCHAINEDLIST ()
 
void AddItem (T *t)
 
void NextCurrent ()
 
void ResetCurrent ()
 
void StartCurrent ()
 
bool HasCurrent ()
 

Public Attributes

ACCSCHAINEDLISTITEM< T > * pFirst
 
ACCSCHAINEDLISTITEM< T > * pCurrentItem
 
bool HasCurrentNull
 

Detailed Description

template<class T>
class ACCSCHAINEDLIST< 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 disavantage 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 >
ACCSCHAINEDLIST< T >::ACCSCHAINEDLIST ( )
inline

Default constructor.

Definition at line 44 of file Chain.hpp.

Member Function Documentation

template<class T >
void ACCSCHAINEDLIST< T >::AddItem ( T *  t)

Add a new item to the list.

Parameters
tAddress of the item to add.

Definition at line 71 of file Chain.hpp.

template<class T >
bool ACCSCHAINEDLIST< T >::HasCurrent ( )
inline

Checks if the current is NULL.

Returns
True if the curent item is NULL.

Definition at line 59 of file Chain.hpp.

template<class T >
void ACCSCHAINEDLIST< 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 99 of file Chain.hpp.

template<class T >
void ACCSCHAINEDLIST< T >::ResetCurrent ( )
inline

Reset the current item to the first of the list, or NULL if HasCurrentNull is true.

Definition at line 53 of file Chain.hpp.

template<class T >
void ACCSCHAINEDLIST< T >::StartCurrent ( )
inline

Reset the current item to the first of the list.

Definition at line 55 of file Chain.hpp.

Member Data Documentation

template<class T >
bool ACCSCHAINEDLIST< T >::HasCurrentNull

If true, the current pointer is null when all items has been used.

Definition at line 41 of file Chain.hpp.

template<class T >
ACCSCHAINEDLISTITEM<T>* ACCSCHAINEDLIST< T >::pCurrentItem

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

Definition at line 39 of file Chain.hpp.

template<class T >
ACCSCHAINEDLISTITEM<T>* ACCSCHAINEDLIST< 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: