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

#include <elst.h>

List of all members.

Public Member Functions

 ELIST_ITERATOR ()
 ELIST_ITERATOR (ELIST *list_to_iterate)
void set_to_list (ELIST *list_to_iterate)
void add_after_then_move (ELIST_LINK *new_link)
void add_after_stay_put (ELIST_LINK *new_link)
void add_before_then_move (ELIST_LINK *new_link)
void add_before_stay_put (ELIST_LINK *new_link)
void add_list_after (ELIST *list_to_add)
void add_list_before (ELIST *list_to_add)
ELIST_LINKdata ()
ELIST_LINKdata_relative (inT8 offset)
ELIST_LINKforward ()
ELIST_LINKextract ()
ELIST_LINKmove_to_first ()
ELIST_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 (ELIST_LINK *new_link)
void exchange (ELIST_ITERATOR *other_it)
inT32 length ()
void sort (int comparator(const void *, const void *))

Friends

void ELIST::assign_to_sublist (ELIST_ITERATOR *, ELIST_ITERATOR *)

Detailed Description

Definition at line 188 of file elst.h.


Constructor & Destructor Documentation

ELIST_ITERATOR::ELIST_ITERATOR ( )
inline

Definition at line 209 of file elst.h.

{ //constructor
list = NULL;
} //unassigned list
ELIST_ITERATOR::ELIST_ITERATOR ( ELIST list_to_iterate)
inline

Definition at line 326 of file elst.h.

{
set_to_list(list_to_iterate);
}

Member Function Documentation

void ELIST_ITERATOR::add_after_stay_put ( ELIST_LINK new_link)
inline

Definition at line 385 of file elst.h.

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

Definition at line 338 of file elst.h.

