All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules 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

Member Function Documentation

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

Definition at line 168 of file elst2.cpp.

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

Definition at line 78 of file elst2.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 ("ELIST2::assign_to_sublist", ABORT, NULL);
87  #endif
88 
89  if (!empty ())
90  LIST_NOT_EMPTY.error ("ELIST2.assign_to_sublist", ABORT, NULL);
91 
92  last = start_it->extract_sublist (end_it);
93 }
bool empty() const
Definition: elst2.h:107
Definition: errcode.h:30
void error(const char *caller, TessErrorLogCode action, const char *format,...) const
Definition: errcode.cpp:40
#define NULL
Definition: host.h:144
const ERRCODE NULL_OBJECT
Definition: lsterr.h:33
bool ELIST2::empty ( ) const
inline

Definition at line 107 of file elst2.h.

107  { //is list empty?
108  return !last;
109  }
void ELIST2::internal_clear ( void(*)(ELIST2_LINK *)  zapper)

Definition at line 42 of file elst2.cpp.

43  {
44  //ptr to zapper functn
45  ELIST2_LINK *ptr;
46  ELIST2_LINK *next;
47 
48  #ifndef NDEBUG
49  if (!this)
50  NULL_OBJECT.error ("ELIST2::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: elst2.h:107
Definition: errcode.h:30
void error(const char *caller, TessErrorLogCode action, const char *format,...) const
Definition: errcode.cpp:40
#define NULL
Definition: host.h:144
const ERRCODE NULL_OBJECT
Definition: lsterr.h:33
void ELIST2::internal_deep_copy ( ELIST2_LINK *(*)(ELIST2_LINK *)  copier,
const ELIST2 list 
)
inT32 ELIST2::length ( ) const

Definition at line 102 of file elst2.cpp.

102  { // count elements
103  ELIST2_ITERATOR it(const_cast<ELIST2*>(this));
104  inT32 count = 0;
105 
106  #ifndef NDEBUG
107  if (!this)
108  NULL_OBJECT.error ("ELIST2::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
void error(const char *caller, TessErrorLogCode action, const char *format,...) const
Definition: errcode.cpp:40
int count(LIST var_list)
Definition: oldlist.cpp:108
#define NULL
Definition: host.h:144
const ERRCODE NULL_OBJECT
Definition: lsterr.h:33
int inT32
Definition: host.h:102
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  }
bool ELIST2::singleton ( ) const
inline

Definition at line 111 of file elst2.h.

111  {
112  return last ? (last == last->next) : false;
113  }
void ELIST2::sort ( int   comparatorconst void *, const void *)

Definition at line 126 of file elst2.cpp.

128  {
129  ELIST2_ITERATOR it(this);
130  inT32 count;
131  ELIST2_LINK **base; //ptr array to sort
132  ELIST2_LINK **current;
133  inT32 i;
134 
135  #ifndef NDEBUG
136  if (!this)
137  NULL_OBJECT.error ("ELIST2::sort", ABORT, NULL);
138  #endif
139 
140  /* Allocate an array of pointers, one per list element */
141  count = length ();
142  base = (ELIST2_LINK **) malloc (count * sizeof (ELIST2_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 }
Definition: errcode.h:30
void error(const char *caller, TessErrorLogCode action, const char *format,...) const
Definition: errcode.cpp:40
int count(LIST var_list)
Definition: oldlist.cpp:108
inT32 length() const
Definition: elst2.cpp:102
#define NULL
Definition: host.h:144
const ERRCODE NULL_OBJECT
Definition: lsterr.h:33
int inT32
Definition: host.h:102

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: