tesseract  4.0.0-1-g2a2b
ELIST2_ITERATOR Class Reference

#include <elst2.h>

Public Member Functions

 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_t offset)
 
ELIST2_LINKforward ()
 
ELIST2_LINKbackward ()
 
ELIST2_LINKextract ()
 
ELIST2_LINKmove_to_first ()
 
ELIST2_LINKmove_to_last ()
 
void mark_cycle_pt ()
 
bool empty ()
 
bool current_extracted ()
 
bool at_first ()
 
bool at_last ()
 
bool cycled_list ()
 
void add_to_end (ELIST2_LINK *new_link)
 
void exchange (ELIST2_ITERATOR *other_it)
 
int32_t 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()

ELIST2_ITERATOR::ELIST2_ITERATOR ( ELIST2 list_to_iterate)
inline

Definition at line 288 of file elst2.h.

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

Member Function Documentation

◆ add_after_stay_put()

void ELIST2_ITERATOR::add_after_stay_put ( ELIST2_LINK new_link)
inline

Definition at line 347 of file elst2.h.

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

◆ add_after_then_move()

void ELIST2_ITERATOR::add_after_then_move ( ELIST2_LINK new_link)
inline

Definition at line 299 of file elst2.h.

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

◆ add_before_stay_put()

void ELIST2_ITERATOR::add_before_stay_put ( ELIST2_LINK new_link)
inline

Definition at line 444 of file elst2.h.

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

◆ add_before_then_move()

void ELIST2_ITERATOR::add_before_then_move ( ELIST2_LINK new_link)
inline

Definition at line 398 of file elst2.h.

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

◆ add_list_after()

void ELIST2_ITERATOR::add_list_after ( ELIST2 list_to_add)
inline

Definition at line 492 of file elst2.h.

492  {
493  #ifndef NDEBUG
494  if (!list)
495  NO_LIST.error ("ELIST2_ITERATOR::add_list_after", ABORT, nullptr);
496  if (!list_to_add)
497  BAD_PARAMETER.error ("ELIST2_ITERATOR::add_list_after", ABORT,
498  "list_to_add is nullptr");
499  #endif
500 
501  if (!list_to_add->empty ()) {
502  if (list->empty ()) {
503  list->last = list_to_add->last;
504  prev = list->last;
505  next = list->First ();
506  ex_current_was_last = true;
507  current = nullptr;
508  }
509  else {
510  if (current) { //not extracted
511  current->next = list_to_add->First ();
512  current->next->prev = current;
513  if (current == list->last)
514  list->last = list_to_add->last;
515  list_to_add->last->next = next;
516  next->prev = list_to_add->last;
517  next = current->next;
518  }
519  else { //current extracted
520  prev->next = list_to_add->First ();
521  prev->next->prev = prev;
522  if (ex_current_was_last) {
523  list->last = list_to_add->last;
524  ex_current_was_last = false;
525  }
526  list_to_add->last->next = next;
527  next->prev = list_to_add->last;
528  next = prev->next;
529  }
530  }
531  list_to_add->last = nullptr;
532  }
533 }
bool empty() const
Definition: elst2.h:107
const ERRCODE NO_LIST
Definition: lsterr.h:32
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:37

◆ add_list_before()

void ELIST2_ITERATOR::add_list_before ( ELIST2 list_to_add)
inline

Definition at line 543 of file elst2.h.