{
#ifndef NDEBUG
if (!this)
NULL_OBJECT.error ("ELIST_ITERATOR::add_after_then_move", ABORT, NULL);
if (!list)
NO_LIST.error ("ELIST_ITERATOR::add_after_then_move", ABORT, NULL);
if (!new_element)
BAD_PARAMETER.error ("ELIST_ITERATOR::add_after_then_move", ABORT,
"new_element is NULL");
if (new_element->next)
STILL_LINKED.error ("ELIST_ITERATOR::add_after_then_move", ABORT, NULL);
#endif
if (list->empty ()) {
new_element->next = new_element;
list->last = new_element;
prev = next = new_element;
}
else {
new_element->next = next;
if (current) { //not extracted
current->next = new_element;
prev = current;
if (current == list->last)
list->last = new_element;
}
else { //current extracted
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 ELIST_ITERATOR::add_before_stay_put ( ELIST_LINK new_link)
inline

Definition at line 479 of file elst.h.

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

Definition at line 435 of file elst.h.

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

Definition at line 524 of file elst.h.

{
#ifndef NDEBUG
if (!this)
NULL_OBJECT.error ("ELIST_ITERATOR::add_list_after", ABORT, NULL);
if (!list)
NO_LIST.error ("ELIST_ITERATOR::add_list_after", ABORT, NULL);
if (!list_to_add)
BAD_PARAMETER.error ("ELIST_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 ();
if (current == list->last)
list->last = list_to_add->last;
list_to_add->last->next = next;
next = current->next;
}
else { //current extracted
prev->next = list_to_add->First ();
if (ex_current_was_last) {
list->last = list_to_add->last;
ex_current_was_last = FALSE;
}
list_to_add->last->next = next;
next = prev->next;
}
}
list_to_add->last = NULL;
}
}
void ELIST_ITERATOR::add_list_before ( ELIST list_to_add)
inline

Definition at line 574 of file elst.h.

{
#ifndef NDEBUG
if (!this)
NULL_OBJECT.error ("ELIST_ITERATOR::add_list_before", ABORT, NULL);
if (!list)
NO_LIST.error ("ELIST_ITERATOR::add_list_before", ABORT, NULL);
if (!list_to_add)
BAD_PARAMETER.error ("ELIST_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 ();
if (current) { //not extracted
list_to_add->last->next = current;
}
else { //current extracted
list_to_add->last->next = next;
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 ELIST_ITERATOR::add_to_end ( ELIST_LINK new_link)
inline

Definition at line 823 of file elst.h.

{
#ifndef NDEBUG
if (!this)
NULL_OBJECT.error ("ELIST_ITERATOR::add_to_end", ABORT, NULL);
if (!list)
NO_LIST.error ("ELIST_ITERATOR::add_to_end", ABORT, NULL);
if (!new_element)
BAD_PARAMETER.error ("ELIST_ITERATOR::add_to_end", ABORT,
"new_element is NULL");
if (new_element->next)
STILL_LINKED.error ("ELIST_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;
list->last->next = new_element;
list->last = new_element;
}
}
}
bool ELIST_ITERATOR::at_first ( )
inline

Definition at line 714 of file elst.h.

{
#ifndef NDEBUG
if (!this)
NULL_OBJECT.error ("ELIST_ITERATOR::at_first", ABORT, NULL);
if (!list)
NO_LIST.error ("ELIST_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
}
bool ELIST_ITERATOR::at_last ( )
inline

Definition at line 736 of file elst.h.

{
#ifndef NDEBUG
if (!this)
NULL_OBJECT.error ("ELIST_ITERATOR::at_last", ABORT, NULL);
if (!list)
NO_LIST.error ("ELIST_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
}
bool ELIST_ITERATOR::current_extracted ( )
inline

Definition at line 268 of file elst.h.

{ //current extracted?
return !current;
}
bool ELIST_ITERATOR::cycled_list ( )
inline

Definition at line 758 of file elst.h.

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

Definition at line 237 of file elst.h.

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

Definition at line 259 of file elst.cpp.

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

Definition at line 260 of file elst.h.

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

Definition at line 322 of file elst.cpp.

{ //other iterator
const ERRCODE DONT_EXCHANGE_DELETED =
"Can't exchange deleted elements of lists";
ELIST_LINK *old_current;
#ifndef NDEBUG
if (!this)
NULL_OBJECT.error ("ELIST_ITERATOR::exchange", ABORT, NULL);
if (!list)
NO_LIST.error ("ELIST_ITERATOR::exchange", ABORT, NULL);
if (!other_it)
BAD_PARAMETER.error ("ELIST_ITERATOR::exchange", ABORT, "other_it NULL");
if (!(other_it->list))
NO_LIST.error ("ELIST_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 ("ELIST_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;
current->next = 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;
other_it->current->next = current;
next = current;
other_it->prev = other_it->current;
}
}
}
else { //no overlap
prev->next = other_it->current;
current->next = other_it->next;
other_it->prev->next = current;
other_it->current->next = next;
}
/* 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;
}
ELIST_LINK * ELIST_ITERATOR::extract ( )
inline

Definition at line 622 of file elst.h.

{
ELIST_LINK *extracted_link;
#ifndef NDEBUG
if (!this)
NULL_OBJECT.error ("ELIST_ITERATOR::extract", ABORT, NULL);
if (!list)
NO_LIST.error ("ELIST_ITERATOR::extract", ABORT, NULL);
if (!current) //list empty or
//element extracted
NULL_CURRENT.error ("ELIST_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
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
current = NULL;
return extracted_link;
}
ELIST_LINK * ELIST_ITERATOR::forward ( )

Definition at line 217 of file elst.cpp.

{
#ifndef NDEBUG
if (!this)
NULL_OBJECT.error ("ELIST_ITERATOR::forward", ABORT, NULL);
if (!list)
NO_LIST.error ("ELIST_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 next from 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 ("ELIST_ITERATOR::forward", ABORT, NULL);
if (!next)
NULL_NEXT.error ("ELIST_ITERATOR::forward", ABORT,
"This is: %p Current is: %p", this, current);
#endif
return current;
}
inT32 ELIST_ITERATOR::length ( )
inline

Definition at line 778 of file elst.h.

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

Definition at line 691 of file elst.h.

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

Definition at line 665 of file elst.h.

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

Definition at line 297 of file elst.cpp.

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

Definition at line 299 of file elst.h.

{
#ifndef NDEBUG
if (!this)
NULL_OBJECT.error ("ELIST_ITERATOR::set_to_list", ABORT, NULL);
if (!list_to_iterate)
BAD_PARAMETER.error ("ELIST_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 ELIST_ITERATOR::sort ( int   comparatorconst void *, const void *)
inline

Definition at line 798 of file elst.h.

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

Friends And Related Function Documentation


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