tesseract  4.00.00dev
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 151 of file elst2.h.

Constructor & Destructor Documentation

◆ ELIST2_ITERATOR() [1/2]

ELIST2_ITERATOR::ELIST2_ITERATOR ( )
inline

Definition at line 172 of file elst2.h.

172  { //constructor
173  list = NULL;
174  } //unassigned list

◆ ELIST2_ITERATOR() [2/2]

ELIST2_ITERATOR::ELIST2_ITERATOR ( ELIST2 list_to_iterate)
inline

Definition at line 289 of file elst2.h.

289  {
290  set_to_list(list_to_iterate);
291 }
void set_to_list(ELIST2 *list_to_iterate)
Definition: elst2.h:265

Member Function Documentation

◆ add_after_stay_put()

void ELIST2_ITERATOR::add_after_stay_put ( ELIST2_LINK new_link)
inline

Definition at line 348 of file elst2.h.

349  {
350  #ifndef NDEBUG
351  if (!list)
352  NO_LIST.error ("ELIST2_ITERATOR::add_after_stay_put", ABORT, NULL);
353  if (!new_element)
354  BAD_PARAMETER.error ("ELIST2_ITERATOR::add_after_stay_put", ABORT,
355  "new_element is NULL");
356  if (new_element->next)
357  STILL_LINKED.error ("ELIST2_ITERATOR::add_after_stay_put", ABORT, NULL);
358  #endif
359 
360  if (list->empty ()) {
361  new_element->next = new_element;
362  new_element->prev = new_element;
363  list->last = new_element;
364  prev = next = new_element;
365  ex_current_was_last = FALSE;
366  current = NULL;
367  }
368  else {
369  new_element->next = next;
370  next->prev = new_element;
371 
372  if (current) { //not extracted
373  new_element->prev = current;
374  current->next = new_element;
375  if (prev == current)
376  prev = new_element;
377  if (current == list->last)
378  list->last = new_element;
379  }
380  else { //current extracted
381  new_element->prev = prev;
382  prev->next = new_element;
383  if (ex_current_was_last) {
384  list->last = new_element;
385  ex_current_was_last = FALSE;
386  }
387  }
388  next = new_element;
389  }
390 }
const ERRCODE STILL_LINKED
Definition: lsterr.h:40
bool empty() const
Definition: elst2.h:107
const ERRCODE BAD_PARAMETER
Definition: lsterr.h:39
#define FALSE
Definition: capi.h:46
void error(const char *caller, TessErrorLogCode action, const char *format,...) const
Definition: errcode.cpp:40
Definition: errcode.h:30
const ERRCODE NO_LIST
Definition: lsterr.h:32

◆ add_after_then_move()

void ELIST2_ITERATOR::add_after_then_move ( ELIST2_LINK new_link)
inline

Definition at line 300 of file elst2.h.

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

◆ add_before_stay_put()

void ELIST2_ITERATOR::add_before_stay_put ( ELIST2_LINK new_link)
inline

Definition at line 445 of file elst2.h.

446  {
447  #ifndef NDEBUG
448  if (!list)
449  NO_LIST.error ("ELIST2_ITERATOR::add_before_stay_put", ABORT, NULL);
450  if (!new_element)
451  BAD_PARAMETER.error ("ELIST2_ITERATOR::add_before_stay_put", ABORT,
452  "new_element is NULL");
453  if (new_element->next)
454  STILL_LINKED.error ("ELIST2_ITERATOR::add_before_stay_put", ABORT, NULL);
455  #endif
456 
457  if (list->empty ()) {
458  new_element->next = new_element;
459  new_element->prev = new_element;
460  list->last = new_element;
461  prev = next = new_element;
462  ex_current_was_last = TRUE;
463  current = NULL;
464  }
465  else {
466  prev->next = new_element;
467  new_element->prev = prev;
468 
469  if (current) { //not extracted
470  new_element->next = current;
471  current->prev = new_element;
472  if (next == current)
473  next = new_element;
474  }
475  else { //current extracted
476  new_element->next = next;
477  next->prev = new_element;
478  if (ex_current_was_last)
479  list->last = new_element;
480  }
481  prev = new_element;
482  }
483 }
#define TRUE
Definition: capi.h:45
const ERRCODE STILL_LINKED
Definition: lsterr.h:40
bool empty() const
Definition: elst2.h:107
const ERRCODE BAD_PARAMETER
Definition: lsterr.h:39
void error(const char *caller, TessErrorLogCode action, const char *format,...) const
Definition: errcode.cpp:40
Definition: errcode.h:30
const ERRCODE NO_LIST
Definition: lsterr.h:32

