#include <list.h>
Public Types | |
| typedef list_type* | handle | 
| 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... | |
| T | 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_type* | list | 
| list head. More... | |
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.
      
  | 
  |||
| 
 define a handle type to abstract the list_type type. 
  | 
  
      
  | 
  ||||
| 
 class constructor. 
 Definition at line 92 of file list.h. 00093   { 
00094     list = 0;
00095   }
 | 
  
      
  | 
  ||||
| 
 The copy constructor copies the list pointer. 
 Definition at line 99 of file list.h. 00100   {
00101     list = rhs.list;
00102   }
 | 
  
      
  | 
  ||||
| 
 destructor does nothing. 
 Definition at line 105 of file list.h. 00105 {} 
 | 
  
      
  | 
  ||||
| 
 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
 | 
  
      
  | 
  ||||
| 
 deallocate the list. 
 Definition at line 109 of file list.h. 00110   {
00111     while ( remove() != 0 )
00112       /* nada */;
00113   } // dealloc
 | 
  
      
  | 
  ||||
| 
 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
 | 
  
      
  | 
  ||||
| 
 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
 | 
  
      
  | 
  ||||
| 
 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
 | 
  
      
  | 
  ||||
| 
 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
 | 
  
      
  | 
  ||||
| 
 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
 | 
  
      
  | 
  ||||
| 
 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
 | 
  
      
  | 
  |||
| 
 list head. 
  | 
  
1.2.8.1 written by Dimitri van Heesch,
 © 1997-2001