#include <fifo_list.h>
Inheritance diagram for FIFO_LIST::
Public Types | |
typedef list_type* | handle |
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... | |
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 | last (void) |
return the last element in the list. More... | |
handle | next (handle h) |
iterator to get the next element. More... | |
Private Attributes | |
list_type* | list |
list head. More... | |
list_type* | tail |
list tail (items are added to the tail). More... |
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.
|
define a handle type to abstract the list_type type.
Definition at line 95 of file fifo_list.h. |
|
class constructor.
Definition at line 99 of file fifo_list.h. 00100 { 00101 list = 0; 00102 tail = 0; 00103 } |
|
default destructor does nothing.
Definition at line 106 of file fifo_list.h. 00106 {} |
|
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 |
|
deallocate the list.
Definition at line 110 of file fifo_list.h. 00111 { 00112 while ( remove() != 0 ) 00113 /* nada */; 00114 } // dealloc |
|
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 |
|
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 |
|
return the last element in the list.
Definition at line 208 of file fifo_list.h. 00209 { 00210 return tail; 00211 } // last |
|
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 |
|
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 |
|
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 |
|
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 |
|
list head.
Definition at line 89 of file fifo_list.h. |
|
list tail (items are added to the tail).
Definition at line 91 of file fifo_list.h. |