◆ add_before_then_move()

void ELIST2_ITERATOR::add_before_then_move ( ELIST2_LINK new_link)
inline

Definition at line 399 of file elst2.h.

400  {
401  #ifndef NDEBUG
402  if (!list)
403  NO_LIST.error ("ELIST2_ITERATOR::add_before_then_move", ABORT, NULL);
404  if (!new_element)
405  BAD_PARAMETER.error ("ELIST2_ITERATOR::add_before_then_move", ABORT,
406  "new_element is NULL");
407  if (new_element->next)
408  STILL_LINKED.error ("ELIST2_ITERATOR::add_before_then_move", ABORT, NULL);
409  #endif
410 
411  if (list->empty ()) {
412  new_element->next = new_element;
413  new_element->prev = new_element;
414  list->last = new_element;
415  prev = next = new_element;
416  }
417  else {
418  prev->next = new_element;
419  new_element->prev = prev;
420 
421  if (current) { //not extracted
422  new_element->next = current;
423  current->prev = new_element;
424  next = current;
425  }
426  else { //current extracted
427  new_element->next = next;
428  next->prev = new_element;
429  if (ex_current_was_last)
430  list->last = new_element;
431  if (ex_current_was_cycle_pt)
432  cycle_pt = new_element;
433  }
434  }
435  current = new_element;
436 }
const ERRCODE STILL_LINKED
Definition: lsterr.h:40
bool empty() const
Definition: elst2.h:107
const ERRCODE BAD_PARAMETER
Definition: lsterr.h:39
void error(const char *caller, TessErrorLogCode action, const char *format,...) const
Definition: errcode.cpp:40
Definition: errcode.h:30
const ERRCODE NO_LIST
Definition: lsterr.h:32

◆ add_list_after()

void ELIST2_ITERATOR::add_list_after ( ELIST2 list_to_add)
inline

Definition at line 493 of file elst2.h.

493  {
494  #ifndef NDEBUG
495  if (!list)
496  NO_LIST.error ("ELIST2_ITERATOR::add_list_after", ABORT, NULL);
497  if (!list_to_add)
498  BAD_PARAMETER.error ("ELIST2_ITERATOR::add_list_after", ABORT,
499  "list_to_add is NULL");
500  #endif
501 
502  if (!list_to_add->empty ()) {
503  if (list->empty ()) {
504  list->last = list_to_add->last;
505  prev = list->last;
506  next = list->First ();
507  ex_current_was_last = TRUE;
508  current = NULL;
509  }
510  else {
511  if (current) { //not extracted
512  current->next = list_to_add->First ();
513  current->next->prev = current;
514  if (current == list->last)
515  list->last = list_to_add->last;
516  list_to_add->last->next = next;
517  next->prev = list_to_add->last;
518  next = current->next;
519  }
520  else { //current extracted
521  prev->next = list_to_add->First ();
522  prev->next->prev = prev;
523  if (ex_current_was_last) {
524  list->last = list_to_add->last;
525  ex_current_was_last = FALSE;
526  }
527  list_to_add->last->next = next;
528  next->prev = list_to_add->last;
529  next = prev->next;
530  }
531  }
532  list_to_add->last = NULL;
533  }
534 }
#define TRUE
Definition: capi.h:45
bool empty() const
Definition: elst2.h:107
const ERRCODE BAD_PARAMETER
Definition: lsterr.h:39
#define FALSE
Definition: capi.h:46
void error(const char *caller, TessErrorLogCode action, const char *format,...) const
Definition: errcode.cpp:40
Definition: errcode.h:30
const ERRCODE NO_LIST
Definition: lsterr.h:32

◆ add_list_before()

void ELIST2_ITERATOR::add_list_before ( ELIST2 list_to_add)
inline

Definition at line 544 of file elst2.h.

544  {
545  #ifndef NDEBUG
546  if (!list)
547  NO_LIST.error ("ELIST2_ITERATOR::add_list_before", ABORT, NULL);
548  if (!list_to_add)
549  BAD_PARAMETER.error ("ELIST2_ITERATOR::add_list_before", ABORT,
550  "list_to_add is NULL");
551  #endif
552 
553  if (!list_to_add->empty ()) {
554  if (list->empty ()) {
555  list->last = list_to_add->last;
556  prev = list->last;
557  current = list->First ();
558  next = current->next;
559  ex_current_was_last = FALSE;
560  }
561  else {
562  prev->next = list_to_add->First ();
563  prev->next->prev = prev;
564 
565  if (current) { //not extracted
566  list_to_add->last->next = current;
567  current->prev = list_to_add->last;
568  }
569  else { //current extracted
570  list_to_add->last->next = next;
571  next->prev = list_to_add->last;
572  if (ex_current_was_last)
573  list->last = list_to_add->last;
574  if (ex_current_was_cycle_pt)
575  cycle_pt = prev->next;
576  }
577  current = prev->next;
578  next = current->next;
579  }
580  list_to_add->last = NULL;
581  }
582 }
bool empty() const
Definition: elst2.h:107
const ERRCODE BAD_PARAMETER
Definition: lsterr.h:39
#define FALSE
Definition: capi.h:46
void error(const char *caller, TessErrorLogCode action, const char *format,...) const
Definition: errcode.cpp:40
Definition: errcode.h:30
const ERRCODE NO_LIST
Definition: lsterr.h:32

◆ add_to_end()

void ELIST2_ITERATOR::add_to_end ( ELIST2_LINK new_link)
inline

Definition at line 791 of file elst2.h.

792  {
793  #ifndef NDEBUG
794  if (!list)
795  NO_LIST.error ("ELIST2_ITERATOR::add_to_end", ABORT, NULL);
796  if (!new_element)
797  BAD_PARAMETER.error ("ELIST2_ITERATOR::add_to_end", ABORT,
798  "new_element is NULL");
799  if (new_element->next)
800  STILL_LINKED.error ("ELIST2_ITERATOR::add_to_end", ABORT, NULL);
801  #endif
802 
803  if (this->at_last ()) {
804  this->add_after_stay_put (new_element);
805  }
806  else {
807  if (this->at_first ()) {
808  this->add_before_stay_put (new_element);
809  list->last = new_element;
810  }
811  else { //Iteratr is elsewhere
812  new_element->next = list->last->next;
813  new_element->prev = list->last;
814  list->last->next->prev = new_element;
815  list->last->next = new_element;
816  list->last = new_element;
817  }
818  }
819 }
BOOL8 at_first()
Definition: elst2.h:697
const ERRCODE STILL_LINKED
Definition: lsterr.h:40
const ERRCODE BAD_PARAMETER
Definition: lsterr.h:39
void add_after_stay_put(ELIST2_LINK *new_link)
Definition: elst2.h:348
void error(const char *caller, TessErrorLogCode action, const char *format,...) const
Definition: errcode.cpp:40
BOOL8 at_last()
Definition: elst2.h:716
Definition: errcode.h:30
void add_before_stay_put(ELIST2_LINK *new_link)
Definition: elst2.h:445
const ERRCODE NO_LIST
Definition: lsterr.h:32

◆ at_first()

BOOL8 ELIST2_ITERATOR::at_first ( )
inline

Definition at line 697 of file elst2.h.

697  {
698  #ifndef NDEBUG
699  if (!list)
700  NO_LIST.error ("ELIST2_ITERATOR::at_first", ABORT, NULL);
701  #endif
702 
703  //we're at a deleted
704  return ((list->empty ()) || (current == list->First ()) || ((current == NULL) &&
705  (prev == list->last) && //NON-last pt between
706  !ex_current_was_last)); //first and last
707 }
bool empty() const
Definition: elst2.h:107
void error(const char *caller, TessErrorLogCode action, const char *format,...) const
Definition: errcode.cpp:40
Definition: errcode.h:30
const ERRCODE NO_LIST
Definition: lsterr.h:32

◆ at_last()

BOOL8 ELIST2_ITERATOR::at_last ( )
inline

Definition at line 716 of file elst2.h.

716  {
717  #ifndef NDEBUG
718  if (!list)
719  NO_LIST.error ("ELIST2_ITERATOR::at_last", ABORT, NULL);
720  #endif
721 
722  //we're at a deleted
723  return ((list->empty ()) || (current == list->last) || ((current == NULL) &&
724  (prev == list->last) && //last point between
725  ex_current_was_last)); //first and last
726 }
bool empty() const
Definition: elst2.h:107
void error(const char *caller, TessErrorLogCode action, const char *format,...) const
Definition: errcode.cpp:40
Definition: errcode.h:30
const ERRCODE NO_LIST
Definition: lsterr.h:32

◆ backward()

ELIST2_LINK * ELIST2_ITERATOR::backward ( )

Definition at line 226 of file elst2.cpp.

226  {
227  #ifndef NDEBUG
228  if (!list)
229  NO_LIST.error ("ELIST2_ITERATOR::backward", ABORT, NULL);
230  #endif
231  if (list->empty ())
232  return NULL;
233 
234  if (current) { //not removed so
235  //set previous
236  next = current;
237  started_cycling = TRUE;
238  // In case prev is deleted by another iterator, get it from current.
239  current = current->prev;
240  } else {
241  if (ex_current_was_cycle_pt)
242  cycle_pt = prev;
243  current = prev;
244  }
245  prev = current->prev;
246 
247  #ifndef NDEBUG
248  if (!current)
249  NULL_DATA.error ("ELIST2_ITERATOR::backward", ABORT, NULL);
250  if (!prev)
251  NULL_PREV.error ("ELIST2_ITERATOR::backward", ABORT,
252  "This is: %p Current is: %p", this, current);
253  #endif
254  return current;
255 }
#define TRUE
Definition: capi.h:45
const ERRCODE NULL_DATA
Definition: lsterr.h:34
bool empty() const
Definition: elst2.h:107
void error(const char *caller, TessErrorLogCode action, const char *format,...) const
Definition: errcode.cpp:40
const ERRCODE NULL_PREV
Definition: lsterr.h:37
Definition: errcode.h:30
const ERRCODE NO_LIST
Definition: lsterr.h:32

◆ current_extracted()

BOOL8 ELIST2_ITERATOR::current_extracted ( )
inline

Definition at line 234 of file elst2.h.

234  { //current extracted?
235  return !current;
236  }

◆ cycled_list()

BOOL8 ELIST2_ITERATOR::cycled_list ( )
inline

Definition at line 735 of file elst2.h.

735  {
736  #ifndef NDEBUG
737  if (!list)
738  NO_LIST.error ("ELIST2_ITERATOR::cycled_list", ABORT, NULL);
739  #endif
740 
741  return ((list->empty ()) || ((current == cycle_pt) && started_cycling));
742 
743 }
bool empty() const
Definition: elst2.h:107
void error(const char *caller, TessErrorLogCode action, const char *format,...) const
Definition: errcode.cpp:40
Definition: errcode.h:30
const ERRCODE NO_LIST
Definition: lsterr.h:32

◆ data()

ELIST2_LINK* ELIST2_ITERATOR::data ( )
inline

Definition at line 200 of file elst2.h.

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

◆ data_relative()

ELIST2_LINK * ELIST2_ITERATOR::data_relative ( inT8  offset)

