Tesseract  3.02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ELIST2_ITERATOR Class Reference

#include <elst2.h>

List of all members.

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.

{ //constructor
list = NULL;
} //unassigned list
ELIST2_ITERATOR::ELIST2_ITERATOR ( ELIST2 list_to_iterate)
inline

Definition at line 291 of file elst2.h.

{
set_to_list(list_to_iterate);
}

Member Function Documentation

void ELIST2_ITERATOR::add_after_stay_put ( ELIST2_LINK new_link)
inline

Definition at line 354 of file elst2.h.

{
#ifndef NDEBUG
if (!this)
NULL_OBJECT.error ("ELIST2_ITERATOR::add_after_stay_put", ABORT, NULL);
if (!list)
NO_LIST.error ("ELIST2_ITERATOR::add_after_stay_put", ABORT, NULL);
if (!new_element)
BAD_PARAMETER.error ("ELIST2_ITERATOR::add_after_stay_put", ABORT,
"new_element is NULL");
if (new_element->next)
STILL_LINKED.error ("ELIST2_ITERATOR::add_after_stay_put", ABORT, NULL);
#endif
if (list->empty ()) {
new_element->next = new_element;
new_element->prev = new_element;
list->last = new_element;
prev = next = new_element;
ex_current_was_last = FALSE;
current = NULL;
}
else {
new_element->next = next;
next->prev = new_element;
if (current) { //not extracted
new_element->prev = current;
current->next = new_element;
if (prev == current)
prev = new_element;
if (current == list->last)
list->last = new_element;
}
else { //current extracted
new_element->prev = prev;
prev->next = new_element;
if (ex_current_was_last) {
list->last = new_element;
ex_current_was_last = FALSE;
}
}
next = new_element;
}
}
void ELIST2_ITERATOR::add_after_then_move ( ELIST2_LINK new_link)
inline

Definition at line 303 of file elst2.h.

{
#ifndef NDEBUG
if (!this)
NULL_OBJECT.error ("ELIST2_ITERATOR::add_after_then_move", ABORT, NULL);
if (!list)
NO_LIST.error ("ELIST2_ITERATOR::add_after_then_move", ABORT, NULL);
if (!new_element)
BAD_PARAMETER.error ("ELIST2_ITERATOR::add_after_then_move", ABORT,
"new_element is NULL");
if (new_element->next)
STILL_LINKED.error ("ELIST2_ITERATOR::add_after_then_move", ABORT, NULL);
#endif
if (list->empty ()) {
new_element->next = new_element;
new_element->prev = new_element;
list->last = new_element;
prev = next = new_element;
}
else {
new_element->next = next;
next->prev = new_element;
if (current) { //not extracted
new_element->prev = current;
current->next = new_element;
prev = current;
if (current == list->last)
list->last = new_element;
}
else { //current extracted
new_element->prev = prev;
prev->next = new_element;
if (ex_current_was_last)
list->last = new_element;
if (ex_current_was_cycle_pt)
cycle_pt = new_element;
}
}
current = new_element;
}
void ELIST2_ITERATOR::add_before_stay_put ( ELIST2_LINK new_link)
inline

Definition at line 457 of file elst2.h.

{
#ifndef NDEBUG
if (!this)
NULL_OBJECT.error ("ELIST2_ITERATOR::add_before_stay_put", ABORT, NULL);
if (!list)
NO_LIST.error ("ELIST2_ITERATOR::add_before_stay_put", ABORT, NULL);
if (!new_element)
BAD_PARAMETER.error ("ELIST2_ITERATOR::add_before_stay_put", ABORT,
"new_element is NULL");
if (new_element->next)
STILL_LINKED.error ("ELIST2_ITERATOR::add_before_stay_put", ABORT, NULL);
#endif
if (list->empty ()) {
new_element->next = new_element;
new_element->prev = new_element;
list->last = new_element;
prev = next = new_element;
ex_current_was_last = TRUE;
current = NULL;
}
else {
prev->next = new_element;
new_element->prev = prev;
if (current) { //not extracted
new_element->next = current;
current->prev = new_element;
if (next == current)
next = new_element;
}
else { //current extracted
new_element->next = next;
next->prev = new_element;
if (ex_current_was_last)
list->last = new_element;
}
prev = new_element;
}
}
void ELIST2_ITERATOR::add_before_then_move ( ELIST2_LINK new_link)
inline

