CLIST_ITERATOR Class Reference

#include <clst.h>

List of all members.


Detailed Description

Generic iterator class for singly linked lists with embedded links.

Definition at line 179 of file clst.h.

Public Member Functions

Private Member Functions

Private Attributes

Friends


Constructor & Destructor Documentation

CLIST_ITERATOR::CLIST_ITERATOR (  )  [inline]

Definition at line 200 of file clst.h.

References NULL.

00200                      {  //constructor
00201       list = NULL;
00202     }                            //unassigned list

CLIST_ITERATOR::CLIST_ITERATOR ( CLIST list_to_iterate  )  [inline]

CONSTRUCTOR - set iterator to specified list;.

Definition at line 310 of file clst.h.

References set_to_list().

00310                                                             {
00311   set_to_list(list_to_iterate);
00312 }


Member Function Documentation

void CLIST_ITERATOR::add_after_stay_put ( void *  new_data  )  [inline]

Add a new element to the list after the current element but do not move the iterator to the new element.

Definition at line 366 of file clst.h.

References ABORT, current, CLIST_LINK::data, CLIST::empty(), ex_current_was_last, FALSE, CLIST::last, list, next, CLIST_LINK::next, NULL, and prev.

00367                                                                {
00368   CLIST_LINK *new_element;
00369 
00370   #ifdef _DEBUG
00371   if (!this)
00372     NULL_OBJECT.error ("CLIST_ITERATOR::add_after_stay_put", ABORT, NULL);
00373   if (!list)
00374     NO_LIST.error ("CLIST_ITERATOR::add_after_stay_put", ABORT, NULL);
00375   if (!new_data)
00376     BAD_PARAMETER.error ("CLIST_ITERATOR::add_after_stay_put", ABORT,
00377       "new_data is NULL");
00378   #endif
00379 
00380   new_element = new CLIST_LINK;
00381   new_element->data = new_data;
00382 
00383   if (list->empty ()) {
00384     new_element->next = new_element;
00385     list->last = new_element;
00386     prev = next = new_element;
00387     ex_current_was_last = FALSE;
00388     current = NULL;
00389   }
00390   else {
00391     new_element->next = next;
00392 
00393     if (current) {               //not extracted
00394       current->next = new_element;
00395       if (prev == current)
00396         prev = new_element;
00397       if (current == list->last)
00398         list->last = new_element;
00399     }
00400     else {                       //current extracted
00401       prev->next = new_element;
00402       if (ex_current_was_last) {
00403         list->last = new_element;
00404         ex_current_was_last = FALSE;
00405       }
00406     }
00407     next = new_element;
00408   }
00409 }

void CLIST_ITERATOR::add_after_then_move ( void *  new_data  )  [inline]

Add a new element to the list after the current element and move the iterator to the new element.

Definition at line 319 of file clst.h.

References ABORT, current, cycle_pt, CLIST_LINK::data, CLIST::empty(), ex_current_was_cycle_pt, ex_current_was_last, CLIST::last, list, next, CLIST_LINK::next, NULL, and prev.

Referenced by CLIST::internal_deep_copy().

00320                                                                 {
00321   CLIST_LINK *new_element;
00322 
00323   #ifdef _DEBUG
00324   if (!this)
00325     NULL_OBJECT.error ("CLIST_ITERATOR::add_after_then_move", ABORT, NULL);
00326   if (!list)
00327     NO_LIST.error ("CLIST_ITERATOR::add_after_then_move", ABORT, NULL);
00328   if (!new_data)
00329     BAD_PARAMETER.error ("CLIST_ITERATOR::add_after_then_move", ABORT,
00330       "new_data is NULL");
00331   #endif
00332 
00333   new_element = new CLIST_LINK;
00334   new_element->data = new_data;
00335 
00336   if (list->empty ()) {
00337     new_element->next = new_element;
00338     list->last = new_element;
00339     prev = next = new_element;
00340   }
00341   else {
00342     new_element->next = next;
00343 
00344     if (current) {               //not extracted
00345       current->next = new_element;
00346       prev = current;
00347       if (current == list->last)
00348         list->last = new_element;
00349     }
00350     else {                       //current extracted
00351       prev->next = new_element;
00352       if (ex_current_was_last)
00353         list->last = new_element;
00354       if (ex_current_was_cycle_pt)
00355         cycle_pt = new_element;
00356     }
00357   }
00358   current = new_element;
00359 }

void CLIST_ITERATOR::add_before_stay_put ( void *  new_data  )  [inline]

Add a new element to the list before the current element but dont move the iterator to the new element.

Definition at line 460 of file clst.h.

References ABORT, current, CLIST_LINK::data, CLIST::empty(), ex_current_was_last, CLIST::last, list, next, CLIST_LINK::next, NULL, prev, and TRUE.