Definition at line 264 of file elst2.cpp.

265  { //offset from current
266  ELIST2_LINK *ptr;
267 
268  #ifndef NDEBUG
269  if (!list)
270  NO_LIST.error ("ELIST2_ITERATOR::data_relative", ABORT, NULL);
271  if (list->empty ())
272  EMPTY_LIST.error ("ELIST2_ITERATOR::data_relative", ABORT, NULL);
273  #endif
274 
275  if (offset < 0)
276  for (ptr = current ? current : next; offset++ < 0; ptr = ptr->prev);
277  else
278  for (ptr = current ? current : prev; offset-- > 0; ptr = ptr->next);
279 
280  #ifndef NDEBUG
281  if (!ptr)
282  NULL_DATA.error ("ELIST2_ITERATOR::data_relative", ABORT, NULL);
283  #endif
284 
285  return ptr;
286 }
const ERRCODE NULL_DATA
Definition: lsterr.h:34
voidpf uLong offset
Definition: ioapi.h:42
bool empty() const
Definition: elst2.h:107
void error(const char *caller, TessErrorLogCode action, const char *format,...) const
Definition: errcode.cpp:40
const ERRCODE EMPTY_LIST
Definition: lsterr.h:38
Definition: errcode.h:30
const ERRCODE NO_LIST
Definition: lsterr.h:32

◆ empty()

BOOL8 ELIST2_ITERATOR::empty ( )
inline

Definition at line 226 of file elst2.h.

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

◆ exchange()

void ELIST2_ITERATOR::exchange ( ELIST2_ITERATOR other_it)

Definition at line 298 of file elst2.cpp.

299  { //other iterator
300  const ERRCODE DONT_EXCHANGE_DELETED =
301  "Can't exchange deleted elements of lists";
302 
303  ELIST2_LINK *old_current;
304 
305  #ifndef NDEBUG
306  if (!list)
307  NO_LIST.error ("ELIST2_ITERATOR::exchange", ABORT, NULL);
308  if (!other_it)
309  BAD_PARAMETER.error ("ELIST2_ITERATOR::exchange", ABORT, "other_it NULL");
310  if (!(other_it->list))
311  NO_LIST.error ("ELIST2_ITERATOR::exchange", ABORT, "other_it");
312  #endif
313 
314  /* Do nothing if either list is empty or if both iterators reference the same
315  link */
316 
317  if ((list->empty ()) ||
318  (other_it->list->empty ()) || (current == other_it->current))
319  return;
320 
321  /* Error if either current element is deleted */
322 
323  if (!current || !other_it->current)
324  DONT_EXCHANGE_DELETED.error ("ELIST2_ITERATOR.exchange", ABORT, NULL);
325 
326  /* Now handle the 4 cases: doubleton list; non-doubleton adjacent elements
327  (other before this); non-doubleton adjacent elements (this before other);
328  non-adjacent elements. */
329 
330  //adjacent links
331  if ((next == other_it->current) ||
332  (other_it->next == current)) {
333  //doubleton list
334  if ((next == other_it->current) &&
335  (other_it->next == current)) {
336  prev = next = current;
337  other_it->prev = other_it->next = other_it->current;
338  }
339  else { //non-doubleton with
340  //adjacent links
341  //other before this
342  if (other_it->next == current) {
343  other_it->prev->next = current;
344  other_it->current->next = next;
345  other_it->current->prev = current;
346  current->next = other_it->current;
347  current->prev = other_it->prev;
348  next->prev = other_it->current;
349 
350  other_it->next = other_it->current;
351  prev = current;
352  }
353  else { //this before other
354  prev->next = other_it->current;
355  current->next = other_it->next;
356  current->prev = other_it->current;
357  other_it->current->next = current;
358  other_it->current->prev = prev;
359  other_it->next->prev = current;
360 
361  next = current;
362  other_it->prev = other_it->current;
363  }
364  }
365  }
366  else { //no overlap
367  prev->next = other_it->current;
368  current->next = other_it->next;
369  current->prev = other_it->prev;
370  next->prev = other_it->current;
371  other_it->prev->next = current;
372  other_it->current->next = next;
373  other_it->current->prev = prev;
374  other_it->next->prev = current;
375  }
376 
377  /* update end of list pointer when necessary (remember that the 2 iterators
378  may iterate over different lists!) */
379 
380  if (list->last == current)
381  list->last = other_it->current;
382  if (other_it->list->last == other_it->current)
383  other_it->list->last = current;
384 
385  if (current == cycle_pt)
386  cycle_pt = other_it->cycle_pt;
387  if (other_it->current == other_it->cycle_pt)
388  other_it->cycle_pt = cycle_pt;
389 
390  /* The actual exchange - in all cases*/
391 
392  old_current = current;
393  current = other_it->current;
394  other_it->current = old_current;
395 }
bool empty() const
Definition: elst2.h:107
const ERRCODE BAD_PARAMETER
Definition: lsterr.h:39
void error(const char *caller, TessErrorLogCode action, const char *format,...) const
Definition: errcode.cpp:40
Definition: errcode.h:30
const ERRCODE NO_LIST
Definition: lsterr.h:32

