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

LIST Class Template Reference

template class LIST. More...

#include <list.h>

List of all members.

Public Types

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


Public Methods

 LIST (void)
 class constructor. More...

 LIST (const LIST< T > &rhs)
 The copy constructor copies the list pointer. More...

 ~LIST ()
 destructor does nothing. More...

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

void add (T data)
 Add an element to the 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 next (handle h)
 iterator to get the next element. More...


Private Attributes

list_typelist
 list head. More...


Detailed Description

template<class T> class LIST

template class LIST.

This is a generic list type. It 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

 
      LIST<char *> list;
      LIST<my_struct *> 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 59 of file list.h.


Member Typedef Documentation

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

define a handle type to abstract the list_type type.

Definition at line 88 of file list.h.


Constructor & Destructor Documentation

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

class constructor.

Definition at line 92 of file list.h.

00093   { 
00094     list = 0;
00095   }

template<class T>
LIST<T>::LIST<T> ( const LIST< T > & rhs ) [inline]
 

The copy constructor copies the list pointer.

Definition at line 99 of file list.h.

00100   {
00101     list = rhs.list;
00102   }

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

destructor does nothing.

Definition at line 105 of file list.h.

00105 {} 


Member Function Documentation

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

Add an element to the list.

Definition at line 117 of file list.h.

Referenced by invpacktree_int::new_level(), invpacktree::new_level(), invpacktree_int::reduce(), and invpacktree::reduce().

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

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

deallocate the list.

Definition at line 109 of file list.h.

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

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

get the first element from the list.

Definition at line 193 of file list.h.

Referenced by invpacktree_int::add_elem(), invpacktree::add_elem(), invpacktree::invpacktree(), invpacktree_int::invpacktree_int(), invpacktree_int::reduce(), and invpacktree::reduce().

00194   {
00195     return list;
00196   } // first

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

given a handle, return the associated data item.

Definition at line 185 of file list.h.

Referenced by invpacktree_int::add_elem(), invpacktree::add_elem(), invpacktree::invpacktree(), invpacktree_int::invpacktree_int(), invpacktree_int::reduce(), and invpacktree::reduce().

00186   {
00187 
00188     return h->data;
00189   } // get_item

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

return the lenght of the list.

Definition at line 150 of file list.h.

00151   {
00152       list_type *elem;
00153       unsigned int cnt = 0;
00154 
00155       for (elem = list; elem != 0; elem = elem->next)
00156           cnt++;
00157       return cnt;
00158   }  // lenght

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

iterator to get the next element.

Definition at line 200 of file list.h.

00201   {
00202     list_type *next = 0;
00203 
00204     if (h != 0) {
00205         next = h->next;
00206     }
00207 
00208     return next;
00209   } // next

template<class T>
handle 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 171 of file list.h.

Referenced by dealloc(), invpacktree::invpacktree(), invpacktree_int::invpacktree_int(), invpacktree_int::reduce(), and invpacktree::reduce().

00172   {
00173     list_type *t;
00174 
00175     if (list != 0) {
00176       t = list;
00177       list = t->next;
00178       // no delete t;
00179     }
00180     return list;
00181   } // remove

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

reverse the list.

Definition at line 135 of file list.h.

00136   {
00137     list_type *revlist = 0;
00138     list_type *next;
00139 
00140     for (list_type *t = list; t != 0; t = next) {
00141         next = t->next;
00142         t->next = revlist;
00143         revlist = t;
00144     }
00145     list = revlist;
00146   }  // reverse


Member Data Documentation

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

list head.

Definition at line 84 of file 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