68 prev = next =
nullptr;
73 prev = next =
nullptr;
78 prev = next =
nullptr;
95 return last ? last->
next :
nullptr;
103 void internal_clear (
112 return last ? (last == last->
next) :
false;
117 last = from_list->
last;
124 void assign_to_sublist(
132 const void *,
const void *));
139 void add_sorted(
int comparator(
const void*,
const void*),
178 void add_after_then_move(
181 void add_after_stay_put(
184 void add_before_then_move(
187 void add_before_stay_put(
193 void add_list_before(
199 NULL_DATA.
error (
"ELIST2_ITERATOR::data", ABORT,
nullptr);
201 NO_LIST.
error (
"ELIST2_ITERATOR::data", ABORT,
nullptr);
220 void mark_cycle_pt();
225 NO_LIST.
error (
"ELIST2_ITERATOR::empty", ABORT,
nullptr);
227 return list->
empty ();
250 const void *,
const void *));
265 ELIST2 *list_to_iterate) {
267 if (!list_to_iterate)
268 BAD_PARAMETER.
error (
"ELIST2_ITERATOR::set_to_list", ABORT,
269 "list_to_iterate is nullptr");
272 list = list_to_iterate;
274 current = list->First ();
275 next = current ? current->
next :
nullptr;
277 started_cycling =
false;
278 ex_current_was_last =
false;
279 ex_current_was_cycle_pt =
false;
289 set_to_list(list_to_iterate);
303 NO_LIST.
error (
"ELIST2_ITERATOR::add_after_then_move", ABORT,
nullptr);
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);
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;
318 new_element->
next = next;
319 next->
prev = new_element;
322 new_element->
prev = current;
323 current->
next = new_element;
325 if (current == list->last)
326 list->last = new_element;
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;
337 current = new_element;
351 NO_LIST.
error (
"ELIST2_ITERATOR::add_after_stay_put", ABORT,
nullptr);
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);
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;
368 new_element->
next = next;
369 next->
prev = new_element;
372 new_element->
prev = current;
373 current->
next = new_element;
376 if (current == list->last)
377 list->last = new_element;
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;
402 NO_LIST.
error (
"ELIST2_ITERATOR::add_before_then_move", ABORT,
nullptr);
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);
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;
417 prev->
next = new_element;
418 new_element->
prev = prev;
421 new_element->
next = current;
422 current->
prev = new_element;
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;
434 current = new_element;
448 NO_LIST.
error (
"ELIST2_ITERATOR::add_before_stay_put", ABORT,
nullptr);
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);
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;
465 prev->
next = new_element;
466 new_element->
prev = prev;
469 new_element->
next = current;
470 current->
prev = new_element;
475 new_element->
next = next;
476 next->
prev = new_element;
477 if (ex_current_was_last)
478 list->last = new_element;
495 NO_LIST.
error (
"ELIST2_ITERATOR::add_list_after", ABORT,
nullptr);
497 BAD_PARAMETER.
error (
"ELIST2_ITERATOR::add_list_after", ABORT,
498 "list_to_add is nullptr");
501 if (!list_to_add->
empty ()) {
502 if (list->empty ()) {
503 list->last = list_to_add->
last;
505 next = list->First ();
506 ex_current_was_last =
true;
513 if (current == list->last)
514 list->last = list_to_add->
last;
517 next = current->
next;
522 if (ex_current_was_last) {
523 list->last = list_to_add->
last;
524 ex_current_was_last =
false;
531 list_to_add->
last =
nullptr;
546 NO_LIST.
error (
"ELIST2_ITERATOR::add_list_before", ABORT,
nullptr);
548 BAD_PARAMETER.
error (
"ELIST2_ITERATOR::add_list_before", ABORT,
549 "list_to_add is nullptr");
552 if (!list_to_add->
empty ()) {
553 if (list->empty ()) {
554 list->last = list_to_add->
last;
556 current = list->First ();
557 next = current->
next;
558 ex_current_was_last =
false;
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;
576 current = prev->
next;
577 next = current->
next;
579 list_to_add->
last =
nullptr;
597 NO_LIST.
error (
"ELIST2_ITERATOR::extract", ABORT,
nullptr);
600 NULL_CURRENT.
error (
"ELIST2_ITERATOR::extract",
604 if (list->singleton()) {
606 prev = next = list->last =
nullptr;
611 if (current == list->last) {
613 ex_current_was_last =
true;
615 ex_current_was_last =
false;
619 ex_current_was_cycle_pt = (current == cycle_pt);
620 extracted_link = current;
621 extracted_link->
next =
nullptr;
622 extracted_link->
prev =
nullptr;
624 return extracted_link;
637 NO_LIST.
error (
"ELIST2_ITERATOR::move_to_first", ABORT,
nullptr);
640 current = list->First ();
642 next = current ? current->next :
nullptr;
656 NO_LIST.
error (
"ELIST2_ITERATOR::move_to_last", ABORT,
nullptr);
659 current = list->last;
660 prev = current ? current->prev :
nullptr;
661 next = current ? current->next :
nullptr;
679 NO_LIST.
error (
"ELIST2_ITERATOR::mark_cycle_pt", ABORT,
nullptr);
685 ex_current_was_cycle_pt = TRUE;
686 started_cycling = FALSE;
699 NO_LIST.
error (
"ELIST2_ITERATOR::at_first", ABORT,
nullptr);
703 return ((list->empty ()) || (current == list->First ()) || ((current ==
nullptr) &&
704 (prev == list->last) &&
705 !ex_current_was_last));
718 NO_LIST.
error (
"ELIST2_ITERATOR::at_last", ABORT,
nullptr);
722 return ((list->empty ()) || (current == list->last) || ((current ==
nullptr) &&
723 (prev == list->last) &&
724 ex_current_was_last));
737 NO_LIST.
error (
"ELIST2_ITERATOR::cycled_list", ABORT,
nullptr);
740 return ((list->empty ()) || ((current == cycle_pt) && started_cycling));
754 NO_LIST.
error (
"ELIST2_ITERATOR::length", ABORT,
nullptr);
757 return list->length ();
770 const void *,
const void *)) {
773 NO_LIST.
error (
"ELIST2_ITERATOR::sort", ABORT,
nullptr);
776 list->sort (comparator);
794 NO_LIST.
error (
"ELIST2_ITERATOR::add_to_end", ABORT,
nullptr);
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);
802 if (this->at_last ()) {
803 this->add_after_stay_put (new_element);
806 if (this->at_first ()) {
807 this->add_before_stay_put (new_element);
808 list->last = new_element;
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;
827 #define QUOTE_IT(parm) #parm 860 #define ELIST2IZEH_A(CLASSNAME) \ 862 extern DLLSYM void CLASSNAME##_zapper( \ 865 #define ELIST2IZEH_B(CLASSNAME) \ 876 class DLLSYM CLASSNAME##_LIST : public ELIST2 { \ 878 CLASSNAME##_LIST() : ELIST2() {} \ 882 const CLASSNAME##_LIST &) \ 884 DONT_CONSTRUCT_LIST_BY_COPY.error(QUOTE_IT(CLASSNAME##_LIST), ABORT, \ 890 ELIST2::internal_clear(&CLASSNAME##_zapper); \ 893 ~CLASSNAME##_LIST() \ 899 void deep_copy(const CLASSNAME##_LIST *src_list, \ 900 CLASSNAME *(*copier)(const CLASSNAME *)); \ 903 const CLASSNAME##_LIST &) { \ 904 DONT_ASSIGN_LISTS.error(QUOTE_IT(CLASSNAME##_LIST), ABORT, nullptr); \ 907 #define ELIST2IZEH_C(CLASSNAME) \ 922 class DLLSYM CLASSNAME##_IT : public ELIST2_ITERATOR { \ 924 CLASSNAME##_IT(CLASSNAME##_LIST *list) : ELIST2_ITERATOR(list) {} \ 926 CLASSNAME *data() { return (CLASSNAME *)ELIST2_ITERATOR::data(); } \ 928 CLASSNAME *data_relative(int8_t offset) { \ 929 return (CLASSNAME *)ELIST2_ITERATOR::data_relative(offset); \ 932 CLASSNAME *forward() { return (CLASSNAME *)ELIST2_ITERATOR::forward(); } \ 934 CLASSNAME *backward() { return (CLASSNAME *)ELIST2_ITERATOR::backward(); } \ 936 CLASSNAME *extract() { return (CLASSNAME *)ELIST2_ITERATOR::extract(); } \ 938 CLASSNAME *move_to_first() { \ 939 return (CLASSNAME *)ELIST2_ITERATOR::move_to_first(); \ 942 CLASSNAME *move_to_last() { \ 943 return (CLASSNAME *)ELIST2_ITERATOR::move_to_last(); \ 949 #define ELIST2IZEH(CLASSNAME) \ 951 ELIST2IZEH_A(CLASSNAME) \ 953 ELIST2IZEH_B(CLASSNAME) \ 955 ELIST2IZEH_C(CLASSNAME) 961 #define ELIST2IZE(CLASSNAME) \ 972 DLLSYM void CLASSNAME##_zapper( \ 975 delete (CLASSNAME *)link; \ 979 void CLASSNAME##_LIST::deep_copy(const CLASSNAME##_LIST *src_list, \ 980 CLASSNAME *(*copier)(const CLASSNAME *)) { \ 981 CLASSNAME##_IT from_it(const_cast<CLASSNAME##_LIST *>(src_list)); \ 982 CLASSNAME##_IT to_it(this); \ 984 for (from_it.mark_cycle_pt(); !from_it.cycled_list(); from_it.forward()) \ 985 to_it.add_after_then_move((*copier)(from_it.data())); \ ELIST2_LINK * extract()
Definition: elst2.h:592
void mark_cycle_pt()
Definition: elst2.h:676
void assign_to_sublist(ELIST2_ITERATOR *start_it, ELIST2_ITERATOR *end_it)
Definition: elst2.cpp:73
void operator=(const ELIST2_LINK &)
Definition: elst2.h:76
ELIST2_LINK * cycle_pt
Definition: elst2.h:163
ELIST2_LINK * next
Definition: elst2.h:158
ELIST2_LINK * move_to_first()
Definition: elst2.h:634
ELIST2_LINK * current
Definition: elst2.h:157
ELIST2_LINK(const ELIST2_LINK &)
Definition: elst2.h:71
void add_to_end(ELIST2_LINK *new_link)
Definition: elst2.h:790
bool empty() const
Definition: elst2.h:107
ELIST2_LINK()
Definition: elst2.h:67
void add_after_then_move(ELIST2_LINK *new_link)
Definition: elst2.h:299
ELIST2_LINK * last
Definition: elst2.h:92
void add_list_before(ELIST2 *list_to_add)
Definition: elst2.h:543
bool at_last()
Definition: elst2.h:715
bool singleton() const
Definition: elst2.h:111
ELIST2_LINK * prev
Definition: elst2.h:156
ELIST2()
Definition: elst2.h:99
void shallow_copy(ELIST2 *from_list)
Definition: elst2.h:115
ELIST2 * list
Definition: elst2.h:155
void add_after_stay_put(ELIST2_LINK *new_link)
Definition: elst2.h:347
void add_before_then_move(ELIST2_LINK *new_link)
Definition: elst2.h:398
bool at_first()
Definition: elst2.h:696
void add_list_after(ELIST2 *list_to_add)
Definition: elst2.h:492
void set_to_list(ELIST2 *list_to_iterate)
Definition: elst2.h:264
void add_before_stay_put(ELIST2_LINK *new_link)
Definition: elst2.h:444
bool cycled_list()
Definition: elst2.h:734
bool ex_current_was_cycle_pt
Definition: elst2.h:161
ELIST2_LINK * next
Definition: elst2.h:64
bool ex_current_was_last
Definition: elst2.h:159
bool started_cycling
Definition: elst2.h:165
int32_t length()
Definition: elst2.h:751
ELIST2_LINK * First()
Definition: elst2.h:94
bool empty()
Definition: elst2.h:222
ELIST2_LINK * move_to_last()
Definition: elst2.h:653
ELIST2_LINK * prev
Definition: elst2.h:63
void error(const char *caller, TessErrorLogCode action, const char *format,...) const
Definition: errcode.cpp:37
ELIST2_LINK * data()
Definition: elst2.h:196
bool current_extracted()
Definition: elst2.h:230
void sort(int comparator(const void *, const void *))
Definition: elst2.h:768