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

list.h

Go to the documentation of this file.
00001 
00002 #ifndef _LIST_H_
00003 #define _LIST_H_
00004 
00005 
00037 
00038 
00057 
00058 template <class T>
00059 class LIST
00060 {
00061 public:
00065     class list_type {
00066     public:
00068         T data;
00070         list_type *next;
00073         void *operator new(size_t num_bytes)
00074         {
00075           block_pool mem_pool;
00076 
00077           void *mem_addr = mem_pool.pool_alloc( num_bytes );
00078           return mem_addr;        
00079         } // new
00080     };  // class list_type
00081 
00082 private:
00084   list_type *list;
00085 
00086 public:  
00088   typedef list_type *handle;
00089 
00090 public:
00092   LIST(void) 
00093   { 
00094     list = 0;
00095   }
00096 
00097 
00099   LIST( const LIST<T> &rhs )
00100   {
00101     list = rhs.list;
00102   }
00103 
00105   ~LIST() {} 
00106 
00107 
00109   void dealloc(void)
00110   {
00111     while ( remove() != 0 )
00112       /* nada */;
00113   } // dealloc
00114 
00115 
00117   void add( T data )
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
00132 
00133 
00135   void reverse(void)
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
00147 
00148 
00150   unsigned int length(void)
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
00159 
00171   handle remove(void)
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
00182 
00183 
00185   T get_item( handle h)
00186   {
00187 
00188     return h->data;
00189   } // get_item
00190 
00191 
00193   handle first(void)
00194   {
00195     return list;
00196   } // first
00197 
00198 
00200   handle next(handle h)  
00201   {
00202     list_type *next = 0;
00203 
00204     if (h != 0) {
00205         next = h->next;
00206     }
00207 
00208     return next;
00209   } // next
00210   
00211 };  // template class LIST
00212 
00213 
00214 #endif
00215 

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