50#include "EST_common.h"
52#include "EST_TSortable.h"
53#include "EST_TIterator.h"
55#include "instantiate/EST_TListI.h"
61template<
class T>
class EST_TItem :
public EST_UItem {
63 static void *
operator new(
size_t not_used,
void *place)
64 {(void)not_used;
return place;}
65 static void *
operator new(
size_t size)
67 p = (
void *)walloc(
char,size);
69 static void operator delete(
void *p)
72 static EST_TItem *s_free;
73 static unsigned int s_nfree;
74 static unsigned int s_maxFree;
77 static EST_TItem *make(
const T &val);
78 static void release(EST_TItem<T> *it);
85 EST_TItem(
const T &v) : val(v)
113 void init() { EST_UList::init(); };
122 ~ EST_TList() { clear_and_free(free_item); }
136 const T &
item(
const EST_Litem *p)
const
140 {
return item(nth_pointer(n)); };
143 {
return item(nth_pointer(n)); };
147 {
return item(head()); };
150 {
return item(tail()); };
155 {
return item(head()); };
158 {
return item(tail()); };
162 {
return item(ptr); };
165 {
return item(ptr); };
176 {
return EST_UList::remove(ptr, free_item); };
180 {
return EST_UList::remove(n, free_item); };
192 { EST_UList::append(EST_TItem<T>::make(
item)); };
195 { EST_UList::prepend(EST_TItem<T>::make(
item)); };
201 {
return EST_UList::insert_after(ptr, EST_TItem<T>::make(
item)); };
207 {
return EST_UList::insert_before(ptr, EST_TItem<T>::make(
item)); };
215 { EST_UList::exchange(a, b); };
218 { EST_UList::exchange(i,j); };
233 for (ptr = list.head(); ptr != 0; ptr = ptr->next())
234 st << list.
item(ptr) <<
" ";
240 { clear_and_free(free_item); };
248 void point_to_first(
IPointer &ip)
const { ip.p = head(); }
249 void move_pointer_forwards(
IPointer &ip)
const { ip.p = ip.p->next(); }
250 bool points_to_something(
const IPointer &ip)
const {
return ip.p != NULL; }
258 typedef EST_TIterator< EST_TList<T>,
IPointer, T > Entries;
259 typedef EST_TRwIterator< EST_TList<T>,
IPointer, T > RwEntries;
267 return EST_UList::operator_eq(a, b, EST_TSortable<T>::items_eq);
280 return EST_UList::index(l, item, eq?eq:EST_TSortable<T>::items_eq);
286 EST_UList::sort(a, gt?gt:EST_TSortable<T>::items_gt);
292 EST_UList::sort(a, EST_TSortable<T *>::items_gt);
310 EST_UList::sort_unique(l,
311 EST_TSortable<T>::items_eq,
312 EST_TSortable<T>::items_gt,
313 EST_TList<T>::free_item);
319 EST_UList::merge_sort_unique(l, m,
320 EST_TSortable<T>::items_eq,
321 EST_TSortable<T>::items_gt,
322 EST_TList<T>::free_item);
326const char *error_name(
EST_TList<T> val) { (void)val;
return "<<TLIST>>"; }
void exchange(EST_Litem *a, EST_Litem *b)
exchange 1
EST_Litem * remove_nth(int n)
remove nth item, return pointer to previous item
const T & last() const
return const reference to last item in list
T & item(const EST_Litem *p)
friend ostream & operator<<(ostream &st, EST_TList< T > const &list)
print list
T & nth(int n)
return the Nth value
EST_TList< T > & operator=(const EST_TList< T > &a)
make full copy of list
void clear(void)
remove all items in list
void append(const T &item)
add item onto end of list
T & last()
return reference to last item in list
EST_TList()
default constructor
EST_Litem * remove(EST_Litem *ptr)
static void exchange_contents(EST_Litem *a, EST_Litem *b)
exchange 3
EST_TList(const EST_TList< T > &l)
copy constructor
EST_TList< T > & operator+=(const EST_TList< T > &a)
Add list onto end of existing list.
EST_Litem * insert_after(EST_Litem *ptr, const T &item)
EST_Litem * insert_before(EST_Litem *ptr, const T &item)
void exchange(int i, int j)
exchange 2
const T & item(const EST_Litem *p) const
const T & operator()(const EST_Litem *ptr) const
return const reference to item in list pointed to by {\tt ptr}
const T & first() const
return const reference to first item in list
void prepend(const T &item)
add item onto start of list
const T & nth(int n) const
return a const Nth value