◆ extract()

ELIST2_LINK * ELIST2_ITERATOR::extract ( )
inline

Definition at line 593 of file elst2.h.

593  {
594  ELIST2_LINK *extracted_link;
595 
596  #ifndef NDEBUG
597  if (!list)
598  NO_LIST.error ("ELIST2_ITERATOR::extract", ABORT, NULL);
599  if (!current) //list empty or
600  //element extracted
601  NULL_CURRENT.error ("ELIST2_ITERATOR::extract",
602  ABORT, NULL);
603  #endif
604 
605  if (list->singleton()) {
606  // Special case where we do need to change the iterator.
607  prev = next = list->last = NULL;
608  } else {
609  prev->next = next; //remove from list
610  next->prev = prev;
611 
612  if (current == list->last) {
613  list->last = prev;
614  ex_current_was_last = TRUE;
615  } else {
616  ex_current_was_last = FALSE;
617  }
618  }
619  // Always set ex_current_was_cycle_pt so an add/forward will work in a loop.
620  ex_current_was_cycle_pt = (current == cycle_pt) ? TRUE : FALSE;
621  extracted_link = current;
622  extracted_link->next = NULL; //for safety
623  extracted_link->prev = NULL; //for safety
624  current = NULL;
625  return extracted_link;
626 }
#define TRUE
Definition: capi.h:45
#define FALSE
Definition: capi.h:46
void error(const char *caller, TessErrorLogCode action, const char *format,...) const
Definition: errcode.cpp:40
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

◆ forward()

ELIST2_LINK * ELIST2_ITERATOR::forward ( )

Definition at line 187 of file elst2.cpp.

187  {
188  #ifndef NDEBUG
189  if (!list)
190  NO_LIST.error ("ELIST2_ITERATOR::forward", ABORT, NULL);
191  #endif
192  if (list->empty ())
193  return NULL;
194 
195  if (current) { //not removed so
196  //set previous
197  prev = current;
198  started_cycling = TRUE;
199  // In case next is deleted by another iterator, get it from the current.
200  current = current->next;
201  }
202  else {
203  if (ex_current_was_cycle_pt)
204  cycle_pt = next;
205  current = next;
206  }
207  next = current->next;
208 
209  #ifndef NDEBUG
210  if (!current)
211  NULL_DATA.error ("ELIST2_ITERATOR::forward", ABORT, NULL);
212  if (!next)
213  NULL_NEXT.error ("ELIST2_ITERATOR::forward", ABORT,
214  "This is: %p Current is: %p", this, current);
215  #endif
216  return current;
217 }
#define TRUE
Definition: capi.h:45
const ERRCODE NULL_NEXT
Definition: lsterr.h:36
const ERRCODE NULL_DATA
Definition: lsterr.h:34
bool empty() const
Definition: elst2.h:107
void error(const char *caller, TessErrorLogCode action, const char *format,...) const
Definition: errcode.cpp:40
Definition: errcode.h:30
const ERRCODE NO_LIST
Definition: lsterr.h:32