00461                                                                 {
00462   CLIST_LINK *new_element;
00463 
00464   #ifdef _DEBUG
00465   if (!this)
00466     NULL_OBJECT.error ("CLIST_ITERATOR::add_before_stay_put", ABORT, NULL);
00467   if (!list)
00468     NO_LIST.error ("CLIST_ITERATOR::add_before_stay_put", ABORT, NULL);
00469   if (!new_data)
00470     BAD_PARAMETER.error ("CLIST_ITERATOR::add_before_stay_put", ABORT,
00471       "new_data is NULL");
00472   #endif
00473 
00474   new_element = new CLIST_LINK;
00475   new_element->data = new_data;
00476 
00477   if (list->empty ()) {
00478     new_element->next = new_element;
00479     list->last = new_element;
00480     prev = next = new_element;
00481     ex_current_was_last = TRUE;
00482     current = NULL;
00483   }
00484   else {
00485     prev->next = new_element;
00486     if (current) {               //not extracted
00487       new_element->next = current;
00488       if (next == current)
00489         next = new_element;
00490     }
00491     else {                       //current extracted
00492       new_element->next = next;
00493       if (ex_current_was_last)
00494         list->last = new_element;
00495     }
00496     prev = new_element;
00497   }
00498 }

void CLIST_ITERATOR::add_before_then_move ( void *  new_data  )  [inline]

Add a new element to the list before the current element and move the iterator to the new element.

Definition at line 416 of file clst.h.

References ABORT, current, cycle_pt, CLIST_LINK::data, CLIST::empty(), ex_current_was_cycle_pt, ex_current_was_last, CLIST::last, list, next, CLIST_LINK::next, NULL, and prev.

00417                                                                  {
00418   CLIST_LINK *new_element;
00419 
00420   #ifdef _DEBUG
00421   if (!this)
00422     NULL_OBJECT.error ("CLIST_ITERATOR::add_before_then_move", ABORT, NULL);
00423   if (!list)
00424     NO_LIST.error ("CLIST_ITERATOR::add_before_then_move", ABORT, NULL);
00425   if (!new_data)
00426     BAD_PARAMETER.error ("CLIST_ITERATOR::add_before_then_move", ABORT,
00427       "new_data is NULL");
00428   #endif
00429 
00430   new_element = new CLIST_LINK;
00431   new_element->data = new_data;
00432 
00433   if (list->empty ()) {
00434     new_element->next = new_element;
00435     list->last = new_element;
00436     prev = next = new_element;
00437   }
00438   else {
00439     prev->next = new_element;
00440     if (current) {               //not extracted
00441       new_element->next = current;
00442       next = current;
00443     }
00444     else {                       //current extracted
00445       new_element->next = next;
00446       if (ex_current_was_last)
00447         list->last = new_element;
00448       if (ex_current_was_cycle_pt)
00449         cycle_pt = new_element;
00450     }
00451   }
00452   current = new_element;
00453 }

void CLIST_ITERATOR::add_list_after ( CLIST list_to_add  )  [inline]

Insert another list to this list after the current element but dont move the iterator.

Definition at line 505 of file clst.h.

References ABORT, current, CLIST::empty(), ex_current_was_last, FALSE, CLIST::First(), CLIST::last, list, CLIST_LINK::next, next, NULL, prev, and TRUE.

00505                                                              {
00506   #ifdef _DEBUG
00507   if (!this)
00508     NULL_OBJECT.error ("CLIST_ITERATOR::add_list_after", ABORT, NULL);
00509   if (!list)
00510     NO_LIST.error ("CLIST_ITERATOR::add_list_after", ABORT, NULL);
00511   if (!list_to_add)
00512     BAD_PARAMETER.error ("CLIST_ITERATOR::add_list_after", ABORT,
00513       "list_to_add is NULL");
00514   #endif
00515 
00516   if (!list_to_add->empty ()) {
00517     if (list->empty ()) {
00518       list->last = list_to_add->last;
00519       prev = list->last;
00520       next = list->First ();
00521       ex_current_was_last = TRUE;
00522       current = NULL;
00523     }
00524     else {
00525       if (current) {             //not extracted
00526         current->next = list_to_add->First ();
00527         if (current == list->last)
00528           list->last = list_to_add->last;
00529         list_to_add->last->next = next;
00530         next = current->next;
00531       }
00532       else {                     //current extracted
00533         prev->next = list_to_add->First ();
00534         if (ex_current_was_last) {
00535           list->last = list_to_add->last;
00536           ex_current_was_last = FALSE;
00537         }
00538         list_to_add->last->next = next;
00539         next = prev->next;
00540       }
00541     }
00542     list_to_add->last = NULL;
00543   }
00544 }

