Edinburgh Speech Tools  2.1-release
EST_TDeque.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 
35 #ifndef __EST_TDEQUE_H__
36 #define __EST_TDEQUE_H__
37 
38 #include "EST_TVector.h"
40 
41 /** @class EST_TDeque
42  * @brief Double ended queue.
43  * @ingroup containerclasses
44  *
45  * @author Richard Caley <rjc@cstr.ed.ac.uk>
46  * @version $Id: EST_TDeque.h,v 1.3 2006/07/19 21:52:12 awb Exp $
47  */
48 template <class T>
49 class EST_TDeque {
50 private:
51  EST_TVector<T> p_vector;
52  int p_increment;
53  int p_back;
54  int p_front;
55 
56  // Make the structure bigger.
57  void expand(void);
58 
59 public:
60  EST_TDeque(unsigned int capacity, unsigned int increment);
61  EST_TDeque(unsigned int capacity);
62  EST_TDeque(void);
63 
64  /// Used to fill empty spaces when possible.
65  static const T *Filler;
66 
67  /// Empty it out.
68  void clear(void);
69 
70  /// Is there anything to get?
71  bool is_empty(void) const;
72 
73  /// print picture of state. Mostly useful for debugging.
74  std::ostream &print(std::ostream &s) const;
75 
76  /**@name stack
77  *
78  * An interface looking like a stack.
79  */
80  ///@{
81  void push(T &item);
82  T &pop(void);
83  T &nth(int i);
84  ///@}
85 
86  /**@name inverse stack
87  *
88  * The other end as a stack.
89  */
90  ///@{
91  void back_push(T& item);
92  T &back_pop(void);
93  ///@}
94 
95  /**@name queue
96  *
97  * An interface looking like a queue.
98  */
99  ///@{
100  void add(T& item) { push(item); }
101  T &next() { return back_pop(); }
102  T &last() { return pop(); }
103  ///@}
104 
105  /**@name perl
106  *
107  * For people who think in perl
108  */
109  ///@{
110  void unshift(T& item) { back_push(item); }
111  T &shift() { return back_pop(); }
112  ///@}
113 
114  friend std::ostream& operator << (std::ostream &st, const EST_TDeque< T > &deq)
115  {
116  return deq.print(st);
117  }
118 };
119 
120 #endif
121 
void back_push(T &item)
Definition: EST_TDeque.cc:204
void clear(void)
Empty it out.
Definition: EST_TDeque.cc:140
void unshift(T &item)
Definition: EST_TDeque.h:110
void add(T &item)
Definition: EST_TDeque.h:100
void push(T &item)
Definition: EST_TDeque.cc:148
T & last()
Definition: EST_TDeque.h:102
T & pop(void)
Definition: EST_TDeque.cc:167
bool is_empty(void) const
Is there anything to get?
Definition: EST_TDeque.cc:134
T & back_pop(void)
Definition: EST_TDeque.cc:223
Double ended queue.
Definition: EST_TDeque.h:49
T & nth(int i)
Definition: EST_TDeque.cc:180
std::ostream & print(std::ostream &s) const
print picture of state. Mostly useful for debugging.
Definition: EST_TDeque.cc:76
static const T * Filler
Used to fill empty spaces when possible.
Definition: EST_TDeque.h:65
T & shift()
Definition: EST_TDeque.h:111
Template vector.
Definition: EST_TVector.h:145
T & next()
Definition: EST_TDeque.h:101
EST_TDeque(void)
Definition: EST_TDeque.cc:66