00001 00002 #ifndef FIFO_LIST_H 00003 #define FIFO_LIST_H 00004 00005 #ifndef NULL 00006 #define NULL 0 00007 #endif 00008 00009 /*===============================<o>===================================== 00010 00011 Copyright 1996, 1997, 2004 Ian Kaplan, Bear Products International, 00012 www.bearcave.com. 00013 00014 All Rights Reserved 00015 00016 You may use this software in software components for which you do 00017 not collect money (e.g., non-commercial software). All commercial 00018 use is reserved. 00019 00020 ===============================<o>=====================================*/ 00021 00022 00044 template <class T> 00045 class FIFO_LIST 00046 { 00047 public: 00048 typedef struct LIST_TYPE { 00049 T data; 00050 struct LIST_TYPE *next; 00051 } list_type; // struct list_type 00052 00053 private: 00054 list_type *list; 00055 list_type *tail; 00056 00057 public: 00058 typedef list_type *handle; 00059 00060 public: 00061 FIFO_LIST(void) 00062 { 00063 list = NULL; 00064 tail = NULL; 00065 } 00066 00068 void dealloc(void) 00069 { 00070 while ( remove() != NULL ) 00071 /* nada */; 00072 } // dealloc 00073 00074 00075 void add( T data ) 00076 { 00077 list_type *t; 00078 00079 t = new list_type; 00080 t->data = data; 00081 t->next = NULL; 00082 if (list == NULL) { 00083 list = t; 00084 tail = t; 00085 } 00086 else { 00087 tail->next = t; 00088 tail = t; 00089 } 00090 } // add 00091 00092 00094 void reverse(void) 00095 { 00096 list_type *elem, *prev, *next; 00097 00098 prev = NULL; 00099 next = NULL; 00100 00101 tail = list; 00102 for (elem = list; elem != NULL; prev = elem, elem = next) { 00103 next = elem->next; 00104 elem->next = prev; 00105 } // for 00106 list = prev; 00107 } // reverse 00108 00109 00111 unsigned int length(void) 00112 { 00113 list_type *elem; 00114 unsigned int cnt = 0; 00115 00116 for (elem = list; elem != NULL; elem = elem->next) 00117 cnt++; 00118 return cnt; 00119 } // lenght 00120 00126 handle remove(void) 00127 { 00128 list_type *t; 00129 00130 if (list != NULL) { 00131 t = list; 00132 list = t->next; 00133 delete t; 00134 } 00135 00136 if (list == NULL) 00137 tail = NULL; 00138 00139 return list; 00140 } // remove 00141 00142 00144 T get_item( handle h) 00145 { 00146 00147 return h->data; 00148 } // get_item 00149 00150 00152 handle first(void) 00153 { 00154 return list; 00155 } // first 00156 00157 00159 handle next(handle h) 00160 { 00161 list_type *next = NULL; 00162 00163 if (h != NULL) { 00164 next = h->next; 00165 } 00166 00167 return next; 00168 } // next 00169 00170 }; // template class LIST 00171 00172 00173 #endif 00174