Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

FIFO_LIST Class Template Reference

template class FIFO_LIST. More...

#include <fifo_list.h>

Inheritance diagram for FIFO_LIST::

packdata_list queue List of all members.

Public Types

typedef list_typehandle
 define a handle type to abstract the list_type type. More...


Public Methods

 FIFO_LIST (void)
 class constructor. More...

 ~FIFO_LIST (void)
 default destructor does nothing. More...

void dealloc (void)
 deallocate the list. More...

void add (T data)
 add an element to the FIFO list. More...

void reverse (void)
 reverse the list. More...

unsigned int length (void)
 return the lenght of the list. More...

handle remove (void)
 remove. More...

get_item (handle h)
 given a handle, return the associated data item. More...

handle first (void)
 get the first element from the list. More...

handle last (void)
 return the last element in the list. More...

handle next (handle h)
 iterator to get the next element. More...


Private Attributes

list_typelist
 list head. More...

list_typetail
 list tail (items are added to the tail). More...


Detailed Description

template<class T> class FIFO_LIST

template class FIFO_LIST.

This is a generic list type for a list that has both a head and a tail pointer. In this list, items are added to the tail. When read from the front of the list, items will be read in a first-in, first-out order (FIFO). The template should be instantiated with a scalar type, like an integer or a pointer to a larger type (e.g., a string or a structure). For example

      FIFO_LIST<char *> list;
      FIFO_LIST<my_struct *> list;
      FIFO_LIST<my_class *> list;

The list "links" are allocated in a memory pool. This allocation is handled by the local version of new in list_type. The memory allocated for the list_type objects will be deallocated when the memory pool is freed.

Definition at line 64 of file fifo_list.h.


Member Typedef Documentation

template<class T>
typedef list_type * FIFO_LIST<T>::handle
 

define a handle type to abstract the list_type type.

Definition at line 95 of file fifo_list.h.


Constructor & Destructor Documentation

template<class T>
FIFO_LIST<T>::FIFO_LIST<T> ( void ) [inline]
 

class constructor.

Definition at line 99 of file fifo_list.h.

00100   { 
00101     list = 0;
00102     tail = 0;
00103   }

template<class T>
FIFO_LIST<T>::~FIFO_LIST<T> ( void ) [inline]
 

default destructor does nothing.

Definition at line 106 of file fifo_list.h.

00106 {}


Member Function Documentation

template<class T>
void FIFO_LIST<T>::add ( T data ) [inline]
 

add an element to the FIFO list.

Definition at line 118 of file fifo_list.h.

Referenced by queue::addQueue(), packtree_int::buildBestBasisList(), and packtree::buildBestBasisList().

00119   {
00120     list_type *t;
00121     
00122     t = new list_type();
00123     t->data = data;
00124     t->next = 0;
00125     if (list == 0) {
00126       list = t;
00127       tail = t;
00128     }
00129     else {
00130       tail->next = t;
00131       tail = t;
00132     }
00133   }  // add

template<class T>
void FIFO_LIST<T>::dealloc ( void ) [inline]
 

deallocate the list.

Definition at line 110 of file fifo_list.h.

00111   {
00112     while ( remove() != 0 )
00113       /* nada */;
00114   } // dealloc

template<class T>
handle FIFO_LIST<T>::first ( void ) [inline]
 

get the first element from the list.

Definition at line 201 of file fifo_list.h.

Referenced by calcPacketWidth(), queue::deleteStart(), invpacktree::invpacktree(), invpacktree_int::invpacktree_int(), packdata_list::pr(), queue::queueEmpty(), and queue::queueStart().

00202   {
00203     return list;
00204   } // first

template<class T>
T FIFO_LIST<T>::get_item ( handle h ) [inline]
 

given a handle, return the associated data item.

Definition at line 193 of file fifo_list.h.

Referenced by calcPacketWidth(), queue::deleteStart(), invpacktree::invpacktree(), invpacktree_int::invpacktree_int(), packdata_list::pr(), and queue::queueStart().

00194   {
00195 
00196     return h->data;
00197   } // get_item

template<class T>
handle FIFO_LIST<T>::last ( void ) [inline]
 

return the last element in the list.

Definition at line 208 of file fifo_list.h.

00209   {
00210     return tail;
00211   } // last

template<class T>
unsigned int FIFO_LIST<T>::length ( void ) [inline]
 

return the lenght of the list.

Definition at line 154 of file fifo_list.h.

00155   {
00156       list_type *elem;
00157       unsigned int cnt = 0;
00158 
00159       for (elem = list; elem != 0; elem = elem->next)
00160           cnt++;
00161       return cnt;
00162   }  // lenght

template<class T>
handle FIFO_LIST<T>::next ( handle h ) [inline]
 

iterator to get the next element.

Definition at line 215 of file fifo_list.h.

Referenced by calcPacketWidth(), invpacktree::invpacktree(), invpacktree_int::invpacktree_int(), and packdata_list::pr().

00216   {
00217     list_type *next = 0;
00218 
00219     if (h != 0) {
00220         next = h->next;
00221     }
00222 
00223     return next;
00224   } // next

template<class T>
handle FIFO_LIST<T>::remove ( void ) [inline]
 

remove.

Remove an element from the start of the list and return the first element of the remaining list.

This function relies on the fact that the list elements were allocated from a pool. The memory for these elements will be recovered when the pool is deallocated.

Definition at line 175 of file fifo_list.h.

Referenced by dealloc(), and queue::deleteStart().

00176   {
00177     list_type *t;
00178 
00179     if (list != 0) {
00180       t = list;
00181       list = t->next;
00182       // no delete t;
00183     }
00184 
00185     if (list == 0)
00186         tail = 0;
00187 
00188     return list;
00189   } // remove

template<class T>
void FIFO_LIST<T>::reverse ( void ) [inline]
 

reverse the list.

Definition at line 137 of file fifo_list.h.

00138   {
00139     list_type *elem, *prev, *next;
00140 
00141     prev = 0;
00142     next = 0;
00143 
00144     tail = list;
00145     for (elem = list; elem != 0; prev = elem, elem = next) {
00146       next = elem->next;
00147       elem->next = prev;
00148     } // for 
00149     list = prev;
00150   }  // reverse


Member Data Documentation

template<class T>
list_type * FIFO_LIST<T>::list [private]
 

list head.

Definition at line 89 of file fifo_list.h.

template<class T>
list_type * FIFO_LIST<T>::tail [private]
 

list tail (items are added to the tail).

Definition at line 91 of file fifo_list.h.


The documentation for this class was generated from the following file:
Generated at Tue May 27 21:56:17 2003 for Wavelet compression, determinism and time series forecasting by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001