2 # ifndef TPL_ARRAYSTACK_H
3 # define TPL_ARRAYSTACK_H
7 # include <tpl_memArray.H>
11 using namespace Aleph;
84 T &
push(
const T & data)
throw(std::exception, std::overflow_error)
86 return array.put(data);
89 T & push(T && data) throw(std::exception, std::overflow_error)
91 return array.put(std::move(data));
106 T &
pushn(
const size_t & n = 1) throw(std::exception, std::overflow_error)
119 T
pop() throw(std::exception, std::underflow_error)
134 T
popn(
const int & n)
throw(std::exception, std::underflow_error)
140 T &
top() throw(std::exception,std::underflow_error)
147 return array.first();
150 const T & top()
const throw(std::exception,std::underflow_error)
167 T &
top(
const int & i)
throw(std::exception, std::underflow_error)
169 return array.access(array.size() - i - 1);
172 const T & top(
const int & i)
const throw(std::exception, std::underflow_error)
174 return array.access(array.size() - i - 1);
181 bool is_empty()
const {
return array.size() == 0; }
184 const size_t &
size()
const {
return array.size(); }
186 const size_t & capacity()
const {
return array.capacity(); }
188 template <
class Operation>
189 bool traverse(Operation & operation)
191 return array.traverse(operation);
194 template <
class Operation>
195 bool traverse(Operation & operation)
const
197 return array.traverse(operation);
200 template <
class Operation>
201 bool traverse(Operation && operation = Operation())
const
203 return array.traverse(operation);
206 template <
class Operation>
207 bool traverse(Operation && operation = Operation())
209 return array.traverse(operation);
212 Functional_Methods(T);
242 template <
typename T>
253 : array(new T [d]), head(0), dim(d) { }
262 : array(new T [s.dim]), head(s.head), dim(s.dim)
264 for (
int i = 0; i < head; ++i)
265 array[i] = s.array[i];
270 std::swap(array, s.array);
271 std::swap(head, s.head);
272 std::swap(dim, s.dim);
276 : array(NULL), head(0), dim(0)
286 T * ptr =
new T [s.dim];
290 for (
size_t i = 0; i < s.head; ++i)
291 array[i] = s.array[i];
316 array[head++] = data;
317 return array[head - 1];
324 std::swap(array[head++], data);
325 return array[head - 1];
344 return array[head - 1];
357 return std::move(array[--head]);
371 I((
int (head - n)) >= 0);
374 return std::move(array[head]);
382 return array[head - 1];
389 return array[head - 1];
392 T & base() {
return array[0]; }
409 return array[head - i - 1];
419 const size_t &
size()
const {
return head; }
421 template <
class Operation>
422 bool traverse(Operation & operation)
424 for (
int i = 0; i < head; i++)
425 if (not operation(array[i]))
431 template <
class Operation>
432 bool traverse(Operation & operation)
const
434 return const_cast<FixedStack*
>(
this)->traverse(operation);
437 template <
class Operation>
438 bool traverse(Operation && operation = Operation())
const
440 return traverse<Operation>(operation);
443 template <
class Operation>
444 bool traverse(Operation && operation = Operation())
446 return traverse<Operation>(operation);
449 Functional_Methods(T);
Definition: tpl_memArray.H:17
bool is_empty() const
Retorna true si la pila está vacía.
Definition: tpl_arrayStack.H:413
T & top(const int &i)
Definition: tpl_arrayStack.H:404
T pop()
Definition: tpl_arrayStack.H:353
void empty()
Vacía todos los elementos de la pila.
Definition: tpl_arrayStack.H:178
T & top()
retorna una referencia al elemento situado en el tope de la pila.
Definition: tpl_arrayStack.H:140
T & top(const int &i)
Definition: tpl_arrayStack.H:167
Definition: tpl_arrayStack.H:42
T & push(const T &data)
Definition: tpl_arrayStack.H:312
const size_t & size() const
Retorna el número de elementos que contiene la pila.
Definition: tpl_arrayStack.H:184
const size_t & size() const
Retorna el número de elementos que contiene la pila.
Definition: tpl_arrayStack.H:419
T popn(const int &n)
Definition: tpl_arrayStack.H:369
T & push(const T &data)
Definition: tpl_arrayStack.H:84
T & pushn(const size_t &n=1)
Definition: tpl_arrayStack.H:339
Definition: tpl_arrayStack.H:243
T pop()
Definition: tpl_arrayStack.H:119
FixedStack(size_t d=512)
Constructor.
Definition: tpl_arrayStack.H:252
T & pushn(const size_t &n=1)
Definition: tpl_arrayStack.H:106
T popn(const int &n)
Definition: tpl_arrayStack.H:134
T & top()
retorna una referencia al elemento situado en el tope de la pila.
Definition: tpl_arrayStack.H:378
bool is_empty() const
Retorna true si la pila está vacía.
Definition: tpl_arrayStack.H:181
void empty()
Vacía todos los elementos de la pila.
Definition: tpl_arrayStack.H:416