Definition at line 408 of file elst2.h.

{
#ifndef NDEBUG
if (!this)
NULL_OBJECT.error ("ELIST2_ITERATOR::add_before_then_move", ABORT, NULL);
if (!list)
NO_LIST.error ("ELIST2_ITERATOR::add_before_then_move", ABORT, NULL);
if (!new_element)
BAD_PARAMETER.error ("ELIST2_ITERATOR::add_before_then_move", ABORT,
"new_element is NULL");
if (new_element->next)
STILL_LINKED.error ("ELIST2_ITERATOR::add_before_then_move", ABORT, NULL);
#endif
if (list->empty ()) {
new_element->next = new_element;
new_element->prev = new_element;
list->last = new_element;
prev = next = new_element;
}
else {
prev->next = new_element;
new_element->prev = prev;
if (current) { //not extracted
new_element->next = current;
current->prev = new_element;
next = current;
}
else { //current extracted
new_element->next = next;
next->prev = new_element;
if (ex_current_was_last)
list->last = new_element;
if (ex_current_was_cycle_pt)
cycle_pt = new_element;
}
}
current = new_element;
}
void ELIST2_ITERATOR::add_list_after ( ELIST2 list_to_add)
inline

Definition at line 507 of file elst2.h.

{
#ifndef NDEBUG
if (!this)
NULL_OBJECT.error ("ELIST2_ITERATOR::add_list_after", ABORT, NULL);
if (!list)
NO_LIST.error ("ELIST2_ITERATOR::add_list_after", ABORT, NULL);
if (!list_to_add)
BAD_PARAMETER.error ("ELIST2_ITERATOR::add_list_after", ABORT,
"list_to_add is NULL");
#endif
if (!list_to_add->empty ()) {
if (list->empty ()) {
list->last = list_to_add->last;
prev = list->last;
next = list->First ();
ex_current_was_last = TRUE;
current = NULL;
}
else {
if (current) { //not extracted
current->next = list_to_add->First ();
current->next->prev = current;
if (current == list->last)
list->last = list_to_add->last;
list_to_add->last->next = next;
next->prev = list_to_add->last;
next = current->next;
}
else { //current extracted
prev->next = list_to_add->First ();
prev->next->prev = prev;
if (ex_current_was_last) {
list->last = list_to_add->last;
ex_current_was_last = FALSE;
}
list_to_add->last->next = next;
next->prev = list_to_add->last;
next = prev->next;
}
}
list_to_add->last = NULL;
}
}
void ELIST2_ITERATOR::add_list_before ( ELIST2 list_to_add)
inline

Definition at line 561 of file elst2.h.

{
#ifndef NDEBUG
if (!this)
NULL_OBJECT.error ("ELIST2_ITERATOR::add_list_before", ABORT, NULL);
if (!list)
NO_LIST.error ("ELIST2_ITERATOR::add_list_before", ABORT, NULL);
if (!list_to_add)
BAD_PARAMETER.error ("ELIST2_ITERATOR::add_list_before", ABORT,
"list_to_add is NULL");
#endif
if (!list_to_add->empty ()) {
if (list->empty ()) {
list->last = list_to_add->last;
prev = list->last;
current = list->First ();
next = current->next;
ex_current_was_last = FALSE;
}
else {
prev->next = list_to_add->First ();
prev->next->prev = prev;
if (current) { //not extracted
list_to_add->last->next = current;
current->prev = list_to_add->last;
}
else { //current extracted
list_to_add->last->next = next;
next->prev = list_to_add->last;
if (ex_current_was_last)
list->last = list_to_add->last;
if (ex_current_was_cycle_pt)
cycle_pt = prev->next;
}
current = prev->next;
next = current->next;
}
list_to_add->last = NULL;
}
}
void ELIST2_ITERATOR::add_to_end ( ELIST2_LINK new_link)
inline

Definition at line 838 of file elst2.h.

{
#ifndef NDEBUG
if (!this)
NULL_OBJECT.error ("ELIST2_ITERATOR::add_to_end", ABORT, NULL);
if (!list)
NO_LIST.error ("ELIST2_ITERATOR::add_to_end", ABORT, NULL);
if (!new_element)
BAD_PARAMETER.error ("ELIST2_ITERATOR::add_to_end", ABORT,
"new_element is NULL");
if (new_element->next)
STILL_LINKED.error ("ELIST2_ITERATOR::add_to_end", ABORT, NULL);
#endif
if (this->at_last ()) {
this->add_after_stay_put (new_element);
}
else {
if (this->at_first ()) {
this->add_before_stay_put (new_element);
list->last = new_element;
}
else { //Iteratr is elsewhere
new_element->next = list->last->next;
new_element->prev = list->last;
list->last->next->prev = new_element;
list->last->next = new_element;
list->last = new_element;
}
}
}
BOOL8 ELIST2_ITERATOR::at_first ( )
inline

Definition at line 729 of file elst2.h.

{
#ifndef NDEBUG
if (!this)
NULL_OBJECT.error ("ELIST2_ITERATOR::at_first", ABORT, NULL);
if (!list)
NO_LIST.error ("ELIST2_ITERATOR::at_first", ABORT, NULL);
#endif
//we're at a deleted
return ((list->empty ()) || (current == list->First ()) || ((current == NULL) &&
(prev == list->last) && //NON-last pt between
!ex_current_was_last)); //first and last
}
BOOL8 ELIST2_ITERATOR::at_last ( )
inline

Definition at line 751 of file elst2.h.

{
#ifndef NDEBUG
if (!this)
NULL_OBJECT.error ("ELIST2_ITERATOR::at_last", ABORT, NULL);
if (!list)
NO_LIST.error ("ELIST2_ITERATOR::at_last", ABORT, NULL);
#endif
//we're at a deleted
return ((list->empty ()) || (current == list->last) || ((current == NULL) &&
(prev == list->last) && //last point between
ex_current_was_last)); //first and last
}
ELIST2_LINK * ELIST2_ITERATOR::backward ( )

Definition at line 252 of file elst2.cpp.

{
#ifndef NDEBUG
if (!this)
NULL_OBJECT.error ("ELIST2_ITERATOR::backward", ABORT, NULL);
if (!list)
NO_LIST.error ("ELIST2_ITERATOR::backward", ABORT, NULL);
#endif
if (list->empty ())
return NULL;
if (current) { //not removed so
//set previous
next = current;
started_cycling = TRUE;
// In case prev is deleted by another iterator, get it from current.
current = current->prev;
} else {
if (ex_current_was_cycle_pt)
cycle_pt = prev;
current = prev;
}
prev = current->prev;
#ifndef NDEBUG
if (!current)
NULL_DATA.error ("ELIST2_ITERATOR::backward", ABORT, NULL);
if (!prev)
NULL_PREV.error ("ELIST2_ITERATOR::backward", ABORT,
"This is: %p Current is: %p", this, current);
#endif
return current;
}
BOOL8 ELIST2_ITERATOR::current_extracted ( )
inline

Definition at line 233 of file elst2.h.

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

Definition at line 773 of file elst2.h.

{
#ifndef NDEBUG
if (!this)
NULL_OBJECT.error ("ELIST2_ITERATOR::cycled_list", ABORT, NULL);
if (!list)
NO_LIST.error ("ELIST2_ITERATOR::cycled_list", ABORT, NULL);
#endif
return ((list->empty ()) || ((current == cycle_pt) && started_cycling));
}
ELIST2_LINK* ELIST2_ITERATOR::data ( )
inline

Definition at line 199 of file elst2.h.

{ //get current data
#ifndef NDEBUG
if (!current)
NULL_DATA.error ("ELIST2_ITERATOR::data", ABORT, NULL);
if (!list)
NO_LIST.error ("ELIST2_ITERATOR::data", ABORT, NULL);
#endif
return current;
}
ELIST2_LINK * ELIST2_ITERATOR::data_relative ( inT8  offset)

Definition at line 293 of file elst2.cpp.

{ //offset from current
#ifndef NDEBUG
if (!this)
NULL_OBJECT.error ("ELIST2_ITERATOR::data_relative", ABORT, NULL);
if (!list)
NO_LIST.error ("ELIST2_ITERATOR::data_relative", ABORT, NULL);
if (list->empty ())
EMPTY_LIST.error ("ELIST2_ITERATOR::data_relative", ABORT, NULL);
#endif
if (offset < 0)
for (ptr = current ? current : next; offset++ < 0; ptr = ptr->prev);
else
for (ptr = current ? current : prev; offset-- > 0; ptr = ptr->next);
#ifndef NDEBUG
if (!ptr)
NULL_DATA.error ("ELIST2_ITERATOR::data_relative", ABORT, NULL);
#endif
return ptr;
}
BOOL8 ELIST2_ITERATOR::empty ( )
inline

