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

fifo_list.h

Go to the documentation of this file.
00001 
00002 #ifndef FIFO_LIST_H
00003 #define FIFO_LIST_H
00004 
00036 
00037 #include "blockpool.h"
00038 
00062 
00063 template <class T>
00064 class FIFO_LIST
00065 {
00066 public:
00070     class list_type {
00071     public:
00073         T data;
00075         list_type *next;
00078         void *operator new(size_t num_bytes)
00079         {
00080           block_pool mem_pool;
00081 
00082           void *mem_addr = mem_pool.pool_alloc( num_bytes );
00083           return mem_addr;        
00084         } // new
00085     };  // class list_type
00086 
00087 private:
00089   list_type *list;
00091   list_type *tail;
00092 
00093 public:
00095   typedef list_type *handle;
00096 
00097 public:
00099   FIFO_LIST(void) 
00100   { 
00101     list = 0;
00102     tail = 0;
00103   }
00104 
00106   ~FIFO_LIST(void) {}
00107 
00108 
00110   void dealloc(void)
00111   {
00112     while ( remove() != 0 )
00113       /* nada */;
00114   } // dealloc
00115 
00116 
00118   void add( T data )
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
00134 
00135 
00137   void reverse(void)
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
00151 
00152 
00154   unsigned int length(void)
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
00163 
00175   handle remove(void)
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
00190 
00191 
00193   T get_item( handle h)
00194   {
00195 
00196     return h->data;
00197   } // get_item
00198 
00199 
00201   handle first(void)
00202   {
00203     return list;
00204   } // first
00205 
00206 
00208   handle last(void)
00209   {
00210     return tail;
00211   } // last
00212 
00213 
00215   handle next(handle h)  
00216   {
00217     list_type *next = 0;
00218 
00219     if (h != 0) {
00220         next = h->next;
00221     }
00222 
00223     return next;
00224   } // next
00225   
00226 };  // template class FIFO_LIST
00227 
00228 
00229 #endif
00230 

Generated at Tue May 27 21:56:16 2003 for Wavelet compression, determinism and time series forecasting by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001