Edinburgh Speech Tools  2.1-release
EST_UList.h
Go to the documentation of this file.
1  /************************************************************************/
2  /* */
3  /* Centre for Speech Technology Research */
4  /* University of Edinburgh, UK */
5  /* Copyright (c) 1996,1997 */
6  /* All Rights Reserved. */
7  /* */
8  /* Permission is hereby granted, free of charge, to use and distribute */
9  /* this software and its documentation without restriction, including */
10  /* without limitation the rights to use, copy, modify, merge, publish, */
11  /* distribute, sublicense, and/or sell copies of this work, and to */
12  /* permit persons to whom this work is furnished to do so, subject to */
13  /* the following conditions: */
14  /* 1. The code must retain the above copyright notice, this list of */
15  /* conditions and the following disclaimer. */
16  /* 2. Any modifications must be clearly marked as such. */
17  /* 3. Original authors' names are not deleted. */
18  /* 4. The authors' names are not used to endorse or promote products */
19  /* derived from this software without specific prior written */
20  /* permission. */
21  /* */
22  /* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
23  /* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
24  /* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
25  /* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
26  /* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
27  /* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
28  /* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
29  /* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
30  /* THIS SOFTWARE. */
31  /* */
32  /*************************************************************************/
33  /* */
34  /* Author: Richard Caley (rjc@cstr.ed.ac.uk) */
35  /* Date: Mon Jul 21 1997 */
36  /* -------------------------------------------------------------------- */
37  /* Untyped list used as the basis of the TList class */
38  /* */
39  /*************************************************************************/
40 
41 #ifndef __EST_ULIST_H__
42 #define __EST_ULIST_H__
43 
44 #include <iostream>
45 
46 #include "EST_common.h"
47 #include "EST_String.h"
48 
49 class EST_UItem {
50 public:
51  void init() { n = NULL; p = NULL;}
52  virtual ~ EST_UItem() {;}
55  EST_UItem *next() { return n; }
56  EST_UItem *prev() { return p; }
57 };
58 
59 class EST_UList {
60 protected:
63 
64 protected:
65  void init() { h = NULL; t = NULL; };
66  void clear_and_free(void (*item_free)(EST_UItem *item));
67 
68 public:
69  EST_UList() { init(); };
70  virtual ~ EST_UList() { clear_and_free(NULL); }
71 
72  EST_UItem *nth_pointer(int n) const;
73 
74  EST_UItem *insert_after(EST_UItem *ptr, EST_UItem *new_item); // returns pointer to inserted item
75  EST_UItem *insert_before(EST_UItem *ptr, EST_UItem *new_item); // returns pointer to item after inserted item
76 
77  // remove single item, return pointer to previous
78  EST_UItem *remove(EST_UItem *ptr, void (*item_free)(EST_UItem *item));
79  EST_UItem *remove(int n, void (*item_free)(EST_UItem *item));
80 
81  void exchange(EST_UItem *a, EST_UItem *b);
82  void exchange(int i, int j);
83 
84  void reverse(); // in place
85 
86  int length() const; // number of items in list
87  int index(EST_UItem *item) const; // position from start of list (head = 0)
88 
89  int empty() const // returns true if no items in list
90  {return (h == NULL) ? 1 : 0;};
91  void clear(void)
92  { clear_and_free(NULL); };
93  void append(EST_UItem *item); // add item onto end of list
94 
95  void prepend(EST_UItem *item); // add item onto start of list
96 
97  EST_UItem *head() const // return pointer to head of list
98  { return h; };
99  EST_UItem *tail() const // return pointer to tail of list
100  { return t; };
101 
102 
103  static bool operator_eq(const EST_UList &a,
104  const EST_UList &b,
105  bool (*eq)(const EST_UItem *item1, const EST_UItem *item2));
106 
107  static int index(const EST_UList &l,
108  const EST_UItem &b,
109  bool (*eq)(const EST_UItem *item1, const EST_UItem *item2));
110 
111  static void sort(EST_UList &a,
112  bool (*gt)(const EST_UItem *item1, const EST_UItem *item2));
113  static void qsort(EST_UList &a,
114  bool (*gt)(const EST_UItem *item1, const EST_UItem *item2),
115  void (*exchange)(EST_UItem *item1, EST_UItem *item2));
116  static void sort_unique(EST_UList &l,
117  bool (*eq)(const EST_UItem *item1, const EST_UItem *item2),
118  bool (*gt)(const EST_UItem *item1, const EST_UItem *item2),
119  void (*item_free)(EST_UItem *item));
120  static void merge_sort_unique(EST_UList &l, EST_UList &m,
121  bool (*eq)(const EST_UItem *item1, const EST_UItem *item2),
122  bool (*gt)(const EST_UItem *item1, const EST_UItem *item2),
123  void (*item_free)(EST_UItem *item));
124 };
125 
126 
127 // inline functions in header file
128 // everything else in EST_UList.C
129 
130 
131 /* Please don't use these - use the member functions instead!
132 inline EST_UItem *next(EST_UItem *ptr)
133 {
134  if (ptr != 0)
135  return ptr->n;
136  return 0;
137 }
138 
139 inline EST_UItem *prev(EST_UItem *ptr)
140 {
141  if (ptr != 0)
142  return ptr->p;
143  return 0;
144 }
145 */
146 
147 
148 #endif
void qsort(EST_TList< T > &a)
void sort_unique(EST_TList< T > &l)
Definition: EST_TList.h:317
EST_UItem * prev()
Definition: EST_UList.h:56
void init()
Definition: EST_UList.h:51
STATIC STATUS exchange()
Definition: editline.c:1742
virtual ~EST_UItem()
Definition: EST_UList.h:52
LISP append(LISP l1, LISP l2)
Definition: slib_list.cc:177
int index(EST_TList< T > &l, T &val, bool(*eq)(const EST_UItem *, const EST_UItem *)=NULL)
Definition: EST_TList.h:286
EST_UItem * h
Definition: EST_UList.h:61
EST_UItem * next()
Definition: EST_UList.h:55
void clear(void)
Definition: EST_UList.h:91
EST_UItem * n
Definition: EST_UList.h:53
EST_UItem * p
Definition: EST_UList.h:54
NULL
Definition: EST_WFST.cc:55
void merge_sort_unique(EST_TList< T > &l, EST_TList< T > &m)
Definition: EST_TList.h:326
EST_UItem * tail() const
Definition: EST_UList.h:99
void sort(EST_TList< T > &a)
void init()
Definition: EST_UList.h:65
EST_UItem * t
Definition: EST_UList.h:62
EST_UList()
Definition: EST_UList.h:69
EST_UItem * head() const
Definition: EST_UList.h:97
void reverse(EST_Wave &sig)
int empty() const
Definition: EST_UList.h:89