Tesseract 3.02

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- Class List
- Class Hierarchy
- Class Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Friends
CLIST Class Reference

`#include <clst.h>`

List of all members.

## Public Member Functions

| CLIST ()
| ~CLIST ()
void | internal_deep_clear (void(*zapper)(void *))
void | shallow_clear ()
bool | empty () const
bool | singleton () const
void | shallow_copy (CLIST *from_list)
void | assign_to_sublist (CLIST_ITERATOR *start_it, CLIST_ITERATOR *end_it)
inT32 | length () const
void | sort (int comparator(const void *, const void *))
bool | add_sorted (int comparator(const void *, const void *), bool unique, void *new_data)
void | set_subtract (int comparator(const void *, const void *), bool unique, CLIST *minuend, CLIST *subtrahend)

## Friends

class | CLIST_ITERATOR

## Detailed Description

Definition at line 70 of file clst.h.

## Constructor & Destructor Documentation

CLIST::CLIST | ( |  | ) |

inline

Definition at line 81 of file clst.h.

{ //constructor
last = NULL;
}

CLIST::~CLIST | ( |  | ) |

inline

Definition at line 85 of file clst.h.

{ //destructor
shallow_clear();
}

## Member Function Documentation

bool CLIST::add_sorted | ( | int | comparatorconst void *, const void *,
|  | bool | unique,
|  | void * | new_data
| ) |  |

Definition at line 199 of file clst.cpp.

{
// Check for adding at the end.
if (last == NULL || comparator(&last->data, &new_data) < 0) {
CLIST_LINK* new_element = new CLIST_LINK;
new_element->data = new_data;
if (last == NULL) {
new_element->next = new_element;
} else {
new_element->next = last->next;
last->next = new_element;
}
last = new_element;
return true;
} else if (!unique || last->data != new_data) {
// Need to use an iterator.
CLIST_ITERATOR it(this);
for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
void* data = it.data();
if (data == new_data && unique)
return false;
if (comparator(&data, &new_data) > 0)
break;
}
if (it.cycled_list())
it.add_to_end(new_data);
else
it.add_before_then_move(new_data);
return true;
}
return false;
}

void CLIST::assign_to_sublist | ( | CLIST_ITERATOR * | start_it,
|  | CLIST_ITERATOR * | end_it
| ) |  |

Definition at line 109 of file clst.cpp.

{ //from list end
const ERRCODE LIST_NOT_EMPTY =
"Destination list must be empty before extracting a sublist";
#ifndef NDEBUG
if (!this)
NULL_OBJECT.error ("CLIST::assign_to_sublist", ABORT, NULL);
#endif
if (!empty ())
LIST_NOT_EMPTY.error ("CLIST.assign_to_sublist", ABORT, NULL);
last = start_it->extract_sublist (end_it);
}

bool CLIST::empty | ( |  | ) | const

inline

Definition at line 95 of file clst.h.

{ //is list empty?
return !last;
}

void CLIST::internal_deep_clear | ( | void(*)(void *) | zapper | ) |

Definition at line 42 of file clst.cpp.

{ //ptr to zapper functn
CLIST_LINK *ptr;
CLIST_LINK *next;
#ifndef NDEBUG
if (!this)
NULL_OBJECT.error ("CLIST::internal_deep_clear", ABORT, NULL);
#endif
if (!empty ()) {
ptr = last->next; //set to first
last->next = NULL; //break circle
last = NULL; //set list empty
while (ptr) {
next = ptr->next;
zapper (ptr->data);
delete(ptr);
ptr = next;
}
}
}

inT32 CLIST::length | ( |  | ) | const

Definition at line 133 of file clst.cpp.

{ //count elements
CLIST_ITERATOR it(const_cast<CLIST*>(this));
inT32 count = 0;
#ifndef NDEBUG
if (!this)
NULL_OBJECT.error ("CLIST::length", ABORT, NULL);
#endif
for (it.mark_cycle_pt(); !it.cycled_list(); it.forward())
count++;
return count;
}

void CLIST::set_subtract | ( | int | comparatorconst void *, const void *,
|  | bool | unique,
|  | CLIST * | minuend,
|  | CLIST * | subtrahend
| ) |  |

Definition at line 237 of file clst.cpp.

{
shallow_clear();
CLIST_ITERATOR m_it(minuend);
CLIST_ITERATOR s_it(subtrahend);
// Since both lists are sorted, finding the subtras that are not
// minus is a case of a parallel iteration.
for (m_it.mark_cycle_pt(); !m_it.cycled_list(); m_it.forward()) {
void* minu = m_it.data();
void* subtra = NULL;
if (!s_it.empty()) {
subtra = s_it.data();
while (!s_it.at_last() &&
comparator(&subtra, &minu) < 0) {
s_it.forward();
subtra = s_it.data();
}
}
if (subtra == NULL || comparator(&subtra, &minu) != 0)
add_sorted(comparator, unique, minu);
}
}

void CLIST::shallow_clear | ( |  | ) |

Definition at line 75 of file clst.cpp.

{ //destroy all links
CLIST_LINK *ptr;
CLIST_LINK *next;
#ifndef NDEBUG
if (!this)
NULL_OBJECT.error ("CLIST::shallow_clear", ABORT, NULL);
#endif
if (!empty ()) {
ptr = last->next; //set to first
last->next = NULL; //break circle
last = NULL; //set list empty
while (ptr) {
next = ptr->next;
delete(ptr);
ptr = next;
}
}
}

void CLIST::shallow_copy | ( | CLIST * | from_list | ) |

inline

Definition at line 103 of file clst.h.

{ //beware destructors!!
last = from_list->last;
}

bool CLIST::singleton | ( |  | ) | const

inline

Definition at line 99 of file clst.h.

{
return last != NULL ? (last == last->next) : false;
}

void CLIST::sort | ( | int | comparatorconst void *, const void * | ) |

Definition at line 155 of file clst.cpp.

{
CLIST_ITERATOR it(this);
inT32 count;
void **base; //ptr array to sort
void **current;
inT32 i;
#ifndef NDEBUG
if (!this)
NULL_OBJECT.error ("CLIST::sort", ABORT, NULL);
#endif
/* Allocate an array of pointers, one per list element */
count = length ();
base = (void **) malloc (count * sizeof (void *));
/* Extract all elements, putting the pointers in the array */
current = base;
for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) {
*current = it.extract ();
current++;
}
/* Sort the pointer array */
qsort ((char *) base, count, sizeof (*base), comparator);
/* Rebuild the list from the sorted pointers */
current = base;
for (i = 0; i < count; i++) {
it.add_to_end (*current);
current++;
}
free(base);
}

## Friends And Related Function Documentation

friend class CLIST_ITERATOR

friend

Definition at line 72 of file clst.h.

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

- /mnt/data/src/tesseract-ocr/ccutil/clst.h
- /mnt/data/src/tesseract-ocr/ccutil/clst.cpp