00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 namespace Gecode { namespace Support {
00039
00052 template<class T>
00053 class SentinelStack {
00054 private:
00055 const T sentinel;
00056 T* tos;
00057 public:
00059 SentinelStack(T* p, T s);
00061 bool empty(void) const;
00063 T top(void) const;
00065 T last(void) const;
00067 T pop(void);
00069 void push(T x);
00070 };
00071
00072 template<class T>
00073 forceinline
00074 SentinelStack<T>::SentinelStack(T* p, T s)
00075 : sentinel(s), tos(p) {
00076 *(tos++) = sentinel;
00077 }
00078 template<class T>
00079 forceinline bool
00080 SentinelStack<T>::empty(void) const {
00081 return *(tos-1) == sentinel;
00082 }
00083 template<class T>
00084 forceinline T
00085 SentinelStack<T>::top(void) const {
00086 return *(tos-1);
00087 }
00088 template<class T>
00089 forceinline T
00090 SentinelStack<T>::last(void) const {
00091 return *tos;
00092 }
00093 template<class T>
00094 forceinline T
00095 SentinelStack<T>::pop(void) {
00096 return *(--tos);
00097 }
00098 template<class T>
00099 forceinline void
00100 SentinelStack<T>::push(T x) {
00101 assert(x != sentinel);
00102 *(tos++) = x;
00103 }
00104
00105 }}
00106
00118 #define GECODE_AUTOSTACK(T,S,X,N) \
00119 GECODE_AUTOARRAY(T,__GECODE__AS__ ## X ## __LINE__,(N)+1); \
00120 Gecode::Support::SentinelStack<T> X(__GECODE__AS__ ## X ## __LINE__,(S));
00121
00122