All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ELIST2_ITERATOR Class Reference

#include <elst2.h>

Public Member Functions

 ELIST2_ITERATOR ()
 
 ELIST2_ITERATOR (ELIST2 *list_to_iterate)
 
void set_to_list (ELIST2 *list_to_iterate)
 
void add_after_then_move (ELIST2_LINK *new_link)
 
void add_after_stay_put (ELIST2_LINK *new_link)
 
void add_before_then_move (ELIST2_LINK *new_link)
 
void add_before_stay_put (ELIST2_LINK *new_link)
 
void add_list_after (ELIST2 *list_to_add)
 
void add_list_before (ELIST2 *list_to_add)
 
ELIST2_LINKdata ()
 
ELIST2_LINKdata_relative (inT8 offset)
 
ELIST2_LINKforward ()
 
ELIST2_LINKbackward ()
 
ELIST2_LINKextract ()
 
ELIST2_LINKmove_to_first ()
 
ELIST2_LINKmove_to_last ()
 
void mark_cycle_pt ()
 
BOOL8 empty ()
 
BOOL8 current_extracted ()
 
BOOL8 at_first ()
 
BOOL8 at_last ()
 
BOOL8 cycled_list ()
 
void add_to_end (ELIST2_LINK *new_link)
 
void exchange (ELIST2_ITERATOR *other_it)
 
inT32 length ()
 
void sort (int comparator(const void *, const void *))
 

Friends

void ELIST2::assign_to_sublist (ELIST2_ITERATOR *, ELIST2_ITERATOR *)
 

Detailed Description

Definition at line 150 of file elst2.h.

Constructor & Destructor Documentation

ELIST2_ITERATOR::ELIST2_ITERATOR ( )
inline

Definition at line 171 of file elst2.h.

171  { //constructor
172  list = NULL;
173  } //unassigned list
#define NULL
Definition: host.h:144
ELIST2_ITERATOR::ELIST2_ITERATOR ( ELIST2 list_to_iterate)
inline

Definition at line 291 of file elst2.h.

291  {
292  set_to_list(list_to_iterate);
293 }
void set_to_list(ELIST2 *list_to_iterate)
Definition: elst2.h:264

Member Function Documentation

void ELIST2_ITERATOR::add_after_stay_put ( ELIST2_LINK new_link)
inline

Definition at line 354 of file elst2.h.

355  {
356  #ifndef NDEBUG
357  if (!this)
358  NULL_OBJECT.error ("ELIST2_ITERATOR::add_after_stay_put", ABORT, NULL);
359  if (!list)
360  NO_LIST.error ("ELIST2_ITERATOR::add_after_stay_put", ABORT, NULL);
361  if (!new_element)
362  BAD_PARAMETER.error ("ELIST2_ITERATOR::add_after_stay_put", ABORT,
363  "new_element is NULL");
364  if (new_element->next)
365  STILL_LINKED.error ("ELIST2_ITERATOR::add_after_stay_put", ABORT, NULL);
366  #endif
367 
368  if (list->empty ()) {
369  new_element->next = new_element;
370  new_element->prev = new_element;
371  list->last = new_element;
372  prev = next = new_element;
373  ex_current_was_last = FALSE;
374  current = NULL;
375  }
376  else {
377  new_element->next = next;
378  next->prev = new_element;
379 
380  if (current) { //not extracted
381  new_element->prev = current;
382  current->next = new_element;
383  if (prev == current)
384  prev = new_element;
385  if (current == list->last)
386  list->last = new_element;
387  }
388  else { //current extracted
389  new_element->prev = prev;
390  prev->next = new_element;
391  if (ex_current_was_last) {
392  list->last = new_element;
393  ex_current_was_last = FALSE;
394  }
395  }
396  next = new_element;
397  }
398 }
bool empty() const
Definition: elst2.h:107
Definition: errcode.h:30
const ERRCODE BAD_PARAMETER
Definition: lsterr.h:39
const ERRCODE NO_LIST
Definition: lsterr.h:32
void error(const char *caller, TessErrorLogCode action, const char *format,...) const
Definition: errcode.cpp:40
#define FALSE
Definition: capi.h:29
const ERRCODE STILL_LINKED
Definition: lsterr.h:40
#define NULL
Definition: host.h:144
const ERRCODE NULL_OBJECT
Definition: lsterr.h:33
void ELIST2_ITERATOR::add_after_then_move ( ELIST2_LINK new_link)
inline

Definition at line 303 of file elst2.h.

