Generated on Sat Feb 7 2015 02:01:31 for Gecode by doxygen 1.8.9.1
static-stack.hpp
Go to the documentation of this file.
1 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2 /*
3  * Main authors:
4  * Christian Schulte <schulte@gecode.org>
5  *
6  * Copyright:
7  * Christian Schulte, 2002
8  *
9  * Last modified:
10  * $Date: 2009-09-08 21:10:29 +0200 (Tue, 08 Sep 2009) $ by $Author: schulte $
11  * $Revision: 9692 $
12  *
13  * This file is part of Gecode, the generic constraint
14  * development environment:
15  * http://www.gecode.org
16  *
17  * Permission is hereby granted, free of charge, to any person obtaining
18  * a copy of this software and associated documentation files (the
19  * "Software"), to deal in the Software without restriction, including
20  * without limitation the rights to use, copy, modify, merge, publish,
21  * distribute, sublicense, and/or sell copies of the Software, and to
22  * permit persons to whom the Software is furnished to do so, subject to
23  * the following conditions:
24  *
25  * The above copyright notice and this permission notice shall be
26  * included in all copies or substantial portions of the Software.
27  *
28  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
32  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
33  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
34  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35  *
36  */
37 
38 namespace Gecode { namespace Support {
39 
45  template<class T, class A>
46  class StaticStack {
47  private:
49  A& a;
51  int n;
53  unsigned int tos;
55  T* stack;
56  public:
58  StaticStack(A& a, int n);
60  ~StaticStack(void);
61 
63  void reset(void);
65  bool empty(void) const;
67  int entries(void) const;
68 
70  T pop(void);
72  T& top(void) const;
74  T& last(void) const;
76  void push(const T& x);
77 
78  private:
80  static void* operator new(size_t s) throw() { (void) s; return NULL; }
82  static void operator delete(void* p) { (void) p; };
84  StaticStack(const StaticStack& s) : a(s.a) {}
86  const StaticStack& operator =(const StaticStack&) { return *this; }
87  };
88 
89  template<class T, class A>
92  : a(a0), n(n0), tos(0), stack(a.template alloc<T>(n)) {}
93 
94  template<class T, class A>
97  a.free(stack,n);
98  }
99 
100  template<class T, class A>
101  forceinline bool
103  return tos==0;
104  }
105 
106  template<class T, class A>
107  forceinline int
109  return tos;
110  }
111 
112  template<class T, class A>
113  forceinline void
115  tos = 0;
116  }
117 
118  template<class T, class A>
119  forceinline T
121  assert((tos > 0) && (tos <= static_cast<unsigned int>(n)));
122  return stack[--tos];
123  }
124 
125  template<class T, class A>
126  forceinline T&
127  StaticStack<T,A>::top(void) const {
128  assert((tos > 0) && (tos <= static_cast<unsigned int>(n)));
129  return stack[tos-1];
130  }
131 
132  template<class T, class A>
133  forceinline T&
135  assert((tos >= 0) && (tos < static_cast<unsigned int>(n)));
136  return stack[tos];
137  }
138 
139  template<class T, class A>
140  forceinline void
142  assert(tos < static_cast<unsigned int>(n));
143  stack[tos++] = x;
144  }
145 
146 }}
147 
148 // STATISTICS: support-any
void push(const T &x)
Push element x on top of stack.
T & top(void) const
Return element on top of stack.
int entries(void) const
Return number of entries currently on stack.
T & last(void) const
Return element that has just been popped.
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:236
bool empty(void) const
Test whether stack is empty.
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:238
StaticStack(A &a, int n)
Initialize for n elements.
void reset(void)
Reset stack (pop all elements)
~StaticStack(void)
Release memory.
Node * x
Pointer to corresponding Boolean expression node.
Definition: bool-expr.cpp:253
#define forceinline
Definition: config.hpp:132
Stack with fixed number of elements.
T pop(void)
Pop topmost element from stack and return it.
Gecode toplevel namespace
struct Gecode::@518::NNF::@57::@59 a
For atomic nodes.