543  {
544  #ifndef NDEBUG
545  if (!list)
546  NO_LIST.error ("ELIST2_ITERATOR::add_list_before", ABORT, nullptr);
547  if (!list_to_add)
548  BAD_PARAMETER.error ("ELIST2_ITERATOR::add_list_before", ABORT,
549  "list_to_add is nullptr");
550  #endif
551 
552  if (!list_to_add->empty ()) {
553  if (list->empty ()) {
554  list->last = list_to_add->last;
555  prev = list->last;
556  current = list->First ();
557  next = current->next;
558  ex_current_was_last = false;
559  }
560  else {
561  prev->next = list_to_add->First ();
562  prev->next->prev = prev;
563 
564  if (current) { //not extracted
565  list_to_add->last->next = current;
566  current->prev = list_to_add->last;
567  }
568  else { //current extracted
569  list_to_add->last->next = next;
570  next->prev = list_to_add->last;
571  if (ex_current_was_last)
572  list->last = list_to_add->last;
573  if (ex_current_was_cycle_pt)
574  cycle_pt = prev->next;
575  }
576  current = prev->next;
577  next = current->next;
578  }
579  list_to_add->last = nullptr;
580  }
581 }
bool empty() const
Definition: elst2.h:107
const ERRCODE NO_LIST
Definition: lsterr.h:32
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:37

◆ add_to_end()

void ELIST2_ITERATOR::add_to_end ( ELIST2_LINK new_link)
inline

Definition at line 790 of file elst2.h.

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

◆ at_first()

bool ELIST2_ITERATOR::at_first ( )
inline

Definition at line 696 of file elst2.h.

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

◆ at_last()

bool ELIST2_ITERATOR::at_last ( )
inline

Definition at line 715 of file elst2.h.

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

◆ backward()

ELIST2_LINK * ELIST2_ITERATOR::backward ( )

Definition at line 231 of file elst2.cpp.

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

◆ current_extracted()

bool ELIST2_ITERATOR::current_extracted ( )
inline

Definition at line 230 of file elst2.h.

230  { //current extracted?
231  return !current;
232  }

◆ cycled_list()

bool ELIST2_ITERATOR::cycled_list ( )
inline

Definition at line 734 of file elst2.h.

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

◆ data()

ELIST2_LINK* ELIST2_ITERATOR::data ( )
inline

Definition at line 196 of file elst2.h.

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

◆ data_relative()

ELIST2_LINK * ELIST2_ITERATOR::data_relative ( int8_t  offset)

Definition at line 270 of file elst2.cpp.

271  { //offset from current
272  ELIST2_LINK *ptr;
273 
274  #ifndef NDEBUG
275  if (!list)
276  NO_LIST.error ("ELIST2_ITERATOR::data_relative", ABORT, nullptr);
277  if (list->empty ())
278  EMPTY_LIST.error ("ELIST2_ITERATOR::data_relative", ABORT, nullptr);
279  #endif
280 
281  if (offset < 0)
282  for (ptr = current ? current : next; offset++ < 0; ptr = ptr->prev);
283  else
284  for (ptr = current ? current : prev; offset-- > 0; ptr = ptr->next);
285 
286  #ifndef NDEBUG
287  if (!ptr)
288  NULL_DATA.error ("ELIST2_ITERATOR::data_relative", ABORT, nullptr);
289  #endif
290 
291  return ptr;
292 }
bool empty() const
Definition: elst2.h:107
const ERRCODE NO_LIST
Definition: lsterr.h:32
Definition: errcode.h:30
const ERRCODE NULL_DATA
Definition: lsterr.h:34
const ERRCODE EMPTY_LIST
Definition: lsterr.h:38
void error(const char *caller, TessErrorLogCode action, const char *format,...) const
Definition: errcode.cpp:37

◆ empty()

bool ELIST2_ITERATOR::empty ( )
inline

Definition at line 222 of file elst2.h.

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

◆ exchange()

void ELIST2_ITERATOR::exchange ( ELIST2_ITERATOR other_it)

Definition at line 304 of file elst2.cpp.

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

◆ extract()

ELIST2_LINK * ELIST2_ITERATOR::extract ( )
inline

Definition at line 592 of file elst2.h.

592  {
593  ELIST2_LINK *extracted_link;
594 
595  #ifndef NDEBUG
596  if (!list)
597  NO_LIST.error ("ELIST2_ITERATOR::extract", ABORT, nullptr);
598  if (!current) //list empty or
599  //element extracted
600  NULL_CURRENT.error ("ELIST2_ITERATOR::extract",
601  ABORT, nullptr);
602  #endif
603 
604  if (list->singleton()) {
605  // Special case where we do need to change the iterator.
606  prev = next = list->last = nullptr;
607  } else {
608  prev->next = next; //remove from list
609  next->prev = prev;
610 
611  if (current == list->last) {
612  list->last = prev;
613  ex_current_was_last = true;
614  } else {
615  ex_current_was_last = false;
616  }
617  }
618  // Always set ex_current_was_cycle_pt so an add/forward will work in a loop.
619  ex_current_was_cycle_pt = (current == cycle_pt);
620  extracted_link = current;
621  extracted_link->next = nullptr; //for safety
622  extracted_link->prev = nullptr; //for safety
623  current = nullptr;
624  return extracted_link;
625 }
bool singleton() const
Definition: elst2.h:111
const ERRCODE NO_LIST
Definition: lsterr.h:32
Definition: errcode.h:30
const ERRCODE NULL_CURRENT
Definition: lsterr.h:35
void error(const char *caller, TessErrorLogCode action, const char *format,...) const
Definition: errcode.cpp:37

◆ 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, nullptr);
191  #endif
192  if (list->empty ())
193  return nullptr;
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 
208 #ifndef NDEBUG
209  if (!current)
210  NULL_DATA.error ("ELIST2_ITERATOR::forward", ABORT, nullptr);
211 #endif
212 
213  next = current->next;
214 
215 #ifndef NDEBUG
216  if (!next)
217  NULL_NEXT.error ("ELIST2_ITERATOR::forward", ABORT,
218  "This is: %p Current is: %p", this, current);
219 #endif
220 
221  return current;
222 }
#define TRUE
Definition: capi.h:51
bool empty() const
Definition: elst2.h:107
const ERRCODE NO_LIST
Definition: lsterr.h:32
Definition: errcode.h:30
const ERRCODE NULL_NEXT
Definition: lsterr.h:36
const ERRCODE NULL_DATA
Definition: lsterr.h:34
void error(const char *caller, TessErrorLogCode action, const char *format,...) const
Definition: errcode.cpp:37

◆ length()

int32_t ELIST2_ITERATOR::length ( )
inline

Definition at line 751 of file elst2.h.

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

◆ mark_cycle_pt()

void ELIST2_ITERATOR::mark_cycle_pt ( )
inline

Definition at line 676 of file elst2.h.

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

◆ move_to_first()

ELIST2_LINK * ELIST2_ITERATOR::move_to_first ( )
inline

Definition at line 634 of file elst2.h.

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

◆ move_to_last()

ELIST2_LINK * ELIST2_ITERATOR::move_to_last ( )
inline

Definition at line 653 of file elst2.h.

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

◆ set_to_list()

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 (!list_to_iterate)
268  BAD_PARAMETER.error ("ELIST2_ITERATOR::set_to_list", ABORT,
269  "list_to_iterate is nullptr");
270  #endif
271 
272  list = list_to_iterate;
273  prev = list->last;
274  current = list->First ();
275  next = current ? current->next : nullptr;
276  cycle_pt = nullptr; //await explicit set
277  started_cycling = false;
278  ex_current_was_last = false;
279  ex_current_was_cycle_pt = false;
280 }
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:37

◆ sort()

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

Definition at line 768 of file elst2.h.

770  {
771  #ifndef NDEBUG
772  if (!list)
773  NO_LIST.error ("ELIST2_ITERATOR::sort", ABORT, nullptr);
774  #endif
775 
776  list->sort (comparator);
777  move_to_first();
778 }
const ERRCODE NO_LIST
Definition: lsterr.h:32
Definition: errcode.h:30
ELIST2_LINK * move_to_first()
Definition: elst2.h:634
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:37

Friends And Related Function Documentation

◆ ELIST2::assign_to_sublist


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