"Fossies" - the Fresh Open Source Software Archive

Member "tesseract-ocr/doc/html/class_c_l_i_s_t___i_t_e_r_a_t_o_r.html" (26 Oct 2012, 107552 Bytes) of package /linux/misc/old/tesseract-ocr-3.02.02-doc-html.tar.gz:


Caution: In this restricted "Fossies" environment the current HTML page may not be correctly presentated and may have some non-functional links. You can here alternatively try to browse the pure source code or just view or download the uninterpreted raw source code. If the rendering is insufficient you may try to find and view the page on the tesseract-ocr-3.02.02-doc-html.tar.gz project site itself.

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

#include <clst.h>

List of all members.

Public Member Functions

 CLIST_ITERATOR ()
 CLIST_ITERATOR (CLIST *list_to_iterate)
void set_to_list (CLIST *list_to_iterate)
void add_after_then_move (void *new_data)
void add_after_stay_put (void *new_data)
void add_before_then_move (void *new_data)
void add_before_stay_put (void *new_data)
void add_list_after (CLIST *list_to_add)
void add_list_before (CLIST *list_to_add)
void * data ()
void * data_relative (inT8 offset)
void * forward ()
void * extract ()
void * move_to_first ()
void * move_to_last ()
void mark_cycle_pt ()
BOOL8 empty ()
BOOL8 current_extracted ()
BOOL8 at_first ()
BOOL8 at_last ()
BOOL8 cycled_list ()
void add_to_end (void *new_data)
void exchange (CLIST_ITERATOR *other_it)
inT32 length ()
void sort (int comparator(const void *, const void *))

Friends

void CLIST::assign_to_sublist (CLIST_ITERATOR *, CLIST_ITERATOR *)

Detailed Description

Definition at line 144 of file clst.h.


Constructor & Destructor Documentation

CLIST_ITERATOR::CLIST_ITERATOR ( )
inline

Definition at line 165 of file clst.h.

{ //constructor
list = NULL;
} //unassigned list
CLIST_ITERATOR::CLIST_ITERATOR ( CLIST list_to_iterate)
inline

Definition at line 282 of file clst.h.

{
set_to_list(list_to_iterate);
}

Member Function Documentation

void CLIST_ITERATOR::add_after_stay_put ( void *  new_data)
inline

Definition at line 344 of file clst.h.