void CLIST_ITERATOR::add_list_before ( CLIST list_to_add  )  [inline]

Insert another list to this list before the current element.

Move the iterator to the start of the inserted elements iterator.

Definition at line 552 of file clst.h.

References ABORT, current, cycle_pt, CLIST::empty(), ex_current_was_cycle_pt, ex_current_was_last, FALSE, CLIST::First(), CLIST::last, list, CLIST_LINK::next, next, NULL, and prev.

00552                                                               {
00553   #ifdef _DEBUG
00554   if (!this)
00555     NULL_OBJECT.error ("CLIST_ITERATOR::add_list_before", ABORT, NULL);
00556   if (!list)
00557     NO_LIST.error ("CLIST_ITERATOR::add_list_before", ABORT, NULL);
00558   if (!list_to_add)
00559     BAD_PARAMETER.error ("CLIST_ITERATOR::add_list_before", ABORT,
00560       "list_to_add is NULL");
00561   #endif
00562 
00563   if (!list_to_add->empty ()) {
00564     if (list->empty ()) {
00565       list->last = list_to_add->last;
00566       prev = list->last;
00567       current = list->First ();
00568       next = current->next;
00569       ex_current_was_last = FALSE;
00570     }
00571     else {
00572       prev->next = list_to_add->First ();
00573       if (current) {             //not extracted
00574         list_to_add->last->next = current;
00575       }
00576       else {                     //current extracted
00577         list_to_add->last->next = next;
00578         if (ex_current_was_last)
00579           list->last = list_to_add->last;
00580         if (ex_current_was_cycle_pt)
00581           cycle_pt = prev->next;
00582       }
00583       current = prev->next;
00584       next = current->next;
00585     }
00586     list_to_add->last = NULL;
00587   }
00588 }

void CLIST_ITERATOR::add_to_end ( void *  new_data  )  [inline]

Add a new element to the end of the list without moving the iterator.

This is provided because a single linked list cannot move to the last as the iterator couldn't set its prev pointer. Adding to the end is essential for implementing queues.

Definition at line 775 of file clst.h.

References ABORT, CLIST_LINK::data, CLIST::last, list, CLIST_LINK::next, NULL, and prev.

Referenced by CLIST::internal_de_dump(), and CLIST::sort().

00776                                                        {
00777   CLIST_LINK *new_element;
00778 
00779   #ifdef _DEBUG
00780   if (!this)
00781     NULL_OBJECT.error ("CLIST_ITERATOR::add_to_end", ABORT, NULL);
00782   if (!list)
00783     NO_LIST.error ("CLIST_ITERATOR::add_to_end", ABORT, NULL);
00784   if (!new_data)
00785     BAD_PARAMETER.error ("CLIST_ITERATOR::add_to_end", ABORT,
00786       "new_data is NULL");
00787   #endif
00788 
00789   if (this->at_last ()) {
00790     this->add_after_stay_put (new_data);
00791   }
00792   else {
00793     if (this->at_first ()) {
00794       this->add_before_stay_put (new_data);
00795       list->last = prev;
00796     }
00797     else {                       //Iteratr is elsewhere
00798       new_element = new CLIST_LINK;
00799       new_element->data = new_data;
00800 
00801       new_element->next = list->last->next;
00802       list->last->next = new_element;
00803       list->last = new_element;
00804     }
00805   }
00806 }

BOOL8 CLIST_ITERATOR::at_first (  )  [inline]

Are we at the start of the list?

Definition at line 685 of file clst.h.

References ABORT, current, CLIST::empty(), ex_current_was_last, CLIST::First(), CLIST::last, list, NULL, and prev.

00685                                       {
00686   #ifdef _DEBUG
00687   if (!this)
00688     NULL_OBJECT.error ("CLIST_ITERATOR::at_first", ABORT, NULL);
00689   if (!list)
00690     NO_LIST.error ("CLIST_ITERATOR::at_first", ABORT, NULL);
00691   #endif
00692 
00693                                  //we're at a deleted
00694   return ((list->empty ()) || (current == list->First ()) || ((current == NULL) &&
00695     (prev == list->last) &&      //NON-last pt between
00696     !ex_current_was_last));      //first and last
00697 }

BOOL8 CLIST_ITERATOR::at_last (  )  [inline]

Are we at the end of the list?

Definition at line 703 of file clst.h.

References ABORT, current, CLIST::empty(), ex_current_was_last, CLIST::last, list, NULL, and prev.

Referenced by extract_sublist().