Definition at line 225 of file elst2.h.

{ //is list empty?
#ifndef NDEBUG
if (!list)
NO_LIST.error ("ELIST2_ITERATOR::empty", ABORT, NULL);
#endif
return list->empty ();
}
void ELIST2_ITERATOR::exchange ( ELIST2_ITERATOR other_it)

Definition at line 330 of file elst2.cpp.

{ //other iterator
const ERRCODE DONT_EXCHANGE_DELETED =
"Can't exchange deleted elements of lists";
ELIST2_LINK *old_current;
#ifndef NDEBUG
if (!this)
NULL_OBJECT.error ("ELIST2_ITERATOR::exchange", ABORT, NULL);
if (!list)
NO_LIST.error ("ELIST2_ITERATOR::exchange", ABORT, NULL);
if (!other_it)
BAD_PARAMETER.error ("ELIST2_ITERATOR::exchange", ABORT, "other_it NULL");
if (!(other_it->list))
NO_LIST.error ("ELIST2_ITERATOR::exchange", ABORT, "other_it");
#endif
/* Do nothing if either list is empty or if both iterators reference the same
link */
if ((list->empty ()) ||
(other_it->list->empty ()) || (current == other_it->current))
return;
/* Error if either current element is deleted */
if (!current || !other_it->current)
DONT_EXCHANGE_DELETED.error ("ELIST2_ITERATOR.exchange", ABORT, NULL);
/* Now handle the 4 cases: doubleton list; non-doubleton adjacent elements
(other before this); non-doubleton adjacent elements (this before other);
non-adjacent elements. */
//adjacent links
if ((next == other_it->current) ||
(other_it->next == current)) {
//doubleton list
if ((next == other_it->current) &&
(other_it->next == current)) {
prev = next = current;
other_it->prev = other_it->next = other_it->current;
}
else { //non-doubleton with
//adjacent links
//other before this
if (other_it->next == current) {
other_it->prev->next = current;
other_it->current->next = next;
other_it->current->prev = current;
current->next = other_it->current;
current->prev = other_it->prev;
next->prev = other_it->current;
other_it->next = other_it->current;
prev = current;
}
else { //this before other
prev->next = other_it->current;
current->next = other_it->next;
current->prev = other_it->current;
other_it->current->next = current;
other_it->current->prev = prev;
other_it->next->prev = current;
next = current;
other_it->prev = other_it->current;
}
}
}
else { //no overlap
prev->next = other_it->current;
current->next = other_it->next;
current->prev = other_it->prev;
next->prev = other_it->current;
other_it->prev->next = current;
other_it->current->next = next;
other_it->current->prev = prev;
other_it->next->prev = current;
}
/* update end of list pointer when necessary (remember that the 2 iterators
may iterate over different lists!) */
if (list->last == current)
list->last = other_it->current;
if (other_it->list->last == other_it->current)
other_it->list->last = current;
if (current == cycle_pt)
cycle_pt = other_it->cycle_pt;
if (other_it->current == other_it->cycle_pt)
other_it->cycle_pt = cycle_pt;
/* The actual exchange - in all cases*/
old_current = current;
current = other_it->current;
other_it->current = old_current;
}
ELIST2_LINK * ELIST2_ITERATOR::extract ( )
inline

Definition at line 613 of file elst2.h.

