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

#include <elst2.h>

Public Member Functions

 ELIST2 ()
 
void internal_clear (void(*zapper)(ELIST2_LINK *))
 
bool empty () const
 
bool singleton () const
 
void shallow_copy (ELIST2 *from_list)
 
void internal_deep_copy (ELIST2_LINK *(*copier)(ELIST2_LINK *), const ELIST2 *list)
 
void assign_to_sublist (ELIST2_ITERATOR *start_it, ELIST2_ITERATOR *end_it)
 
inT32 length () const
 
void sort (int comparator(const void *, const void *))
 
void add_sorted (int comparator(const void *, const void *), ELIST2_LINK *new_link)
 

Friends

class ELIST2_ITERATOR
 

Detailed Description

Definition at line 88 of file elst2.h.

Constructor & Destructor Documentation

ELIST2::ELIST2 ( )
inline

Definition at line 99 of file elst2.h.

99  { //constructor
100  last = NULL;
101  }
#define NULL
Definition: host.h:144
LIST last(LIST var_list)
Definition: oldlist.cpp:277

Member Function Documentation

void ELIST2::add_sorted ( int   comparatorconst void *, const void *,
ELIST2_LINK new_link 
)

Definition at line 169 of file elst2.cpp.

170  {
171  // Check for adding at the end.
172  if (last == NULL || comparator(&last, &new_link) < 0) {
173  if (last == NULL) {
174  new_link->next = new_link;
175  new_link->prev = new_link;
176  } else {
177  new_link->next = last->next;
178  new_link->prev = last;
179  last->next = new_link;
180  new_link->next->prev = new_link;
181  }
182  last = new_link;
183  } else {
184  // Need to use an iterator.
185  ELIST2_ITERATOR it(this);
186  for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
187  ELIST2_LINK* link = it.data();
188  if (comparator(&link, &new_link) > 0)
189  break;
190  }
191  if (it.cycled_list())
192  it.add_to_end(new_link);
193  else
194  it.add_before_then_move(new_link);
195  }
196 }
#define NULL
Definition: host.h:144
LIST last(LIST var_list)
Definition: oldlist.cpp:277
struct list_rec * next
Definition: oldlist.h:130
void ELIST2::assign_to_sublist ( ELIST2_ITERATOR start_it,
ELIST2_ITERATOR end_it 
)

Definition at line 79 of file elst2.cpp.

81  { //from list end
82  const ERRCODE LIST_NOT_EMPTY =
83  "Destination list must be empty before extracting a sublist";
84 
85  #ifndef NDEBUG
86  if (!this)
87  NULL_OBJECT.error ("ELIST2::assign_to_sublist", ABORT, NULL);
88  #endif
89 
90  if (!empty ())
91  LIST_NOT_EMPTY.error ("ELIST2.assign_to_sublist", ABORT, NULL);
92 
93  last = start_it->extract_sublist (end_it);
94 }
Definition: errcode.h:30
#define NULL
Definition: host.h:144
const ERRCODE NULL_OBJECT
Definition: lsterr.h:33
bool empty() const
Definition: elst2.h:107
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 ELIST2::empty ( ) const
inline

Definition at line 107 of file elst2.h.

107  { //is list empty?
108  return !last;
109  }
LIST last(LIST var_list)
Definition: oldlist.cpp:277
void ELIST2::internal_clear ( void(*)(ELIST2_LINK *)  zapper)

Definition at line 43 of file elst2.cpp.

44  {
45  //ptr to zapper functn
46  ELIST2_LINK *ptr;
47  ELIST2_LINK *next;
48 
49  #ifndef NDEBUG
50  if (!this)
51  NULL_OBJECT.error ("ELIST2::internal_clear", ABORT, NULL);
52  #endif
53 
54  if (!empty ()) {
55  ptr = last->next; //set to first
56  last->next = NULL; //break circle
57  last = NULL; //set list empty
58  while (ptr) {
59  next = ptr->next;
60  zapper(ptr);
61  ptr = next;
62  }
63  }
64 }
Definition: errcode.h:30
#define NULL
Definition: host.h:144
const ERRCODE NULL_OBJECT
Definition: lsterr.h:33
bool empty() const
Definition: elst2.h:107
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 ELIST2::internal_deep_copy ( ELIST2_LINK *(*)(ELIST2_LINK *)  copier,
const ELIST2 list 
)
inT32 ELIST2::length ( ) const

Definition at line 103 of file elst2.cpp.

103  { // count elements
104  ELIST2_ITERATOR it(const_cast<ELIST2*>(this));
105  inT32 count = 0;
106 
107  #ifndef NDEBUG
108  if (!this)
109  NULL_OBJECT.error ("ELIST2::length", ABORT, NULL);
110  #endif
111 
112  for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ())
113  count++;
114  return count;
115 }
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 ELIST2::shallow_copy ( ELIST2 from_list)
inline

Definition at line 115 of file elst2.h.

116  { //beware destructors!!
117  last = from_list->last;
118  }
LIST last(LIST var_list)
Definition: oldlist.cpp:277
bool ELIST2::singleton ( ) const
inline

Definition at line 111 of file elst2.h.

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

Definition at line 127 of file elst2.cpp.

129  {
130  ELIST2_ITERATOR it(this);
131  inT32 count;
132  ELIST2_LINK **base; //ptr array to sort
133  ELIST2_LINK **current;
134  inT32 i;
135 
136  #ifndef NDEBUG
137  if (!this)
138  NULL_OBJECT.error ("ELIST2::sort", ABORT, NULL);
139  #endif
140 
141  /* Allocate an array of pointers, one per list element */
142  count = length ();
143  base = (ELIST2_LINK **) malloc (count * sizeof (ELIST2_LINK *));
144 
145  /* Extract all elements, putting the pointers in the array */
146  current = base;
147  for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) {
148  *current = it.extract ();
149  current++;
150  }
151 
152  /* Sort the pointer array */
153  qsort ((char *) base, count, sizeof (*base), comparator);
154 
155  /* Rebuild the list from the sorted pointers */
156  current = base;
157  for (i = 0; i < count; i++) {
158  it.add_to_end (*current);
159  current++;
160  }
161  free(base);
162 }
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
void error(const char *caller, TessErrorLogCode action, const char *format,...) const
Definition: errcode.cpp:41
inT32 length() const
Definition: elst2.cpp:103
int count(LIST var_list)
Definition: oldlist.cpp:108

Friends And Related Function Documentation

friend class ELIST2_ITERATOR
friend

Definition at line 90 of file elst2.h.


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