Main Page   Packages   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Search  

DList Class Reference

#include <DList.hpp>

List of all members.

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

DLinkhead
DLinktail
DLinkcurr
ULONG pos
ULONG nbElements


Constructor & Destructor Documentation

DList::DList   [inline]
 

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 }

DList::~DList   [virtual]
 

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 }


Member Function Documentation

void DList::append Elem    item
 

Definition at line 181 of file DList.cpp.

Referenced by enqueue(), and insert().

00182 {
00183   if ( tail == NULL ) 
00184   {
00185     tail = curr = head;
00186   }
00187 
00188   // Create the new tail DLink(Elem Element, DLink* nextp, DLink* prevp)
00189   tail->next = new DLink( item, NULL, tail );
00190   tail = tail->next;     
00191   curr = tail;
00192 
00193   nbElements++;
00194   pos++;
00195 }

void DList::clear  
 

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 }

Elem DList::currValue   [inline]
 

Definition at line 127 of file DList.cpp.

00128 {
00129   return getValue();
00130 }

Elem DList::dequeue   [inline]
 

Definition at line 202 of file DList.cpp.

00203 {
00204   assert( head != NULL );
00205   curr = head->next;
00206   if ( curr == NULL ) return ZERO;
00207   return remove();
00208 }

void DList::display  
 

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 }

void DList::enqueue Elem    item [inline]
 

Definition at line 197 of file DList.cpp.

00198 {
00199   append( item );
00200 }

long DList::find Elem    val
 

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 }

long DList::findID ULONG    ID
 

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 }

long DList::findTimeStamp double    stamp
 

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 }

long DList::getPos   [inline]
 

Definition at line 242 of file DList.cpp.

00243 {
00244   return pos;
00245 }

Elem DList::getValue  
 

Definition at line 132 of file DList.cpp.

Referenced by currValue().

00133 { 
00134   if ( curr != NULL  &&  curr != head  &&  nbElements > 0 ) 
00135   {
00136     return curr->element;    // Return value of the current element
00137   }
00138 
00139   return ZERO;
00140 }

void DList::insert Elem    item
 

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 }

bool DList::isEmpty   const [inline]
 

Definition at line 142 of file DList.cpp.

00143 {
00144   return ( head->next == NULL );
00145 }

bool DList::isInList   const [inline]
 

Definition at line 147 of file DList.cpp.

00148 {
00149   return ( curr != NULL );
00150 }

ULONG DList::length  
 

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 }

void DList::next   [inline]
 

Definition at line 70 of file DList.cpp.

00071 {
00072   if ( curr != NULL )           // if current is known.
00073   {
00074     if ( curr->next == NULL )  
00075     {
00076       curr = tail;
00077       pos = nbElements;
00078     } 
00079     else 
00080     { 
00081       curr = curr->next;        // Current ptr is now the next position ptr
00082       pos = 0;
00083     }
00084   }
00085 }

void DList::prev   [inline]
 

Definition at line 56 of file DList.cpp.

00057 {
00058   if (curr != NULL) 
00059   {
00060     curr = curr->prev;          // Current ptr is now the previous position ptr
00061     pos--;
00062   } 
00063   else 
00064   {
00065     curr = head;
00066     pos  = 0;
00067   }
00068 }

Elem DList::remove  
 

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 }

void DList::setFirst   [inline]
 

Definition at line 42 of file DList.cpp.

Referenced by display(), and findTimeStamp().

00043 {
00044   if ( head->next != NULL )  
00045   {
00046     curr = head;
00047     pos = 1;
00048   } 
00049   else 
00050   { 
00051     curr = head;
00052     pos = 0;
00053   }
00054 }

void DList::setPos ULONG    pos
 

Definition at line 106 of file DList.cpp.

00107 {
00108   curr = head;                          // The header is position 0
00109   pos = 0;                                    
00110   for( register ULONG i = 0;
00111        (curr != NULL) && (i < pos);     // Move to position 1, 2, ... , pos.
00112        i++ )  
00113   {
00114     curr = curr->next;
00115     pos++;
00116   }
00117 }

void DList::setValue Elem    val
 

Definition at line 119 of file DList.cpp.

00120 {
00121   if ( curr != NULL  &&  curr != head  &&  nbElements > 0 )  
00122   {
00123     curr->element = val;
00124   }
00125 }

long DList::size   [inline]
 

Definition at line 87 of file DList.cpp.

00088 {
00089   return nbElements;
00090 }


Member Data Documentation

DLink* DList::curr [private]
 

Definition at line 47 of file DList.hpp.

DLink* DList::head [private]
 

Definition at line 45 of file DList.hpp.

ULONG DList::nbElements [private]
 

Definition at line 50 of file DList.hpp.

ULONG DList::pos [private]
 

Definition at line 49 of file DList.hpp.

DLink* DList::tail [private]
 

Definition at line 46 of file DList.hpp.


The documentation for this class was generated from the following files:
Generated on Sun Oct 14 18:48:33 2001 for Standard J2K Library by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001