304  {
305  #ifndef NDEBUG
306  if (!this)
307  NULL_OBJECT.error ("ELIST2_ITERATOR::add_after_then_move", ABORT, NULL);
308  if (!list)
309  NO_LIST.error ("ELIST2_ITERATOR::add_after_then_move", ABORT, NULL);
310  if (!new_element)
311  BAD_PARAMETER.error ("ELIST2_ITERATOR::add_after_then_move", ABORT,
312  "new_element is NULL");
313  if (new_element->next)
314  STILL_LINKED.error ("ELIST2_ITERATOR::add_after_then_move", ABORT, NULL);
315  #endif
316 
317  if (list->empty ()) {
318  new_element->next = new_element;
319  new_element->prev = new_element;
320  list->last = new_element;
321  prev = next = new_element;
322  }
323  else {
324  new_element->next = next;
325  next->prev = new_element;
326 
327  if (current) { //not extracted
328  new_element->prev = current;
329  current->next = new_element;
330  prev = current;
331  if (current == list->last)
332  list->last = new_element;
333  }
334  else { //current extracted
335  new_element->prev = prev;
336  prev->next = new_element;
337  if (ex_current_was_last)
338  list->last = new_element;
339  if (ex_current_was_cycle_pt)
340  cycle_pt = new_element;
341  }
342  }
343  current = new_element;
344 }
bool empty() const
Definition: elst2.h:107
Definition: errcode.h:30
const ERRCODE BAD_PARAMETER
Definition: lsterr.h:39
const ERRCODE NO_LIST
Definition: lsterr.h:32
void error(const char *caller, TessErrorLogCode action, const char *format,...) const
Definition: errcode.cpp:40
const ERRCODE STILL_LINKED
Definition: lsterr.h:40
#define NULL
Definition: host.h:144
const ERRCODE NULL_OBJECT
Definition: lsterr.h:33
void ELIST2_ITERATOR::add_before_stay_put ( ELIST2_LINK new_link)
inline

Definition at line 457 of file elst2.h.

458  {
459  #ifndef NDEBUG
460  if (!this)
461  NULL_OBJECT.error ("ELIST2_ITERATOR::add_before_stay_put", ABORT, NULL);
462  if (!list)
463  NO_LIST.error ("ELIST2_ITERATOR::add_before_stay_put", ABORT, NULL);
464  if (!new_element)
465  BAD_PARAMETER.error ("ELIST2_ITERATOR::add_before_stay_put", ABORT,
466  "new_element is NULL");
467  if (new_element->next)
468  STILL_LINKED.error ("ELIST2_ITERATOR::add_before_stay_put", ABORT, NULL);
469  #endif
470 
471  if (list->empty ()) {
472  new_element->next = new_element;
473  new_element->prev = new_element;
474  list->last = new_element;
475  prev = next = new_element;
476  ex_current_was_last = TRUE;
477  current = NULL;
478  }
479  else {
480  prev->next = new_element;
481  new_element->prev = prev;
482 
483  if (current) { //not extracted
484  new_element->next = current;
485  current->prev = new_element;
486  if (next == current)
487  next = new_element;
488  }
489  else { //current extracted
490  new_element->next = next;
491  next->prev = new_element;
492  if (ex_current_was_last)
493  list->last = new_element;
494  }
495  prev = new_element;
496  }
497 }
bool empty() const
Definition: elst2.h:107
Definition: errcode.h:30
const ERRCODE BAD_PARAMETER
Definition: lsterr.h:39
const ERRCODE NO_LIST
Definition: lsterr.h:32
void error(const char *caller, TessErrorLogCode action, const char *format,...) const
Definition: errcode.cpp:40
#define TRUE
Definition: capi.h:28
const ERRCODE STILL_LINKED
Definition: lsterr.h:40
#define NULL
Definition: host.h:144
const ERRCODE NULL_OBJECT
Definition: lsterr.h:33
void ELIST2_ITERATOR::add_before_then_move ( ELIST2_LINK new_link)
inline

Definition at line 408 of file elst2.h.