00703                                      {
00704   #ifdef _DEBUG
00705   if (!this)
00706     NULL_OBJECT.error ("CLIST_ITERATOR::at_last", ABORT, NULL);
00707   if (!list)
00708     NO_LIST.error ("CLIST_ITERATOR::at_last", ABORT, NULL);
00709   #endif
00710 
00711                                  //we're at a deleted
00712   return ((list->empty ()) || (current == list->last) || ((current == NULL) &&
00713     (prev == list->last) &&      //last point between
00714     ex_current_was_last));       //first and last
00715 }

BOOL8 CLIST_ITERATOR::current_extracted (  )  [inline]

Definition at line 259 of file clst.h.

00259                               {  //current extracted?
00260       return !current;
00261     }

BOOL8 CLIST_ITERATOR::cycled_list (  )  [inline]

Have we returned to the cycle_pt since it was set?

Definition at line 721 of file clst.h.

References ABORT, current, cycle_pt, CLIST::empty(), list, NULL, and started_cycling.

Referenced by extract_sublist(), CLIST::internal_deep_copy(), CLIST::internal_dump(), CLIST::length(), CLIST::prep_serialise(), and CLIST::sort().

00721                                          {
00722   #ifdef _DEBUG
00723   if (!this)
00724     NULL_OBJECT.error ("CLIST_ITERATOR::cycled_list", ABORT, NULL);
00725   if (!list)
00726     NO_LIST.error ("CLIST_ITERATOR::cycled_list", ABORT, NULL);
00727   #endif
00728 
00729   return ((list->empty ()) || ((current == cycle_pt) && started_cycling));
00730 
00731 }

void* CLIST_ITERATOR::data (  )  [inline]

Definition at line 228 of file clst.h.

References ABORT, and NULL.

Referenced by CLIST::internal_deep_copy(), and CLIST::internal_dump().

00228                  {  //get current data
00229     #ifdef _DEBUG
00230       if (!list)
00231         NO_LIST.error ("CLIST_ITERATOR::data", ABORT, NULL);
00232       if (!current)
00233         NULL_DATA.error ("CLIST_ITERATOR::data", ABORT, NULL);
00234     #endif
00235       return current->data;
00236     }

void * CLIST_ITERATOR::data_relative ( INT8  offset  ) 

Return the data pointer to the element "offset" elements from current.

"offset" must not be less than -1.

Note:
This function can't be INLINEd because it contains a loop

Definition at line 337 of file clst.cpp.

References ABORT, current, CLIST_LINK::data, CLIST::empty(), list, CLIST_LINK::next, NULL, and prev.

00338                                                  {  //offset from current
00339   CLIST_LINK *ptr;
00340 
00341   #ifdef _DEBUG
00342   if (!this)
00343     NULL_OBJECT.error ("CLIST_ITERATOR::data_relative", ABORT, NULL);
00344   if (!list)
00345     NO_LIST.error ("CLIST_ITERATOR::data_relative", ABORT, NULL);
00346   if (list->empty ())
00347     EMPTY_LIST.error ("CLIST_ITERATOR::data_relative", ABORT, NULL);
00348   if (offset < -1)
00349     BAD_PARAMETER.error ("CLIST_ITERATOR::data_relative", ABORT,
00350       "offset < -l");
00351   #endif
00352 
00353   if (offset == -1)
00354     ptr = prev;
00355   else
00356     for (ptr = current ? current : prev; offset-- > 0; ptr = ptr->next);
00357 
00358   #ifdef _DEBUG
00359   if (!ptr)
00360     NULL_DATA.error ("CLIST_ITERATOR::data_relative", ABORT, NULL);
00361   #endif
00362 
00363   return ptr->data;
00364 }

BOOL8 CLIST_ITERATOR::empty (  )  [inline]

Definition at line 251 of file clst.h.

References ABORT, and NULL.

00251                   {  //is list empty?
00252     #ifdef _DEBUG
00253       if (!list)
00254         NO_LIST.error ("CLIST_ITERATOR::empty", ABORT, NULL);
00255     #endif
00256       return list->empty ();
00257     }

void CLIST_ITERATOR::exchange ( CLIST_ITERATOR other_it  ) 

Exchange two list elements.

Given another iterator, whose current element is a different element on the same list list OR an element of another list, exchange the two current elements.

On return, each iterator points to the element which was the other iterators current on entry. This function hasn't been in-lined because its a bit big!

Definition at line 402 of file clst.cpp.

References ABORT, current, cycle_pt, CLIST::empty(), ERRCODE::error(), CLIST::last, list, CLIST_LINK::next, next, NULL, and prev.