◆ length()

inT32 ELIST2_ITERATOR::length ( )
inline

Definition at line 752 of file elst2.h.

752  {
753  #ifndef NDEBUG
754  if (!list)
755  NO_LIST.error ("ELIST2_ITERATOR::length", ABORT, NULL);
756  #endif
757 
758  return list->length ();
759 }
void error(const char *caller, TessErrorLogCode action, const char *format,...) const
Definition: errcode.cpp:40
inT32 length() const
Definition: elst2.cpp:91
Definition: errcode.h:30
const ERRCODE NO_LIST
Definition: lsterr.h:32

◆ mark_cycle_pt()

void ELIST2_ITERATOR::mark_cycle_pt ( )
inline

Definition at line 677 of file elst2.h.

677  {
678  #ifndef NDEBUG
679  if (!list)
680  NO_LIST.error ("ELIST2_ITERATOR::mark_cycle_pt", ABORT, NULL);
681  #endif
682 
683  if (current)
684  cycle_pt = current;
685  else
686  ex_current_was_cycle_pt = TRUE;
687  started_cycling = FALSE;
688 }
#define TRUE
Definition: capi.h:45
#define FALSE
Definition: capi.h:46
void error(const char *caller, TessErrorLogCode action, const char *format,...) const
Definition: errcode.cpp:40
Definition: errcode.h:30
const ERRCODE NO_LIST
Definition: lsterr.h:32

◆ move_to_first()

ELIST2_LINK * ELIST2_ITERATOR::move_to_first ( )
inline

Definition at line 635 of file elst2.h.

635  {
636  #ifndef NDEBUG
637  if (!list)
638  NO_LIST.error ("ELIST2_ITERATOR::move_to_first", ABORT, NULL);
639  #endif
640 
641  current = list->First ();
642  prev = list->last;
643  next = current ? current->next : NULL;
644  return current;
645 }
void error(const char *caller, TessErrorLogCode action, const char *format,...) const
Definition: errcode.cpp:40
Definition: errcode.h:30
const ERRCODE NO_LIST
Definition: lsterr.h:32

◆ move_to_last()

ELIST2_LINK * ELIST2_ITERATOR::move_to_last ( )
inline

Definition at line 654 of file elst2.h.

654  {
655  #ifndef NDEBUG
656  if (!list)
657  NO_LIST.error ("ELIST2_ITERATOR::move_to_last", ABORT, NULL);
658  #endif
659 
660  current = list->last;
661  prev = current ? current->prev : NULL;
662  next = current ? current->next : NULL;
663  return current;
664 }
void error(const char *caller, TessErrorLogCode action, const char *format,...) const
Definition: errcode.cpp:40
Definition: errcode.h:30
const ERRCODE NO_LIST
Definition: lsterr.h:32

◆ set_to_list()

void ELIST2_ITERATOR::set_to_list ( ELIST2 list_to_iterate)
inline

Definition at line 265 of file elst2.h.

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

◆ sort()

void ELIST2_ITERATOR::sort ( int   comparator const void *, const void *)
inline

Definition at line 769 of file elst2.h.

771  {
772  #ifndef NDEBUG
773  if (!list)
774  NO_LIST.error ("ELIST2_ITERATOR::sort", ABORT, NULL);
775  #endif
776 
777  list->sort (comparator);
778  move_to_first();
779 }
void sort(int comparator(const void *, const void *))
Definition: elst2.cpp:109
void error(const char *caller, TessErrorLogCode action, const char *format,...) const
Definition: errcode.cpp:40
ELIST2_LINK * move_to_first()
Definition: elst2.h:635
Definition: errcode.h:30
const ERRCODE NO_LIST
Definition: lsterr.h:32

Friends And Related Function Documentation

◆ ELIST2::assign_to_sublist


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