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

FIFO_LIST< T > Class Template Reference

This is a generic list type for a list that has both a head and a tail pointer (note the the LIST template only has a head pointer). More...

#include <fifo_list.h>

Inheritance diagram for FIFO_LIST< T >:

Inheritance graph
[legend]
Collaboration diagram for FIFO_LIST< T >:

Collaboration graph
[legend]
List of all members.

Public Types

typedef FIFO_LIST::LIST_TYPE list_type
typedef list_typehandle

Public Member Functions

 FIFO_LIST (void)
void dealloc (void)
 deallocate the list

void add (T data)
void reverse (void)
 reverse the list

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

handle remove (void)
 remove an element from the start of the list and return the first element of the remaining list

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

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

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


Private Attributes

list_typelist
list_typetail

Detailed Description

template<class T>
class FIFO_LIST< T >

This is a generic list type for a list that has both a head and a tail pointer (note the the LIST template only has a head 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. In contrast, the LIST template class adds items to the head and reads from the head (last in, first out). 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

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

This class does not have anything but the default destructor. In order to allow a function to allocate a list and then return the list as its result, the list is not deallocated by the destructor. The list can be deallocated by calling the "dealloc" class function.

Definition at line 45 of file fifo_list.h.


Member Typedef Documentation

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

Definition at line 58 of file fifo_list.h.

template<class T>
typedef struct FIFO_LIST::LIST_TYPE FIFO_LIST< T >::list_type
 


Constructor & Destructor Documentation

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

Definition at line 61 of file fifo_list.h.

00062   { 
00063     list = NULL;
00064     tail = NULL;
00065   }


Member Function Documentation

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

Definition at line 75 of file fifo_list.h.

00076   {
00077     list_type *t;
00078     
00079     t = new list_type;
00080     t->data = data;
00081     t->next = NULL;
00082     if (list == NULL) {
00083       list = t;
00084       tail = t;
00085     }
00086     else {
00087       tail->next = t;
00088       tail = t;
00089     }
00090   }  // add

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

deallocate the list

Definition at line 68 of file fifo_list.h.

00069   {
00070     while ( remove() != NULL )
00071       /* nada */;
00072   } // dealloc

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

get the first element from the list

Definition at line 152 of file fifo_list.h.

00153   {
00154     return list;
00155   } // first

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

given a handle, return the associated data item

Definition at line 144 of file fifo_list.h.

00145   {
00146 
00147     return h->data;
00148   } // get_item

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

return the lenght of the list

Definition at line 111 of file fifo_list.h.

00112   {
00113       list_type *elem;
00114       unsigned int cnt = 0;
00115 
00116       for (elem = list; elem != NULL; elem = elem->next)
00117           cnt++;
00118       return cnt;
00119   }  // lenght

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

iterator to get the next element

Definition at line 159 of file fifo_list.h.

Referenced by FIFO_LIST< pSym >::reverse().

00160   {
00161     list_type *next = NULL;
00162 
00163     if (h != NULL) {
00164         next = h->next;
00165     }
00166 
00167     return next;
00168   } // next

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

remove an element from the start of the list and return the first element of the remaining list

Definition at line 126 of file fifo_list.h.

Referenced by FIFO_LIST< pSym >::dealloc().

00127   {
00128     list_type *t;
00129 
00130     if (list != NULL) {
00131       t = list;
00132       list = t->next;
00133       delete t;
00134     }
00135 
00136     if (list == NULL)
00137         tail = NULL;
00138 
00139     return list;
00140   } // remove

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

reverse the list

Definition at line 94 of file fifo_list.h.

00095   {
00096     list_type *elem, *prev, *next;
00097 
00098     prev = NULL;
00099     next = NULL;
00100 
00101     tail = list;
00102     for (elem = list; elem != NULL; prev = elem, elem = next) {
00103       next = elem->next;
00104       elem->next = prev;
00105     } // for 
00106     list = prev;
00107   }  // reverse


Member Data Documentation

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

Definition at line 54 of file fifo_list.h.

Referenced by FIFO_LIST< pSym >::add(), FIFO_LIST< pSym >::FIFO_LIST(), FIFO_LIST< pSym >::first(), FIFO_LIST< pSym >::length(), FIFO_LIST< pSym >::remove(), and FIFO_LIST< pSym >::reverse().

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

Definition at line 55 of file fifo_list.h.

Referenced by FIFO_LIST< pSym >::add(), FIFO_LIST< pSym >::FIFO_LIST(), FIFO_LIST< pSym >::remove(), and FIFO_LIST< pSym >::reverse().


The documentation for this class was generated from the following file:
Generated on Wed Mar 31 21:16:06 2004 for Data Structures for a VHDL Compiler by doxygen 1.3.3