{
CLIST_LINK *new_element;
#ifndef NDEBUG
if (!this)
NULL_OBJECT.error ("CLIST_ITERATOR::add_after_stay_put", ABORT, NULL);
if (!list)
NO_LIST.error ("CLIST_ITERATOR::add_after_stay_put", ABORT, NULL);
if (!new_data)
BAD_PARAMETER.error ("CLIST_ITERATOR::add_after_stay_put", ABORT,
"new_data is NULL");
#endif
new_element = new CLIST_LINK;
new_element->data = new_data;
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 CLIST_ITERATOR::add_after_then_move ( void *  new_data)
inline

Definition at line 294 of file clst.h.

{
CLIST_LINK *new_element;
#ifndef NDEBUG
if (!this)
NULL_OBJECT.error ("CLIST_ITERATOR::add_after_then_move", ABORT, NULL);
if (!list)
NO_LIST.error ("CLIST_ITERATOR::add_after_then_move", ABORT, NULL);
if (!new_data)
BAD_PARAMETER.error ("CLIST_ITERATOR::add_after_then_move", ABORT,
"new_data is NULL");
#endif
new_element = new CLIST_LINK;
new_element->data = new_data;
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 CLIST_ITERATOR::add_before_stay_put ( void *  new_data)
inline

Definition at line 444 of file clst.h.

{
CLIST_LINK *new_element;
#ifndef NDEBUG
if (!this)
NULL_OBJECT.error ("CLIST_ITERATOR::add_before_stay_put", ABORT, NULL);
if (!list)
NO_LIST.error ("CLIST_ITERATOR::add_before_stay_put", ABORT, NULL);
if (!new_data)
BAD_PARAMETER.error ("CLIST_ITERATOR::add_before_stay_put", ABORT,
"new_data is NULL");
#endif
new_element = new CLIST_LINK;
new_element->data = new_data;
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 CLIST_ITERATOR::add_before_then_move ( void *  new_data)
inline

Definition at line 397 of file clst.h.

{
CLIST_LINK *new_element;
#ifndef NDEBUG
if (!this)
NULL_OBJECT.error ("CLIST_ITERATOR::add_before_then_move", ABORT, NULL);
if (!list)
NO_LIST.error ("CLIST_ITERATOR::add_before_then_move", ABORT, NULL);
if (!new_data)
BAD_PARAMETER.error ("CLIST_ITERATOR::add_before_then_move", ABORT,
"new_data is NULL");
#endif
new_element = new CLIST_LINK;
new_element->data = new_data;
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 CLIST_ITERATOR::add_list_after ( CLIST list_to_add)
inline

Definition at line 492 of file clst.h.

{
#ifndef NDEBUG
if (!this)
NULL_OBJECT.error ("CLIST_ITERATOR::add_list_after", ABORT, NULL);
if (!list)
NO_LIST.error ("CLIST_ITERATOR::add_list_after", ABORT, NULL);
if (!list_to_add)
BAD_PARAMETER.error ("CLIST_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 CLIST_ITERATOR::add_list_before ( CLIST list_to_add)
inline

Definition at line 542 of file clst.h.

{
#ifndef NDEBUG
if (!this)
NULL_OBJECT.error ("CLIST_ITERATOR::add_list_before", ABORT, NULL);
if (!list)
NO_LIST.error ("CLIST_ITERATOR::add_list_before", ABORT, NULL);
if (!list_to_add)
BAD_PARAMETER.error ("CLIST_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 CLIST_ITERATOR::add_to_end ( void *  new_data)
inline

Definition at line 791 of file clst.h.

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

Definition at line 682 of file clst.h.

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

Definition at line 704 of file clst.h.

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

Definition at line 224 of file clst.h.

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

Definition at line 726 of file clst.h.

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

Definition at line 193 of file clst.h.

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

Definition at line 316 of file clst.cpp.

{ //offset from current
CLIST_LINK *ptr;
#ifndef NDEBUG
if (!this)
NULL_OBJECT.error ("CLIST_ITERATOR::data_relative", ABORT, NULL);
if (!list)
NO_LIST.error ("CLIST_ITERATOR::data_relative", ABORT, NULL);
if (list->empty ())
EMPTY_LIST.error ("CLIST_ITERATOR::data_relative", ABORT, NULL);
if (offset < -1)
BAD_PARAMETER.error ("CLIST_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 ("CLIST_ITERATOR::data_relative", ABORT, NULL);
#endif
return ptr->data;
}
BOOL8 CLIST_ITERATOR::empty ( )
inline

Definition at line 216 of file clst.h.

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

Definition at line 382 of file clst.cpp.

{ //other iterator
const ERRCODE DONT_EXCHANGE_DELETED =
"Can't exchange deleted elements of lists";
CLIST_LINK *old_current;
#ifndef NDEBUG
if (!this)
NULL_OBJECT.error ("CLIST_ITERATOR::exchange", ABORT, NULL);
if (!list)
NO_LIST.error ("CLIST_ITERATOR::exchange", ABORT, NULL);
if (!other_it)
BAD_PARAMETER.error ("CLIST_ITERATOR::exchange", ABORT, "other_it NULL");
if (!(other_it->list))
NO_LIST.error ("CLIST_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 ("CLIST_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;
}
void * CLIST_ITERATOR::extract ( )
inline

Definition at line 590 of file clst.h.

{
void *extracted_data;
#ifndef NDEBUG
if (!this)
NULL_OBJECT.error ("CLIST_ITERATOR::extract", ABORT, NULL);
if (!list)
NO_LIST.error ("CLIST_ITERATOR::extract", ABORT, NULL);
if (!current) //list empty or
//element extracted
NULL_CURRENT.error ("CLIST_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_data = current->data;
delete(current); //destroy CONS cell
current = NULL;
return extracted_data;
}
void * CLIST_ITERATOR::forward ( )

Definition at line 274 of file clst.cpp.

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

Definition at line 746 of file clst.h.

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

Definition at line 659 of file clst.h.

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

Definition at line 633 of file clst.h.

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

Definition at line 354 of file clst.cpp.

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

Definition at line 255 of file clst.h.

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

Definition at line 766 of file clst.h.

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

Friends And Related Function Documentation


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