#include <DList.hpp>
Public Methods | |
DList () | |
virtual | ~DList () |
void | clear () |
void | insert (Elem item) |
void | append (Elem item) |
Elem | remove () |
void | setFirst () |
void | prev () |
void | next () |
ULONG | length () |
void | setPos (ULONG pos) |
void | setValue (Elem item) |
Elem | getValue () |
Elem | currValue () |
bool | isEmpty () const |
bool | isInList () const |
long | getPos () |
long | size () |
long | find (Elem val) |
long | findID (ULONG ID) |
void | display () |
void | enqueue (Elem item) |
Elem | dequeue () |
long | findTimeStamp (double stamp) |
Private Attributes | |
DLink * | head |
DLink * | tail |
DLink * | curr |
ULONG | pos |
ULONG | nbElements |
|
Definition at line 8 of file DList.cpp. 00009 : nbElements( 0 ), pos( 0 ) // No Element in the list yet ! 00010 { 00011 head = new DLink(); // Create an empty header Link 00012 // where prev and next are NULL 00013 curr = tail = head; // Share the same empty Link 00014 00015 assert( head != NULL ); 00016 assert( curr != NULL ); 00017 assert( tail != NULL ); 00018 } |
|
Definition at line 20 of file DList.cpp. 00020 { // Destructor 00021 while(head != NULL) { // Return Link nodes to free shared memory 00022 curr = head; // Set the current ptr to the head ptr. 00023 head = head->next; // The current head ptr now points to 00024 delete curr; // the next elem which become the new head, 00025 nbElements--; // so the current head ptr can be deleted. 00026 } 00027 } |
|
Definition at line 181 of file DList.cpp. Referenced by enqueue(), and insert().
|
|
Definition at line 29 of file DList.cpp. 00030 { 00031 while (head->next != NULL) // Return Link nodes to free memory 00032 { 00033 curr = head->next; // Current ptr points to next header element 00034 head->next = curr->next; // Next head elem is the next current element 00035 delete curr; // Delete the current element 00036 nbElements--; 00037 } 00038 curr = tail = head; // The head, tail and current is the samething 00039 pos = 0; 00040 } |
|
Definition at line 127 of file DList.cpp. 00128 { 00129 return getValue(); 00130 } |
|
|
|
Definition at line 247 of file DList.cpp. 00248 { 00249 if ( nbElements < 1 ) 00250 { 00251 printf( "Empty List\n" ); 00252 return; // Empty List 00253 } 00254 00255 DLink* temp = curr; 00256 00257 setFirst(); 00258 00259 printf( "\n===========================================\n" ); 00260 00261 while ( curr != NULL ) // Stop if we reach the end 00262 { 00263 printf( "%d) ", pos ); 00264 printf( "%d\t", curr->element ); 00265 printf( "%s\t", curr->element->pkt+4 ); 00266 printf( "[%u]\t", curr->element->pktLength ); 00267 00268 if ( curr->prev == NULL ) 00269 { 00270 printf( "NULL \t" ); 00271 } 00272 else 00273 { 00274 printf( "%d\t", curr->prev->element ); 00275 } 00276 00277 if ( curr->next == NULL ) 00278 { 00279 printf( "NULL \n" ); 00280 } 00281 else 00282 { 00283 printf( "%d\n", curr->next->element ); 00284 } 00285 00286 curr = curr->next; 00287 pos++; 00288 } 00289 00290 printf( "\n===========================================\n" ); 00291 fflush( stdout ); 00292 curr = temp; 00293 } |
|
Definition at line 197 of file DList.cpp. 00198 { 00199 append( item ); 00200 } |
|
Definition at line 295 of file DList.cpp. 00296 { 00297 if ( curr == NULL ) 00298 { 00299 curr = head; 00300 pos = 0; 00301 } 00302 00303 if ( nbElements < 1 ) 00304 { 00305 printf( "Can't search inside an empty list\n" ); 00306 return -50; 00307 } 00308 00309 if ( curr == head ) 00310 { 00311 curr = head->next; // We start at the next header element 00312 pos = 1; 00313 } 00314 00315 register ULONG i = 0; 00316 DLink* temp = curr; 00317 00318 for( ; curr != NULL; i++, pos++ ) // Stop if we reach the tail 00319 { 00320 if ( curr->element == ZERO ) // Valid data inside !? 00321 { 00322 exit( 1 ); 00323 printf( "Search process aborted, since current element's data are not defined.\n" ); 00324 curr = temp; 00325 return -100 - i; 00326 } 00327 00328 if ( curr->element == val ) 00329 { 00330 return pos; // Found it 00331 } 00332 else 00333 { 00334 curr = curr->next; 00335 } 00336 } 00337 00338 curr = temp; 00339 return -1; // Not found 00340 } |
|
Definition at line 344 of file DList.cpp. 00345 { 00346 if ( curr == NULL ) 00347 { 00348 curr = head; 00349 pos = 0; 00350 } 00351 00352 if ( nbElements < 1 ) 00353 { 00354 // printf( "Can't search inside an empty list\n" ); 00355 return -50; 00356 } 00357 00358 if ( curr == head ) 00359 { 00360 curr = head->next; // We start at the next header element 00361 pos = 1; 00362 } 00363 00364 register ULONG i = 0; 00365 DLink* temp = curr; 00366 00367 for( ; curr != NULL; i++, pos++ ) // Stop if we reach the tail 00368 { 00369 if ( curr->element == ZERO ) // Valid data inside !? 00370 { 00371 exit( 1 ); 00372 printf( "Search process aborted, since current element's data are not defined.\n" ); 00373 curr = temp; 00374 return -100 - i; 00375 } 00376 00377 if ( curr->element->getID() == ID ) 00378 { 00379 return pos; // Found it 00380 } 00381 else 00382 { 00383 curr = curr->next; 00384 } 00385 } 00386 00387 curr = temp; 00388 return -1; // Not found 00389 } |
|
Definition at line 392 of file DList.cpp. 00393 { 00394 if ( curr == NULL ) 00395 { 00396 setFirst(); 00397 } 00398 00399 00400 if ( nbElements < 1 ) 00401 { 00402 // printf( "Can't search inside an empty list\n" ); 00403 return -50; 00404 } 00405 00406 if ( curr == head ) 00407 { 00408 setFirst(); 00409 } 00410 00411 register ULONG i = 0; 00412 DLink* temp = curr; 00413 00414 for( ; curr != NULL; i++, pos++ ) // Stop if we reach the tail 00415 { 00416 if ( curr->element == ZERO ) // Valid data inside !? 00417 { 00418 exit( 1 ); 00419 printf( "Search process aborted, since current element's data are not defined.\n" ); 00420 curr = temp; 00421 return -100 - i; 00422 } 00423 00424 if ( curr->element->getTimeStamp() <= stamp ) 00425 { 00426 printf("Found at %d\n",pos); 00427 fflush(stdout); 00428 return pos; // Found it 00429 } 00430 else 00431 { 00432 curr = curr->next; 00433 } 00434 } 00435 00436 curr = temp; 00437 return -1; // Not found 00438 } |
|
Definition at line 242 of file DList.cpp. 00243 { 00244 return pos; 00245 } |
|
Definition at line 132 of file DList.cpp. Referenced by currValue().
|
|
Definition at line 152 of file DList.cpp. 00153 { 00154 if ( curr == NULL || curr->prev == NULL ) 00155 { 00156 curr = head; 00157 pos = 0; 00158 append( item ); 00159 return; 00160 } 00161 00162 // Create the new DLink(Elem Element, DLink* nextp, DLink* prevp) 00163 00164 curr->next = new DLink( item, curr->next, curr ); 00165 00166 if ( curr->next->next != NULL ) // New element is not the tail ? 00167 { 00168 curr->next->next->prev = curr->next; // Set the old curr->next DLink 00169 } // Backward ptr to the new DLink. 00170 00171 if ( tail == curr ) 00172 { 00173 tail = curr->next; 00174 } 00175 00176 curr = curr->next; // New element is now the current. 00177 nbElements++; 00178 } |
|
|
|
Definition at line 147 of file DList.cpp. 00148 { 00149 return ( curr != NULL ); 00150 } |
|
Definition at line 92 of file DList.cpp. 00093 { 00094 ULONG cnt = 0; 00095 for(DLink* temp = head->next; // Create a temp which next head ptr. 00096 temp != NULL; // Until tail i.e. NULL 00097 temp = temp->next ) // Move the the next Link ptr. 00098 { 00099 cnt++; // Count the number of elements available 00100 } 00101 00102 nbElements = cnt; 00103 return cnt; // which are not NULL. 00104 } |
|
|
|
|
|
Definition at line 211 of file DList.cpp. 00212 { 00213 assert( curr != NULL ); // Must be a valid position in the list 00214 if ( curr == head ) 00215 { 00216 curr = head->next; 00217 } 00218 00219 assert( nbElements > 0 ); // Is it the head ? 00220 00221 Elem temp = curr->element; // Save the removed element's data 00222 DLink* newCurr = curr->prev; // Save the new current position 00223 00224 curr->prev->next = curr->next; // Set prev elem forward ptr to next elem 00225 00226 if ( curr->next == NULL ) // Is it the tail ? 00227 { 00228 tail == curr->prev; // Previous element is now the tail 00229 } 00230 else 00231 { 00232 curr->next->prev = curr->prev; // Set next elem backward ptr to prev elem 00233 } 00234 00235 delete curr; // Delete the current removed Link 00236 curr = newCurr; // Moving backward, in case we are at the tail 00237 nbElements--; // We just erase an element, so substract it. 00238 pos--; 00239 return temp; // Send the old current data to user 00240 } |
|
Definition at line 42 of file DList.cpp. Referenced by display(), and findTimeStamp().
|
|
|
|
|
|
Definition at line 87 of file DList.cpp. 00088 { 00089 return nbElements; 00090 } |
|
|
|
|
|
|
|
|
|
|