409  {
410  #ifndef NDEBUG
411  if (!this)
412  NULL_OBJECT.error ("ELIST2_ITERATOR::add_before_then_move", ABORT, NULL);
413  if (!list)
414  NO_LIST.error ("ELIST2_ITERATOR::add_before_then_move", ABORT, NULL);
415  if (!new_element)
416  BAD_PARAMETER.error ("ELIST2_ITERATOR::add_before_then_move", ABORT,
417  "new_element is NULL");
418  if (new_element->next)
419  STILL_LINKED.error ("ELIST2_ITERATOR::add_before_then_move", ABORT, NULL);
420  #endif
421 
422  if (list->empty ()) {
423  new_element->next = new_element;
424  new_element->prev = new_element;
425  list->last = new_element;
426  prev = next = new_element;
427  }
428  else {
429  prev->next = new_element;
430  new_element->prev = prev;
431 
432  if (current) { //not extracted
433  new_element->next = current;
434  current->prev = new_element;
435  next = current;
436  }
437  else { //current extracted
438  new_element->next = next;
439  next->prev = new_element;
440  if (ex_current_was_last)
441  list->last = new_element;
442  if (ex_current_was_cycle_pt)
443  cycle_pt = new_element;
444  }
445  }
446  current = new_element;
447 }
bool empty() const
Definition: elst2.h:107
Definition: errcode.h:30
const ERRCODE BAD_PARAMETER
Definition: lsterr.h:39
const ERRCODE NO_LIST
Definition: lsterr.h:32
void error(const char *caller, TessErrorLogCode action, const char *format,...) const
Definition: errcode.cpp:40
const ERRCODE STILL_LINKED
Definition: lsterr.h:40
#define NULL
Definition: host.h:144
const ERRCODE NULL_OBJECT
Definition: lsterr.h:33
void ELIST2_ITERATOR::add_list_after ( ELIST2 list_to_add)
inline

Definition at line 507 of file elst2.h.

507  {
508  #ifndef NDEBUG
509  if (!this)
510  NULL_OBJECT.error ("ELIST2_ITERATOR::add_list_after", ABORT, NULL);
511  if (!list)
512  NO_LIST.error ("ELIST2_ITERATOR::add_list_after", ABORT, NULL);
513  if (!list_to_add)
514  BAD_PARAMETER.error ("ELIST2_ITERATOR::add_list_after", ABORT,
515  "list_to_add is NULL");
516  #endif
517 
518  if (!list_to_add->empty ()) {
519  if (list->empty ()) {
520  list->last = list_to_add->last;
521  prev = list->last;
522  next = list->First ();
523  ex_current_was_last = TRUE;
524  current = NULL;
525  }
526  else {
527  if (current) { //not extracted
528  current->next = list_to_add->First ();
529  current->next->prev = current;
530  if (current == list->last)
531  list->last = list_to_add->last;
532  list_to_add->last->next = next;
533  next->prev = list_to_add->last;
534  next = current->next;
535  }
536  else { //current extracted
537  prev->next = list_to_add->First ();
538  prev->next->prev = prev;
539  if (ex_current_was_last) {
540  list->last = list_to_add->last;
541  ex_current_was_last = FALSE;
542  }
543  list_to_add->last->next = next;
544  next->prev = list_to_add->last;
545  next = prev->next;
546  }
547  }
548  list_to_add->last = NULL;
549  }
550 }
bool empty() const
Definition: elst2.h:107
Definition: errcode.h:30
const ERRCODE BAD_PARAMETER
Definition: lsterr.h:39
const ERRCODE NO_LIST
Definition: lsterr.h:32
void error(const char *caller, TessErrorLogCode action, const char *format,...) const
Definition: errcode.cpp:40
#define FALSE
Definition: capi.h:29
#define TRUE
Definition: capi.h:28
#define NULL
Definition: host.h:144
const ERRCODE NULL_OBJECT
Definition: lsterr.h:33
void ELIST2_ITERATOR::add_list_before ( ELIST2 list_to_add)
inline

Definition at line 561 of file elst2.h.

561  {
562  #ifndef NDEBUG
563  if (!this)
564  NULL_OBJECT.error ("ELIST2_ITERATOR::add_list_before", ABORT, NULL);
565  if (!list)
566  NO_LIST.error ("ELIST2_ITERATOR::add_list_before", ABORT, NULL);
567  if (!list_to_add)
568  BAD_PARAMETER.error ("ELIST2_ITERATOR::add_list_before", ABORT,
569  "list_to_add is NULL");
570  #endif
571 
572  if (!list_to_add->empty ()) {
573  if (list->empty ()) {
574  list->last = list_to_add->last;
575  prev = list->last;
576  current = list->First ();
577  next = current->next;
578  ex_current_was_last = FALSE;
579  }
580  else {
581  prev->next = list_to_add->First ();
582  prev->next->prev = prev;
583 
584  if (current) { //not extracted
585  list_to_add->last->next = current;
586  current->prev = list_to_add->last;
587  }
588  else { //current extracted
589  list_to_add->last->next = next;
590  next->prev = list_to_add->last;
591  if (ex_current_was_last)
592  list->last = list_to_add->last;
593  if (ex_current_was_cycle_pt)
594  cycle_pt = prev->next;
595  }
596  current = prev->next;
597  next = current->next;
598  }
599  list_to_add->last = NULL;
600  }
601 }
bool empty() const
Definition: elst2.h:107
Definition: errcode.h:30
const ERRCODE BAD_PARAMETER
Definition: lsterr.h:39
const ERRCODE NO_LIST
Definition: lsterr.h:32
void error(const char *caller, TessErrorLogCode action, const char *format,...) const
Definition: errcode.cpp:40
#define FALSE
Definition: capi.h:29
#define NULL
Definition: host.h:144
const ERRCODE NULL_OBJECT
Definition: lsterr.h:33
void ELIST2_ITERATOR::add_to_end ( ELIST2_LINK new_link)
inline

