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

#include <elst.h>

Public Member Functions

 ELIST ()
 
void internal_clear (void(*zapper)(ELIST_LINK *))
 
bool empty () const
 
bool singleton () const
 
void shallow_copy (ELIST *from_list)
 
void internal_deep_copy (ELIST_LINK *(*copier)(ELIST_LINK *), const ELIST *list)
 
void assign_to_sublist (ELIST_ITERATOR *start_it, ELIST_ITERATOR *end_it)
 
inT32 length () const
 
void sort (int comparator(const void *, const void *))
 
ELIST_LINKadd_sorted_and_find (int comparator(const void *, const void *), bool unique, ELIST_LINK *new_link)
 
bool add_sorted (int comparator(const void *, const void *), bool unique, ELIST_LINK *new_link)
 

Friends

class ELIST_ITERATOR
 

Detailed Description

Definition at line 114 of file elst.h.

Constructor & Destructor Documentation

ELIST::ELIST ( )
inline

Definition at line 125 of file elst.h.

125  { //constructor
126  last = NULL;
127  }
#define NULL
Definition: host.h:144
LIST last(LIST var_list)
Definition: oldlist.cpp:277

Member Function Documentation

bool ELIST::add_sorted ( int   comparatorconst void *, const void *,
bool  unique,
ELIST_LINK new_link 
)
inline

Definition at line 175 of file elst.h.

176  {
177  return (add_sorted_and_find(comparator, unique, new_link) == new_link);
178  }
ELIST_LINK * add_sorted_and_find(int comparator(const void *, const void *), bool unique, ELIST_LINK *new_link)
Definition: elst.cpp:173
ELIST_LINK * ELIST::add_sorted_and_find ( int   comparatorconst void *, const void *,
bool  unique,
ELIST_LINK new_link 
)

Definition at line 173 of file elst.cpp.

175  {
176  // Check for adding at the end.
177  if (last == NULL || comparator(&last, &new_link) < 0) {
178  if (last == NULL) {
179  new_link->next = new_link;
180  } else {
181  new_link->next = last->next;
182  last->next = new_link;
183  }
184  last = new_link;
185  } else {
186  // Need to use an iterator.
187  ELIST_ITERATOR it(this);
188  for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
189  ELIST_LINK* link = it.data();
190  int compare = comparator(&link, &new_link);
191  if (compare > 0) {
192  break;
193  } else if (unique && compare == 0) {
194  return link;
195  }
196  }
197  if (it.cycled_list())
198  it.add_to_end(new_link);
199  else
200  it.add_before_then_move(new_link);
201  }
202  return new_link;
203 }
#define NULL
Definition: host.h:144
LIST last(LIST var_list)
Definition: oldlist.cpp:277
struct list_rec * next
Definition: oldlist.h:130
void ELIST::assign_to_sublist ( ELIST_ITERATOR start_it,
ELIST_ITERATOR end_it 
)

Definition at line 78 of file elst.cpp.

80  { //from list end
81  const ERRCODE LIST_NOT_EMPTY =
82  "Destination list must be empty before extracting a sublist";
83 
84  #ifndef NDEBUG
85  if (!this)
86  NULL_OBJECT.error ("ELIST::assign_to_sublist", ABORT, NULL);
87  #endif
88 
89  if (!empty ())
90  LIST_NOT_EMPTY.error ("ELIST.assign_to_sublist", ABORT, NULL);
91 
92  last = start_it->extract_sublist (end_it);
93 }
bool empty() const
Definition: elst.h:133
Definition: errcode.h:30
#define NULL
Definition: host.h:144
const ERRCODE NULL_OBJECT
Definition: lsterr.h:33
LIST last(LIST var_list)
Definition: oldlist.cpp:277
void error(const char *caller, TessErrorLogCode action, const char *format,...) const
Definition: errcode.cpp:41
bool ELIST::empty ( ) const
inline

Definition at line 133 of file elst.h.

133  { //is list empty?
134  return !last;
135  }
LIST last(LIST var_list)
Definition: oldlist.cpp:277
void ELIST::internal_clear ( void(*)(ELIST_LINK *)  zapper)

Definition at line 42 of file elst.cpp.

43  {
44  //ptr to zapper functn
45  ELIST_LINK *ptr;
46  ELIST_LINK *next;
47 
48  #ifndef NDEBUG
49  if (!this)
50  NULL_OBJECT.error ("ELIST::internal_clear", ABORT, NULL);
51  #endif
52 
53  if (!empty ()) {
54  ptr = last->next; //set to first
55  last->next = NULL; //break circle
56  last = NULL; //set list empty
57  while (ptr) {
58  next = ptr->next;
59  zapper(ptr);
60  ptr = next;
61  }
62  }
63 }
bool empty() const
Definition: elst.h:133
Definition: errcode.h:30
#define NULL
Definition: host.h:144
const ERRCODE NULL_OBJECT
Definition: lsterr.h:33
LIST last(LIST var_list)
Definition: oldlist.cpp:277
void error(const char *caller, TessErrorLogCode action, const char *format,...) const
Definition: errcode.cpp:41
struct list_rec * next
Definition: oldlist.h:130
void ELIST::internal_deep_copy ( ELIST_LINK *(*)(ELIST_LINK *)  copier,
const ELIST list 
)
inT32 ELIST::length ( ) const

Definition at line 102 of file elst.cpp.

102  { // count elements
103  ELIST_ITERATOR it(const_cast<ELIST*>(this));
104  inT32 count = 0;
105 
106  #ifndef NDEBUG
107  if (!this)
108  NULL_OBJECT.error ("ELIST::length", ABORT, NULL);
109  #endif
110 
111  for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ())
112  count++;
113  return count;
114 }
Definition: errcode.h:30
#define NULL
Definition: host.h:144
int inT32
Definition: host.h:102
const ERRCODE NULL_OBJECT
Definition: lsterr.h:33
void error(const char *caller, TessErrorLogCode action, const char *format,...) const
Definition: errcode.cpp:41
int count(LIST var_list)
Definition: oldlist.cpp:108
void ELIST::shallow_copy ( ELIST from_list)
inline

Definition at line 141 of file elst.h.

142  { //beware destructors!!
143  last = from_list->last;
144  }
LIST last(LIST var_list)
Definition: oldlist.cpp:277
bool ELIST::singleton ( ) const
inline

Definition at line 137 of file elst.h.

137  {
138  return last ? (last == last->next) : false;
139  }
LIST last(LIST var_list)
Definition: oldlist.cpp:277
struct list_rec * next
Definition: oldlist.h:130
void ELIST::sort ( int   comparatorconst void *, const void *)

Definition at line 126 of file elst.cpp.

128  {
129  ELIST_ITERATOR it(this);
130  inT32 count;
131  ELIST_LINK **base; //ptr array to sort
132  ELIST_LINK **current;
133  inT32 i;
134 
135  #ifndef NDEBUG
136  if (!this)
137  NULL_OBJECT.error ("ELIST::sort", ABORT, NULL);
138  #endif
139 
140  /* Allocate an array of pointers, one per list element */
141  count = length ();
142  base = (ELIST_LINK **) malloc (count * sizeof (ELIST_LINK *));
143 
144  /* Extract all elements, putting the pointers in the array */
145  current = base;
146  for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) {
147  *current = it.extract ();
148  current++;
149  }
150 
151  /* Sort the pointer array */
152  qsort ((char *) base, count, sizeof (*base), comparator);
153 
154  /* Rebuild the list from the sorted pointers */
155  current = base;
156  for (i = 0; i < count; i++) {
157  it.add_to_end (*current);
158  current++;
159  }
160  free(base);
161 }
void * base[2]
Definition: tessarray.h:53
Definition: errcode.h:30
#define NULL
Definition: host.h:144
int inT32
Definition: host.h:102
const ERRCODE NULL_OBJECT
Definition: lsterr.h:33
inT32 length() const
Definition: elst.cpp:102
void error(const char *caller, TessErrorLogCode action, const char *format,...) const
Definition: errcode.cpp:41
int count(LIST var_list)
Definition: oldlist.cpp:108

Friends And Related Function Documentation

friend class ELIST_ITERATOR
friend

Definition at line 116 of file elst.h.


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