{
ELIST2_LINK *extracted_link;
#ifndef NDEBUG
if (!this)
NULL_OBJECT.error ("ELIST2_ITERATOR::extract", ABORT, NULL);
if (!list)
NO_LIST.error ("ELIST2_ITERATOR::extract", ABORT, NULL);
if (!current) //list empty or
//element extracted
NULL_CURRENT.error ("ELIST2_ITERATOR::extract",
#endif
if (list->singleton()) {
// Special case where we do need to change the iterator.
prev = next = list->last = NULL;
} else {
prev->next = next; //remove from list
next->prev = prev;
if (current == list->last) {
list->last = prev;
ex_current_was_last = TRUE;
} else {
ex_current_was_last = FALSE;
}
}
// Always set ex_current_was_cycle_pt so an add/forward will work in a loop.
ex_current_was_cycle_pt = (current == cycle_pt) ? TRUE : FALSE;
extracted_link = current;
extracted_link->next = NULL; //for safety
extracted_link->prev = NULL; //for safety
current = NULL;
return extracted_link;
}
ELIST2_LINK * ELIST2_ITERATOR::forward ( )

Definition at line 210 of file elst2.cpp.

{
#ifndef NDEBUG
if (!this)
NULL_OBJECT.error ("ELIST2_ITERATOR::forward", ABORT, NULL);
if (!list)
NO_LIST.error ("ELIST2_ITERATOR::forward", ABORT, NULL);
#endif
if (list->empty ())
return NULL;
if (current) { //not removed so
//set previous
prev = current;
started_cycling = TRUE;
// In case next is deleted by another iterator, get it from the current.
current = current->next;
}
else {
if (ex_current_was_cycle_pt)
cycle_pt = next;
current = next;
}
next = current->next;
#ifndef NDEBUG
if (!current)
NULL_DATA.error ("ELIST2_ITERATOR::forward", ABORT, NULL);
if (!next)
NULL_NEXT.error ("ELIST2_ITERATOR::forward", ABORT,
"This is: %p Current is: %p", this, current);
#endif
return current;
}
inT32 ELIST2_ITERATOR::length ( )
inline

Definition at line 793 of file elst2.h.

{
#ifndef NDEBUG
if (!this)
NULL_OBJECT.error ("ELIST2_ITERATOR::length", ABORT, NULL);
if (!list)
NO_LIST.error ("ELIST2_ITERATOR::length", ABORT, NULL);
#endif
return list->length ();
}
void ELIST2_ITERATOR::mark_cycle_pt ( )
inline

Definition at line 706 of file elst2.h.

{
#ifndef NDEBUG
if (!this)
NULL_OBJECT.error ("ELIST2_ITERATOR::mark_cycle_pt", ABORT, NULL);
if (!list)
NO_LIST.error ("ELIST2_ITERATOR::mark_cycle_pt", ABORT, NULL);
#endif
if (current)
cycle_pt = current;
else
ex_current_was_cycle_pt = TRUE;
started_cycling = FALSE;
}
ELIST2_LINK * ELIST2_ITERATOR::move_to_first ( )
inline

Definition at line 658 of file elst2.h.

{
#ifndef NDEBUG
if (!this)
NULL_OBJECT.error ("ELIST2_ITERATOR::move_to_first", ABORT, NULL);
if (!list)
NO_LIST.error ("ELIST2_ITERATOR::move_to_first", ABORT, NULL);
#endif
current = list->First ();
prev = list->last;
next = current ? current->next : NULL;
return current;
}
ELIST2_LINK * ELIST2_ITERATOR::move_to_last ( )
inline

Definition at line 680 of file elst2.h.

{
#ifndef NDEBUG
if (!this)
NULL_OBJECT.error ("ELIST2_ITERATOR::move_to_last", ABORT, NULL);
if (!list)
NO_LIST.error ("ELIST2_ITERATOR::move_to_last", ABORT, NULL);
#endif
current = list->last;
prev = current ? current->prev : NULL;
next = current ? current->next : NULL;
return current;
}
void ELIST2_ITERATOR::set_to_list ( ELIST2 list_to_iterate)
inline

Definition at line 264 of file elst2.h.

{
#ifndef NDEBUG
if (!this)
NULL_OBJECT.error ("ELIST2_ITERATOR::set_to_list", ABORT, NULL);
if (!list_to_iterate)
BAD_PARAMETER.error ("ELIST2_ITERATOR::set_to_list", ABORT,
"list_to_iterate is NULL");
#endif
list = list_to_iterate;
prev = list->last;
current = list->First ();
next = current ? current->next : NULL;
cycle_pt = NULL; //await explicit set
started_cycling = FALSE;
ex_current_was_last = FALSE;
ex_current_was_cycle_pt = FALSE;
}
void ELIST2_ITERATOR::sort ( int   comparatorconst void *, const void *)
inline

Definition at line 813 of file elst2.h.

{
#ifndef NDEBUG
if (!this)
NULL_OBJECT.error ("ELIST2_ITERATOR::sort", ABORT, NULL);
if (!list)
NO_LIST.error ("ELIST2_ITERATOR::sort", ABORT, NULL);
#endif
list->sort (comparator);
}

Friends And Related Function Documentation


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