Definition at line 838 of file elst2.h.

839  {
840  #ifndef NDEBUG
841  if (!this)
842  NULL_OBJECT.error ("ELIST2_ITERATOR::add_to_end", ABORT, NULL);
843  if (!list)
844  NO_LIST.error ("ELIST2_ITERATOR::add_to_end", ABORT, NULL);
845  if (!new_element)
846  BAD_PARAMETER.error ("ELIST2_ITERATOR::add_to_end", ABORT,
847  "new_element is NULL");
848  if (new_element->next)
849  STILL_LINKED.error ("ELIST2_ITERATOR::add_to_end", ABORT, NULL);
850  #endif
851 
852  if (this->at_last ()) {
853  this->add_after_stay_put (new_element);
854  }
855  else {
856  if (this->at_first ()) {
857  this->add_before_stay_put (new_element);
858  list->last = new_element;
859  }
860  else { //Iteratr is elsewhere
861  new_element->next = list->last->next;
862  new_element->prev = list->last;
863  list->last->next->prev = new_element;
864  list->last->next = new_element;
865  list->last = new_element;
866  }
867  }
868 }
Definition: errcode.h:30
const ERRCODE BAD_PARAMETER
Definition: lsterr.h:39
const ERRCODE NO_LIST
Definition: lsterr.h:32
void add_before_stay_put(ELIST2_LINK *new_link)
Definition: elst2.h:457
BOOL8 at_last()
Definition: elst2.h:751
void error(const char *caller, TessErrorLogCode action, const char *format,...) const
Definition: errcode.cpp:40
BOOL8 at_first()
Definition: elst2.h:729
const ERRCODE STILL_LINKED
Definition: lsterr.h:40
#define NULL
Definition: host.h:144
const ERRCODE NULL_OBJECT
Definition: lsterr.h:33
void add_after_stay_put(ELIST2_LINK *new_link)
Definition: elst2.h:354
BOOL8 ELIST2_ITERATOR::at_first ( )
inline

Definition at line 729 of file elst2.h.

729  {
730  #ifndef NDEBUG
731  if (!this)
732  NULL_OBJECT.error ("ELIST2_ITERATOR::at_first", ABORT, NULL);
733  if (!list)
734  NO_LIST.error ("ELIST2_ITERATOR::at_first", ABORT, NULL);
735  #endif
736 
737  //we're at a deleted
738  return ((list->empty ()) || (current == list->First ()) || ((current == NULL) &&
739  (prev == list->last) && //NON-last pt between
740  !ex_current_was_last)); //first and last
741 }
bool empty() const
Definition: elst2.h:107
Definition: errcode.h:30
const ERRCODE NO_LIST
Definition: lsterr.h:32
void error(const char *caller, TessErrorLogCode action, const char *format,...) const
Definition: errcode.cpp:40
#define NULL
Definition: host.h:144
const ERRCODE NULL_OBJECT
Definition: lsterr.h:33
BOOL8 ELIST2_ITERATOR::at_last ( )
inline

Definition at line 751 of file elst2.h.

751  {
752  #ifndef NDEBUG
753  if (!this)
754  NULL_OBJECT.error ("ELIST2_ITERATOR::at_last", ABORT, NULL);
755  if (!list)
756  NO_LIST.error ("ELIST2_ITERATOR::at_last", ABORT, NULL);
757  #endif
758 
759  //we're at a deleted
760  return ((list->empty ()) || (current == list->last) || ((current == NULL) &&
761  (prev == list->last) && //last point between
762  ex_current_was_last)); //first and last
763 }
bool empty() const
Definition: elst2.h:107
Definition: errcode.h:30
const ERRCODE NO_LIST
Definition: lsterr.h:32
void error(const char *caller, TessErrorLogCode action, const char *format,...) const
Definition: errcode.cpp:40
#define NULL
Definition: host.h:144
const ERRCODE NULL_OBJECT
Definition: lsterr.h:33
ELIST2_LINK * ELIST2_ITERATOR::backward ( )

Definition at line 251 of file elst2.cpp.