00403                                                         {  //other iterator
00404   const ERRCODE DONT_EXCHANGE_DELETED =
00405     "Can't exchange deleted elements of lists";
00406 
00407   CLIST_LINK *old_current;
00408 
00409   #ifdef _DEBUG
00410   if (!this)
00411     NULL_OBJECT.error ("CLIST_ITERATOR::exchange", ABORT, NULL);
00412   if (!list)
00413     NO_LIST.error ("CLIST_ITERATOR::exchange", ABORT, NULL);
00414   if (!other_it)
00415     BAD_PARAMETER.error ("CLIST_ITERATOR::exchange", ABORT, "other_it NULL");
00416   if (!(other_it->list))
00417     NO_LIST.error ("CLIST_ITERATOR::exchange", ABORT, "other_it");
00418   #endif
00419 
00420   /* Do nothing if either list is empty or if both iterators
00421   reference the same link */
00422   if ((list->empty ()) ||
00423     (other_it->list->empty ()) || (current == other_it->current))
00424     return;
00425 
00426   /* Error if either current element is deleted */
00427 
00428   if (!current || !other_it->current)
00429     DONT_EXCHANGE_DELETED.error ("CLIST_ITERATOR.exchange", ABORT, NULL);
00430 
00431   /* Now handle the 4 cases:
00432    doubleton list;
00433    non-doubleton adjacent elements (other before this);
00434    non-doubleton adjacent elements (this before other);
00435     non-adjacent elements.
00436    */
00437 
00438                                  //adjacent links
00439   if ((next == other_it->current) ||
00440   (other_it->next == current)) {
00441                                  //doubleton list
00442     if ((next == other_it->current) &&
00443     (other_it->next == current)) {
00444       prev = next = current;
00445       other_it->prev = other_it->next = other_it->current;
00446     }
00447     else {                       //non-doubleton with
00448                                  //adjacent links
00449                                  //other before this
00450       if (other_it->next == current) {
00451         other_it->prev->next = current;
00452         other_it->current->next = next;
00453         current->next = other_it->current;
00454         other_it->next = other_it->current;
00455         prev = current;
00456       }
00457       else {                     //this before other
00458         prev->next = other_it->current;
00459         current->next = other_it->next;
00460         other_it->current->next = current;
00461         next = current;
00462         other_it->prev = other_it->current;
00463       }
00464     }
00465   }
00466   else {                         //no overlap
00467     prev->next = other_it->current;
00468     current->next = other_it->next;
00469     other_it->prev->next = current;
00470     other_it->current->next = next;
00471   }
00472 
00473   /* update end of list pointer when necessary (remember that
00474   the 2 iterators may iterate over different lists!) */
00475 
00476   if (list->last == current)
00477     list->last = other_it->current;
00478   if (other_it->list->last == other_it->current)
00479     other_it->list->last = current;
00480 
00481   if (current == cycle_pt)
00482     cycle_pt = other_it->cycle_pt;
00483   if (other_it->current == other_it->cycle_pt)
00484     other_it->cycle_pt = cycle_pt;
00485 
00486   /* The actual exchange - in all cases*/
00487 
00488   old_current = current;
00489   current = other_it->current;
00490   other_it->current = old_current;
00491 }

void * CLIST_ITERATOR::extract (  )  [inline]

Extract.

Do extraction by removing current from the list, deleting the cons cell and returning the data to the caller, but NOT updating the iterator. (So that any calling loop can do this.) The iterator's current points to NULL. If the data is to be deleted, this is the callers responsibility.

Definition at line 599 of file clst.h.

References ABORT, current, cycle_pt, ex_current_was_cycle_pt, ex_current_was_last, FALSE, CLIST::last, list, CLIST_LINK::next, next, NULL, prev, CLIST::singleton(), and TRUE.

Referenced by CLIST::sort().

00599                                      {
00600   void *extracted_data;
00601 
00602   #ifdef _DEBUG
00603   if (!this)
00604     NULL_OBJECT.error ("CLIST_ITERATOR::extract", ABORT, NULL);
00605   if (!list)
00606     NO_LIST.error ("CLIST_ITERATOR::extract", ABORT, NULL);
00607   if (!current)                  //list empty or
00608                                  //element extracted
00609     NULL_CURRENT.error ("CLIST_ITERATOR::extract",
00610       ABORT, NULL);
00611   #endif
00612 
00613   if (list->singleton ())        //special case where
00614                                  //we do need to
00615     prev = next = list->last = NULL;
00616   //      change the iterator
00617   else {
00618     prev->next = next;           //remove from list
00619 
00620     if (current == list->last) {
00621       list->last = prev;
00622       ex_current_was_last = TRUE;
00623     }
00624     else
00625       ex_current_was_last = FALSE;
00626 
00627     ex_current_was_cycle_pt = (current == cycle_pt) ? TRUE : FALSE;
00628 
00629   }
00630   extracted_data = current->data;
00631   delete(current);  //destroy CONS cell
00632   current = NULL;
00633   return extracted_data;
00634 }

CLIST_LINK * CLIST_ITERATOR::extract_sublist ( CLIST_ITERATOR other_it  )  [private]

Extract sublist.

This is a private member, used only by CLIST::assign_to_sublist.

Given another iterator for the same list, extract the links from THIS to OTHER inclusive, link them into a new circular list, and return a pointer to the last element.

Can't inline this function because it contains a loop

Definition at line 505 of file clst.cpp.

References ABORT, at_last(), current, cycle_pt, cycled_list(), CLIST::empty(), ERRCODE::error(), ex_current_was_cycle_pt, ex_current_was_last, FALSE, forward(), CLIST::last, list, mark_cycle_pt(), next, CLIST_LINK::next, NULL, prev, and TRUE.

Referenced by CLIST::assign_to_sublist().

00506                                     {  //to other current
00507   CLIST_ITERATOR temp_it = *this;
00508   CLIST_LINK *end_of_new_list;
00509 
00510   const ERRCODE BAD_SUBLIST = "Can't find sublist end point in original list";
00511   #ifdef _DEBUG
00512   const ERRCODE BAD_EXTRACTION_PTS =
00513     "Can't extract sublist from points on different lists";
00514   const ERRCODE DONT_EXTRACT_DELETED =
00515     "Can't extract a sublist marked by deleted points";
00516 
00517   if (!this)
00518     NULL_OBJECT.error ("CLIST_ITERATOR::extract_sublist", ABORT, NULL);
00519   if (!other_it)
00520     BAD_PARAMETER.error ("CLIST_ITERATOR::extract_sublist", ABORT,
00521       "other_it NULL");
00522   if (!list)
00523     NO_LIST.error ("CLIST_ITERATOR::extract_sublist", ABORT, NULL);
00524   if (list != other_it->list)
00525     BAD_EXTRACTION_PTS.error ("CLIST_ITERATOR.extract_sublist", ABORT, NULL);
00526   if (list->empty ())
00527     EMPTY_LIST.error ("CLIST_ITERATOR::extract_sublist", ABORT, NULL);
00528 
00529   if (!current || !other_it->current)
00530     DONT_EXTRACT_DELETED.error ("CLIST_ITERATOR.extract_sublist", ABORT,
00531       NULL);
00532   #endif
00533 
00534   ex_current_was_last = other_it->ex_current_was_last = FALSE;
00535   ex_current_was_cycle_pt = FALSE;
00536   other_it->ex_current_was_cycle_pt = FALSE;
00537 
00538   temp_it.mark_cycle_pt ();
00539   do {                           //walk sublist
00540     if (temp_it.cycled_list ())  //cant find end pt
00541       BAD_SUBLIST.error ("CLIST_ITERATOR.extract_sublist", ABORT, NULL);
00542 
00543     if (temp_it.at_last ()) {
00544       list->last = prev;
00545       ex_current_was_last = other_it->ex_current_was_last = TRUE;
00546     }
00547 
00548     if (temp_it.current == cycle_pt)
00549       ex_current_was_cycle_pt = TRUE;
00550 
00551     if (temp_it.current == other_it->cycle_pt)
00552       other_it->ex_current_was_cycle_pt = TRUE;
00553 
00554     temp_it.forward ();
00555   }
00556   while (temp_it.prev != other_it->current);
00557 
00558                                  //circularise sublist
00559   other_it->current->next = current;
00560   end_of_new_list = other_it->current;
00561 
00562                                  //sublist = whole list
00563   if (prev == other_it->current) {
00564     list->last = NULL;
00565     prev = current = next = NULL;
00566     other_it->prev = other_it->current = other_it->next = NULL;
00567   }
00568   else {
00569     prev->next = other_it->next;
00570     current = other_it->current = NULL;
00571     next = other_it->next;
00572     other_it->prev = prev;
00573   }
00574   return end_of_new_list;
00575 }

void * CLIST_ITERATOR::forward (  ) 

Move the iterator to the next element of the list.

REMEMBER: ALL LISTS ARE CIRCULAR.

Definition at line 297 of file clst.cpp.

References ABORT, current, cycle_pt, CLIST_LINK::data, CLIST::empty(), ex_current_was_cycle_pt, list, CLIST_LINK::next, next, NULL, prev, started_cycling, and TRUE.

Referenced by extract_sublist(), CLIST::internal_deep_copy(), CLIST::internal_dump(), CLIST::length(), move_to_last(), CLIST::prep_serialise(), and CLIST::sort().

