Changeset 3237 for trunk/tools/common
- Timestamp:
- Mar 26, 2000, 12:17:47 AM (25 years ago)
- Location:
- trunk/tools/common
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/common/kList.cpp
r824 r3237 1 /* $Id: kList.cpp,v 1. 1 1999-09-05 02:09:17bird Exp $ */1 /* $Id: kList.cpp,v 1.2 2000-03-25 23:17:46 bird Exp $ */ 2 2 /* 3 3 * Simple list and sorted list template class. … … 151 151 return cEntries; 152 152 } 153 154 155 156 157 158 159 /** 160 * Constructor. 161 */ 162 template <class kEntry> 163 kList<kEntry>::kList() : pFirst(NULL), pLast(NULL), cEntries(0) 164 { 165 } 166 167 168 /** 169 * Destructor. 170 */ 171 template <class kEntry> 172 kList<kEntry>::~kList() 173 { 174 destroy(); 175 } 176 177 178 /** 179 * Removes all entries in the list. 180 */ 181 template <class kEntry> 182 void kList<kEntry>::destroy() 183 { 184 while (pFirst != NULL) 185 { 186 kEntry *p = pFirst; 187 pFirst = (kEntry*)pFirst->getNext(); 188 delete p; 189 #ifdef DEBUG 190 cEntries--; 191 #endif 192 } 193 #ifdef DEBUG 194 if (cEntries != 0) 195 fprintf(stderr, 196 "%s(%d, %s)internal processing warning - cEntires was incorrect upon list destruction.", 197 __FILE__, __LINE__, __FUNCTION__); 198 #endif 199 cEntries = 0; 200 pLast = NULL; 201 } 202 203 204 /** 205 * Inserts an entry into the end of the list. 206 * @param pEntry Pointer to entry to insert. 207 */ 208 template <class kEntry> 209 void kList<kEntry>::insert(kEntry *pEntry) 210 { 211 if (pEntry == NULL) 212 return; 213 214 if (pFirst == NULL) 215 { 216 pEntry->setNext(NULL); 217 pLast = pFirst = pEntry; 218 } 219 else 220 { 221 pEntry->setNext(NULL); 222 pLast->setNext(pEntry); 223 pLast = pEntry; 224 } 225 cEntries++; 226 } 227 228 229 /** 230 * Get first element from the list without removing it. 231 * @returns pointer to matching object. NULL if empty list. 232 * @remark 233 */ 234 template <class kEntry> 235 kEntry *kList<kEntry>::getFirst(void) const 236 { 237 return pFirst; 238 } 239 240 241 /** 242 * Get first element from the list without removing it. 243 * @returns pointer to matching object. NULL if empty list. 244 * @remark 245 */ 246 template <class kEntry> 247 kEntry *kList<kEntry>::getLast(void) const 248 { 249 return pLast; 250 } 251 252 253 /** 254 * Gets count of entries in the list. 255 * @returns Entry count. 256 */ 257 template <class kEntry> 258 unsigned long kList<kEntry>::getCount(void) const 259 { 260 return cEntries; 261 } 262 263 153 264 #endif -
trunk/tools/common/kList.h
r824 r3237 1 /* $Id: kList.h,v 1. 1 1999-09-05 02:09:17 bird Exp $ */1 /* $Id: kList.h,v 1.2 2000-03-25 23:17:47 bird Exp $ */ 2 2 /* 3 3 * Simple list and sorted list template class. … … 85 85 class kList 86 86 { 87 private: 88 kEntry *pFirst; 89 kEntry *pLast; 90 unsigned long cEntries; 87 91 92 public: 93 kList(void); 94 ~kList(void); 95 96 void destroy(void); 97 void insert(kEntry *pEntry); 98 kEntry * getFirst(void) const; 99 kEntry * getLast(void) const; 100 unsigned long getCount(void) const; 88 101 }; 89 102
Note:
See TracChangeset
for help on using the changeset viewer.