251  {
252  #ifndef NDEBUG
253  if (!this)
254  NULL_OBJECT.error ("ELIST2_ITERATOR::backward", ABORT, NULL);
255  if (!list)
256  NO_LIST.error ("ELIST2_ITERATOR::backward", ABORT, NULL);
257  #endif
258  if (list->empty ())
259  return NULL;
260 
261  if (current) { //not removed so
262  //set previous
263  next = current;
264  started_cycling = TRUE;
265  // In case prev is deleted by another iterator, get it from current.
266  current = current->prev;
267  } else {
268  if (ex_current_was_cycle_pt)
269  cycle_pt = prev;
270  current = prev;
271  }
272  prev = current->prev;
273 
274  #ifndef NDEBUG
275  if (!current)
276  NULL_DATA.error ("ELIST2_ITERATOR::backward", ABORT, NULL);
277  if (!prev)
278  NULL_PREV.error ("ELIST2_ITERATOR::backward", ABORT,
279  "This is: %p Current is: %p", this, current);
280  #endif
281  return current;
282 }
bool empty() const
Definition: elst2.h:107
Definition: errcode.h:30
const ERRCODE NO_LIST
Definition: lsterr.h:32
void error(const char *caller, TessErrorLogCode action, const char *format,...) const
Definition: errcode.cpp:40
const ERRCODE NULL_PREV
Definition: lsterr.h:37
const ERRCODE NULL_DATA
Definition: lsterr.h:34
#define TRUE
Definition: capi.h:28
#define NULL
Definition: host.h:144
const ERRCODE NULL_OBJECT
Definition: lsterr.h:33
BOOL8 ELIST2_ITERATOR::current_extracted ( )
inline

Definition at line 233 of file elst2.h.

233  { //current extracted?
234  return !current;
235  }
BOOL8 ELIST2_ITERATOR::cycled_list ( )
inline

Definition at line 773 of file elst2.h.

773  {
774  #ifndef NDEBUG
775  if (!this)
776  NULL_OBJECT.error ("ELIST2_ITERATOR::cycled_list", ABORT, NULL);
777  if (!list)
778  NO_LIST.error ("ELIST2_ITERATOR::cycled_list", ABORT, NULL);
779  #endif
780 
781  return ((list->empty ()) || ((current == cycle_pt) && started_cycling));
782 
783 }
bool empty() const
Definition: elst2.h:107
Definition: errcode.h:30
const ERRCODE NO_LIST
Definition: lsterr.h:32
void error(const char *caller, TessErrorLogCode action, const char *format,...) const
Definition: errcode.cpp:40
#define NULL
Definition: host.h:144
const ERRCODE NULL_OBJECT
Definition: lsterr.h:33
ELIST2_LINK* ELIST2_ITERATOR::data ( )
inline

Definition at line 199 of file elst2.h.

199  { //get current data
200  #ifndef NDEBUG
201  if (!current)
202  NULL_DATA.error ("ELIST2_ITERATOR::data", ABORT, NULL);
203  if (!list)
204  NO_LIST.error ("ELIST2_ITERATOR::data", ABORT, NULL);
205  #endif
206  return current;
207  }
Definition: errcode.h:30
const ERRCODE NO_LIST
Definition: lsterr.h:32
void error(const char *caller, TessErrorLogCode action, const char *format,...) const
Definition: errcode.cpp:40
const ERRCODE NULL_DATA
Definition: lsterr.h:34
#define NULL
Definition: host.h:144
ELIST2_LINK * ELIST2_ITERATOR::data_relative ( inT8  offset)

Definition at line 292 of file elst2.cpp.

293  { //offset from current
294  ELIST2_LINK *ptr;
295 
296  #ifndef NDEBUG
297  if (!this)
298  NULL_OBJECT.error ("ELIST2_ITERATOR::data_relative", ABORT, NULL);
299  if (!list)
300  NO_LIST.error ("ELIST2_ITERATOR::data_relative", ABORT, NULL);
301  if (list->empty ())
302  EMPTY_LIST.error ("ELIST2_ITERATOR::data_relative", ABORT, NULL);
303  #endif
304 
305  if (offset < 0)
306  for (ptr = current ? current : next; offset++ < 0; ptr = ptr->prev);
307  else
308  for (ptr = current ? current : prev; offset-- > 0; ptr = ptr->next);
309 
310  #ifndef NDEBUG
311  if (!ptr)
312  NULL_DATA.error ("ELIST2_ITERATOR::data_relative", ABORT, NULL);
313  #endif
314 
315  return ptr;
316 }
bool empty() const
Definition: elst2.h:107
Definition: errcode.h:30
const ERRCODE NO_LIST
Definition: lsterr.h:32
void error(const char *caller, TessErrorLogCode action, const char *format,...) const
Definition: errcode.cpp:40
const ERRCODE NULL_DATA
Definition: lsterr.h:34
const ERRCODE EMPTY_LIST
Definition: lsterr.h:38
#define NULL
Definition: host.h:144
const ERRCODE NULL_OBJECT
Definition: lsterr.h:33
BOOL8 ELIST2_ITERATOR::empty ( )
inline

Definition at line 225 of file elst2.h.

225  { //is list empty?
226  #ifndef NDEBUG
227  if (!list)
228  NO_LIST.error ("ELIST2_ITERATOR::empty", ABORT, NULL);
229  #endif
230  return list->empty ();
231  }
bool empty() const
Definition: elst2.h:107
Definition: errcode.h:30
const ERRCODE NO_LIST
Definition: lsterr.h:32
void error(const char *caller, TessErrorLogCode action, const char *format,...) const
Definition: errcode.cpp:40
#define NULL
Definition: host.h:144
void ELIST2_ITERATOR::exchange ( ELIST2_ITERATOR other_it)

Definition at line 329 of file elst2.cpp.

330  { //other iterator
331  const ERRCODE DONT_EXCHANGE_DELETED =
332  "Can't exchange deleted elements of lists";
333 
334  ELIST2_LINK *old_current;
335 
336  #ifndef NDEBUG
337  if (!this)
338  NULL_OBJECT.error ("ELIST2_ITERATOR::exchange", ABORT, NULL);
339  if (!list)
340  NO_LIST.error ("ELIST2_ITERATOR::exchange", ABORT, NULL);
341  if (!other_it)
342  BAD_PARAMETER.error ("ELIST2_ITERATOR::exchange", ABORT, "other_it NULL");
343  if (!(other_it->list))
344  NO_LIST.error ("ELIST2_ITERATOR::exchange", ABORT, "other_it");
345  #endif
346 
347  /* Do nothing if either list is empty or if both iterators reference the same
348  link */
349 
350  if ((list->empty ()) ||
351  (other_it->list->empty ()) || (current == other_it->current))
352  return;
353 
354  /* Error if either current element is deleted */
355 
356  if (!current || !other_it->current)
357  DONT_EXCHANGE_DELETED.error ("ELIST2_ITERATOR.exchange", ABORT, NULL);
358 
359  /* Now handle the 4 cases: doubleton list; non-doubleton adjacent elements
360  (other before this); non-doubleton adjacent elements (this before other);
361  non-adjacent elements. */
362 
363  //adjacent links
364  if ((next == other_it->current) ||
365  (other_it->next == current)) {
366  //doubleton list
367  if ((next == other_it->current) &&
368  (other_it->next == current)) {
369  prev = next = current;
370  other_it->prev = other_it->next = other_it->current;
371  }
372  else { //non-doubleton with
373  //adjacent links
374  //other before this
375  if (other_it->next == current) {
376  other_it->prev->next = current;
377  other_it->current->next = next;
378  other_it->current->prev = current;
379  current->next = other_it->current;
380  current->prev = other_it->prev;
381  next->prev = other_it->current;
382 
383  other_it->next = other_it->current;
384  prev = current;
385  }
386  else { //this before other
387  prev->next = other_it->current;
388  current->next = other_it->next;
389  current->prev = other_it->current;
390  other_it->current->next = current;
391  other_it->current->prev = prev;
392  other_it->next->prev = current;
393 
394  next = current;
395  other_it->prev = other_it->current;
396  }
397  }
398  }
399  else { //no overlap
400  prev->next = other_it->current;
401  current->next = other_it->next;
402  current->prev = other_it->prev;
403  next->prev = other_it->current;
404  other_it->prev->next = current;
405  other_it->current->next = next;
406  other_it->current->prev = prev;
407  other_it->next->prev = current;
408  }
409 
410  /* update end of list pointer when necessary (remember that the 2 iterators
411  may iterate over different lists!) */
412 
413  if (list->last == current)
414  list->last = other_it->current;
415  if (other_it->list->last == other_it->current)
416  other_it->list->last = current;
417 
418  if (current == cycle_pt)
419  cycle_pt = other_it->cycle_pt;
420  if (other_it->current == other_it->cycle_pt)
421  other_it->cycle_pt = cycle_pt;
422 
423  /* The actual exchange - in all cases*/
424 
425  old_current = current;
426  current = other_it->current;
427  other_it->current = old_current;
428 }
bool empty() const
Definition: elst2.h:107
Definition: errcode.h:30
const ERRCODE BAD_PARAMETER
Definition: lsterr.h:39
const ERRCODE NO_LIST
Definition: lsterr.h:32
void error(const char *caller, TessErrorLogCode action, const char *format,...) const
Definition: errcode.cpp:40
#define NULL
Definition: host.h:144
const ERRCODE NULL_OBJECT
Definition: lsterr.h:33
ELIST2_LINK * ELIST2_ITERATOR::extract ( )
inline

Definition at line 613 of file elst2.h.