00297                               {
00298   #ifdef _DEBUG
00299   if (!this)
00300     NULL_OBJECT.error ("CLIST_ITERATOR::forward", ABORT, NULL);
00301   if (!list)
00302     NO_LIST.error ("CLIST_ITERATOR::forward", ABORT, NULL);
00303   #endif
00304   if (list->empty ())
00305     return NULL;
00306 
00307   if (current) {                 //not removed so
00308                                  //set previous
00309     prev = current;
00310     started_cycling = TRUE;
00311   }
00312   else {
00313     if (ex_current_was_cycle_pt)
00314       cycle_pt = next;
00315   }
00316   current = next;
00317   next = current->next;
00318 
00319   #ifdef _DEBUG
00320   if (!current)
00321     NULL_DATA.error ("CLIST_ITERATOR::forward", ABORT, NULL);
00322   if (!next)
00323     NULL_NEXT.error ("CLIST_ITERATOR::forward", ABORT,
00324       "This is: %i  Current is: %i",
00325       (int) this, (int) current);
00326   #endif
00327   return current->data;
00328 }

INT32 CLIST_ITERATOR::length (  )  [inline]

Return the length of the list.

Definition at line 737 of file clst.h.

References ABORT, CLIST::length(), list, and NULL.

00737                                     {
00738   #ifdef _DEBUG
00739   if (!this)
00740     NULL_OBJECT.error ("CLIST_ITERATOR::length", ABORT, NULL);
00741   if (!list)
00742     NO_LIST.error ("CLIST_ITERATOR::length", ABORT, NULL);
00743   #endif
00744 
00745   return list->length ();
00746 }

void CLIST_ITERATOR::mark_cycle_pt (  )  [inline]

Mark cycle pointer.

Remember the current location so that we can tell whether we've returned to this point later. If the current point is deleted either now, or in the future, the cycle point will be set to the next item which is set to current.

This could be by a forward, add_after_then_move or add_after_then_move.

Definition at line 666 of file clst.h.

References ABORT, current, cycle_pt, ex_current_was_cycle_pt, FALSE, list, NULL, started_cycling, and TRUE.

Referenced by extract_sublist(), CLIST::internal_deep_copy(), CLIST::internal_dump(), CLIST::length(), CLIST::prep_serialise(), and CLIST::sort().

00666                                           {
00667   #ifdef _DEBUG
00668   if (!this)
00669     NULL_OBJECT.error ("CLIST_ITERATOR::mark_cycle_pt", ABORT, NULL);
00670   if (!list)
00671     NO_LIST.error ("CLIST_ITERATOR::mark_cycle_pt", ABORT, NULL);
00672   #endif
00673 
00674   if (current)
00675     cycle_pt = current;
00676   else
00677     ex_current_was_cycle_pt = TRUE;
00678   started_cycling = FALSE;
00679 }

void * CLIST_ITERATOR::move_to_first (  )  [inline]

Move current so that it is set to the start of the list.

Return data just in case anyone wants it.

Definition at line 642 of file clst.h.

References ABORT, current, CLIST_LINK::data, CLIST::First(), CLIST::last, list, CLIST_LINK::next, next, NULL, and prev.

Referenced by sort().

00642                                            {
00643   #ifdef _DEBUG
00644   if (!this)
00645     NULL_OBJECT.error ("CLIST_ITERATOR::move_to_first", ABORT, NULL);
00646   if (!list)
00647     NO_LIST.error ("CLIST_ITERATOR::move_to_first", ABORT, NULL);
00648   #endif
00649 
00650   current = list->First ();
00651   prev = list->last;
00652   next = current != NULL ? current->next : NULL;
00653   return current->data;
00654 }

void * CLIST_ITERATOR::move_to_last (  ) 

Move current so that it is set to the end of the list.

Return data just in case anyone wants it. This function can't be INLINEd because it contains a loop

Definition at line 373 of file clst.cpp.

References ABORT, current, CLIST_LINK::data, forward(), CLIST::last, list, and NULL.

00373                                    {
00374   #ifdef _DEBUG
00375   if (!this)
00376     NULL_OBJECT.error ("CLIST_ITERATOR::move_to_last", ABORT, NULL);
00377   if (!list)
00378     NO_LIST.error ("CLIST_ITERATOR::move_to_last", ABORT, NULL);
00379   #endif
00380 
00381   while (current != list->last)
00382     forward();
00383 
00384   if (current == NULL)
00385     return NULL;
00386   else
00387     return current->data;
00388 }

void CLIST_ITERATOR::set_to_list ( CLIST list_to_iterate  )  [inline]

Reinitialise the iterator to point to the start of the list_to_iterate over.

Definition at line 286 of file clst.h.

References ABORT, current, cycle_pt, ex_current_was_cycle_pt, ex_current_was_last, FALSE, CLIST::First(), CLIST::last, list, CLIST_LINK::next, next, NULL, prev, and started_cycling.

Referenced by CLIST_ITERATOR(), and CLIST::internal_de_dump().

00287                                                                 {
00288   #ifdef _DEBUG
00289   if (!this)
00290     NULL_OBJECT.error ("CLIST_ITERATOR::set_to_list", ABORT, NULL);
00291   if (!list_to_iterate)
00292     BAD_PARAMETER.error ("CLIST_ITERATOR::set_to_list", ABORT,
00293       "list_to_iterate is NULL");
00294   #endif
00295 
00296   list = list_to_iterate;
00297   prev = list->last;
00298   current = list->First ();
00299   next = current != NULL ? current->next : NULL;
00300   cycle_pt = NULL;               //await explicit set
00301   started_cycling = FALSE;
00302   ex_current_was_last = FALSE;
00303   ex_current_was_cycle_pt = FALSE;
00304 }

void CLIST_ITERATOR::sort ( int   comparator(const void *, const void *)  )  [inline]

Sort the elements of the list, then reposition at the start.

Definition at line 753 of file clst.h.

References ABORT, list, move_to_first(), NULL, and CLIST::sort().

00755                              {
00756   #ifdef _DEBUG
00757   if (!this)
00758     NULL_OBJECT.error ("CLIST_ITERATOR::sort", ABORT, NULL);
00759   if (!list)
00760     NO_LIST.error ("CLIST_ITERATOR::sort", ABORT, NULL);
00761   #endif
00762 
00763   list->sort (comparator);
00764   move_to_first();
00765 }


Friends And Related Function Documentation

void CLIST::assign_to_sublist ( CLIST_ITERATOR ,
CLIST_ITERATOR  
) [friend]


Member Data Documentation

CLIST_LINK* CLIST_ITERATOR::current [private]

Definition at line 185 of file clst.h.

Referenced by add_after_stay_put(), add_after_then_move(), add_before_stay_put(), add_before_then_move(), add_list_after(), add_list_before(), at_first(), at_last(), cycled_list(), data_relative(), exchange(), extract(), extract_sublist(), forward(), mark_cycle_pt(), move_to_first(), move_to_last(), and set_to_list().

CLIST_LINK* CLIST_ITERATOR::cycle_pt [private]

Definition at line 191 of file clst.h.

Referenced by add_after_then_move(), add_before_then_move(), add_list_before(), cycled_list(), exchange(), extract(), extract_sublist(), forward(), mark_cycle_pt(), and set_to_list().

BOOL8 CLIST_ITERATOR::ex_current_was_cycle_pt [private]

Definition at line 189 of file clst.h.

Referenced by add_after_then_move(), add_before_then_move(), add_list_before(), extract(), extract_sublist(), forward(), mark_cycle_pt(), and set_to_list().

BOOL8 CLIST_ITERATOR::ex_current_was_last [private]

Definition at line 187 of file clst.h.

Referenced by add_after_stay_put(), add_after_then_move(), add_before_stay_put(), add_before_then_move(), add_list_after(), add_list_before(), at_first(), at_last(), extract(), extract_sublist(), and set_to_list().

CLIST* CLIST_ITERATOR::list [private]

Definition at line 183 of file clst.h.

Referenced by add_after_stay_put(), add_after_then_move(), add_before_stay_put(), add_before_then_move(), add_list_after(), add_list_before(), add_to_end(), at_first(), at_last(), cycled_list(), data_relative(), exchange(), extract(), extract_sublist(), forward(), length(), mark_cycle_pt(), move_to_first(), move_to_last(), set_to_list(), and sort().

CLIST_LINK* CLIST_ITERATOR::next [private]

Definition at line 186 of file clst.h.

Referenced by add_after_stay_put(), add_after_then_move(), add_before_stay_put(), add_before_then_move(), add_list_after(), add_list_before(), exchange(), extract(), extract_sublist(), forward(), move_to_first(), and set_to_list().

CLIST_LINK* CLIST_ITERATOR::prev [private]

Definition at line 184 of file clst.h.

Referenced by add_after_stay_put(), add_after_then_move(), add_before_stay_put(), add_before_then_move(), add_list_after(), add_list_before(), add_to_end(), at_first(), at_last(), data_relative(), exchange(), extract(), extract_sublist(), forward(), move_to_first(), and set_to_list().

BOOL8 CLIST_ITERATOR::started_cycling [private]

Definition at line 193 of file clst.h.

Referenced by cycled_list(), forward(), mark_cycle_pt(), and set_to_list().


The documentation for this class was generated from the following files:
Generated on Wed Feb 28 19:49:30 2007 for Tesseract by  doxygen 1.5.1