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

LIST< T > Class Template Reference

This is a generic list type. More...

#include <list.h>

Inheritance diagram for LIST< T >:

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

Collaboration graph
[legend]
List of all members.

Public Types

typedef LIST::LIST_TYPE list_type
typedef list_typehandle

Public Member Functions

 LIST (void)
void dealloc (void)
 deallocate the list

void add (T data)
void reverse (void)
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

Detailed Description

template<class T>
class LIST< T >

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;

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 36 of file list.h.


Member Typedef Documentation

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

Definition at line 48 of file list.h.

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


Constructor & Destructor Documentation

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

Definition at line 51 of file list.h.

00052   { 
00053     list = 0;
00054   }


Member Function Documentation

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

Definition at line 65 of file list.h.

00066   {
00067     list_type *t;
00068     
00069     t = new list_type;
00070     t->data = data;
00071     t->next = 0;
00072     if (list == 0) {
00073       list = t;
00074     }
00075     else {
00076       t->next = list;
00077       list = t;
00078     }
00079   }  // add

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

deallocate the list

Definition at line 58 of file list.h.

00059   {
00060     while ( remove() != 0 )
00061       /* nada */;
00062   } // dealloc

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

get the first element from the list

Definition at line 136 of file list.h.

00137   {
00138     return list;
00139   } // first

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

given a handle, return the associated data item

Definition at line 128 of file list.h.

00129   {
00130 
00131     return h->data;
00132   } // get_item

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

return the lenght of the list

Definition at line 99 of file list.h.

00100   {
00101       list_type *elem;
00102       unsigned int cnt = 0;
00103 
00104       for (elem = list; elem != 0; elem = elem->next)
00105           cnt++;
00106       return cnt;
00107   }  // lenght

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

iterator to get the next element

Definition at line 143 of file list.h.

Referenced by LIST< type_time * >::reverse().

00144   {
00145     list_type *next = 0;
00146 
00147     if (h != 0) {
00148         next = h->next;
00149     }
00150 
00151     return next;
00152   } // next

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

Referenced by LIST< type_time * >::dealloc().

00115   {
00116     list_type *t;
00117 
00118     if (list != 0) {
00119       t = list;
00120       list = t->next;
00121       delete t;
00122     }
00123     return list;
00124   } // remove

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

Definition at line 83 of file list.h.

00084   {
00085     list_type *elem, *prev, *next;
00086 
00087     prev = 0;
00088     next = 0;
00089 
00090     for (elem = list; elem != 0; prev = elem, elem = next) {
00091       next = elem->next;
00092       elem->next = prev;
00093     } // for 
00094     list = prev;
00095   }  // reverse


Member Data Documentation

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

Definition at line 45 of file list.h.

Referenced by LIST< type_time * >::add(), symtable::dealloc_sub_tables(), LIST< type_time * >::first(), LIST< type_time * >::length(), LIST< type_time * >::LIST(), symtable::pr(), strtable::pr(), LIST< type_time * >::remove(), and LIST< type_time * >::reverse().


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