613  {
614  ELIST2_LINK *extracted_link;
615 
616  #ifndef NDEBUG
617  if (!this)
618  NULL_OBJECT.error ("ELIST2_ITERATOR::extract", ABORT, NULL);
619  if (!list)
620  NO_LIST.error ("ELIST2_ITERATOR::extract", ABORT, NULL);
621  if (!current) //list empty or
622  //element extracted
623  NULL_CURRENT.error ("ELIST2_ITERATOR::extract",
624  ABORT, NULL);
625  #endif
626 
627  if (list->singleton()) {
628  // Special case where we do need to change the iterator.
629  prev = next = list->last = NULL;
630  } else {
631  prev->next = next; //remove from list
632  next->prev = prev;
633 
634  if (current == list->last) {
635  list->last = prev;
636  ex_current_was_last = TRUE;
637  } else {
638  ex_current_was_last = FALSE;
639  }
640  }
641  // Always set ex_current_was_cycle_pt so an add/forward will work in a loop.
642  ex_current_was_cycle_pt = (current == cycle_pt) ? TRUE : FALSE;
643  extracted_link = current;
644  extracted_link->next = NULL; //for safety
645  extracted_link->prev = NULL; //for safety
646  current = NULL;
647  return extracted_link;
648 }
bool singleton() const
Definition: elst2.h:111
Definition: errcode.h:30
const ERRCODE NO_LIST
Definition: lsterr.h:32
const ERRCODE NULL_CURRENT
Definition: lsterr.h:35
void error(const char *caller, TessErrorLogCode action, const char *format,...) const
Definition: errcode.cpp:40
#define FALSE
Definition: capi.h:29
#define TRUE
Definition: capi.h:28
#define NULL
Definition: host.h:144
const ERRCODE NULL_OBJECT
Definition: lsterr.h:33
ELIST2_LINK * ELIST2_ITERATOR::forward ( )

Definition at line 209 of file elst2.cpp.

209  {
210  #ifndef NDEBUG
211  if (!this)
212  NULL_OBJECT.error ("ELIST2_ITERATOR::forward", ABORT, NULL);
213  if (!list)
214  NO_LIST.error ("ELIST2_ITERATOR::forward", ABORT, NULL);
215  #endif
216  if (list->empty ())
217  return NULL;
218 
219  if (current) { //not removed so
220  //set previous
221  prev = current;
222  started_cycling = TRUE;
223  // In case next is deleted by another iterator, get it from the current.
224  current = current->next;
225  }
226  else {
227  if (ex_current_was_cycle_pt)
228  cycle_pt = next;
229  current = next;
230  }
231  next = current->next;
232 
233  #ifndef NDEBUG
234  if (!current)
235  NULL_DATA.error ("ELIST2_ITERATOR::forward", ABORT, NULL);
236  if (!next)
237  NULL_NEXT.error ("ELIST2_ITERATOR::forward", ABORT,
238  "This is: %p Current is: %p", this, current);
239  #endif
240  return current;
241 }
bool empty() const
Definition: elst2.h:107
Definition: errcode.h:30
const ERRCODE NO_LIST
Definition: lsterr.h:32
const ERRCODE NULL_NEXT
Definition: lsterr.h:36
void error(const char *caller, TessErrorLogCode action, const char *format,...) const
Definition: errcode.cpp:40
const ERRCODE NULL_DATA
Definition: lsterr.h:34
#define TRUE
Definition: capi.h:28
#define NULL
Definition: host.h:144
const ERRCODE NULL_OBJECT
Definition: lsterr.h:33
inT32 ELIST2_ITERATOR::length ( )
inline

Definition at line 793 of file elst2.h.

793  {
794  #ifndef NDEBUG
795  if (!this)
796  NULL_OBJECT.error ("ELIST2_ITERATOR::length", ABORT, NULL);
797  if (!list)
798  NO_LIST.error ("ELIST2_ITERATOR::length", ABORT, NULL);
799  #endif
800 
801  return list->length ();
802 }
Definition: errcode.h:30
const ERRCODE NO_LIST
Definition: lsterr.h:32
void error(const char *caller, TessErrorLogCode action, const char *format,...) const
Definition: errcode.cpp:40
inT32 length() const
Definition: elst2.cpp:102
#define NULL
Definition: host.h:144
const ERRCODE NULL_OBJECT
Definition: lsterr.h:33
void ELIST2_ITERATOR::mark_cycle_pt ( )
inline

Definition at line 706 of file elst2.h.

706  {
707  #ifndef NDEBUG
708  if (!this)
709  NULL_OBJECT.error ("ELIST2_ITERATOR::mark_cycle_pt", ABORT, NULL);
710  if (!list)
711  NO_LIST.error ("ELIST2_ITERATOR::mark_cycle_pt", ABORT, NULL);
712  #endif
713 
714  if (current)
715  cycle_pt = current;
716  else
717  ex_current_was_cycle_pt = TRUE;
718  started_cycling = FALSE;
719 }
Definition: errcode.h:30
const ERRCODE NO_LIST
Definition: lsterr.h:32
void error(const char *caller, TessErrorLogCode action, const char *format,...) const
Definition: errcode.cpp:40
#define FALSE
Definition: capi.h:29
#define TRUE
Definition: capi.h:28
#define NULL
Definition: host.h:144
const ERRCODE NULL_OBJECT
Definition: lsterr.h:33
ELIST2_LINK * ELIST2_ITERATOR::move_to_first ( )
inline

Definition at line 658 of file elst2.h.

658  {
659  #ifndef NDEBUG
660  if (!this)
661  NULL_OBJECT.error ("ELIST2_ITERATOR::move_to_first", ABORT, NULL);
662  if (!list)
663  NO_LIST.error ("ELIST2_ITERATOR::move_to_first", ABORT, NULL);
664  #endif
665 
666  current = list->First ();
667  prev = list->last;
668  next = current ? current->next : NULL;
669  return current;
670 }
Definition: errcode.h:30
const ERRCODE NO_LIST
Definition: lsterr.h:32
void error(const char *caller, TessErrorLogCode action, const char *format,...) const
Definition: errcode.cpp:40
#define NULL
Definition: host.h:144
const ERRCODE NULL_OBJECT
Definition: lsterr.h:33
ELIST2_LINK * ELIST2_ITERATOR::move_to_last ( )
inline

Definition at line 680 of file elst2.h.

680  {
681  #ifndef NDEBUG
682  if (!this)
683  NULL_OBJECT.error ("ELIST2_ITERATOR::move_to_last", ABORT, NULL);
684  if (!list)
685  NO_LIST.error ("ELIST2_ITERATOR::move_to_last", ABORT, NULL);
686  #endif
687 
688  current = list->last;
689  prev = current ? current->prev : NULL;
690  next = current ? current->next : NULL;
691  return current;
692 }
Definition: errcode.h:30
const ERRCODE NO_LIST
Definition: lsterr.h:32
void error(const char *caller, TessErrorLogCode action, const char *format,...) const
Definition: errcode.cpp:40
#define NULL
Definition: host.h:144
const ERRCODE NULL_OBJECT
Definition: lsterr.h:33
void ELIST2_ITERATOR::set_to_list ( ELIST2 list_to_iterate)
inline

Definition at line 264 of file elst2.h.

265  {
266  #ifndef NDEBUG
267  if (!this)
268  NULL_OBJECT.error ("ELIST2_ITERATOR::set_to_list", ABORT, NULL);
269  if (!list_to_iterate)
270  BAD_PARAMETER.error ("ELIST2_ITERATOR::set_to_list", ABORT,
271  "list_to_iterate is NULL");
272  #endif
273 
274  list = list_to_iterate;
275  prev = list->last;
276  current = list->First ();
277  next = current ? current->next : NULL;
278  cycle_pt = NULL; //await explicit set
279  started_cycling = FALSE;
280  ex_current_was_last = FALSE;
281  ex_current_was_cycle_pt = FALSE;
282 }
Definition: errcode.h:30
const ERRCODE BAD_PARAMETER
Definition: lsterr.h:39
void error(const char *caller, TessErrorLogCode action, const char *format,...) const
Definition: errcode.cpp:40
#define FALSE
Definition: capi.h:29
#define NULL
Definition: host.h:144
const ERRCODE NULL_OBJECT
Definition: lsterr.h:33
void ELIST2_ITERATOR::sort ( int   comparatorconst void *, const void *)
inline

Definition at line 813 of file elst2.h.

815  {
816  #ifndef NDEBUG
817  if (!this)
818  NULL_OBJECT.error ("ELIST2_ITERATOR::sort", ABORT, NULL);
819  if (!list)
820  NO_LIST.error ("ELIST2_ITERATOR::sort", ABORT, NULL);
821  #endif
822 
823  list->sort (comparator);
824  move_to_first();
825 }
void sort(int comparator(const void *, const void *))
Definition: elst2.cpp:126
Definition: errcode.h:30
const ERRCODE NO_LIST
Definition: lsterr.h:32
void error(const char *caller, TessErrorLogCode action, const char *format,...) const
Definition: errcode.cpp:40
#define NULL
Definition: host.h:144
const ERRCODE NULL_OBJECT
Definition: lsterr.h:33
ELIST2_LINK * move_to_first()
Definition: elst2.h:658

Friends And Related Function Documentation


The documentation for this class was generated from the following files: