finitestack.hh
Go to the documentation of this file.00001 #ifndef DUNE_FINITE_STACK_HH
00002 #define DUNE_FINITE_STACK_HH
00003
00004 #include <dune/common/exceptions.hh>
00005
00006 namespace Dune {
00007
00027 template<class T, int n>
00028 class FiniteStack {
00029 public :
00030
00032 bool empty () const
00033 {
00034 return f==0;
00035 }
00036
00038 bool full () const
00039 {
00040 return f>=n;
00041 }
00042
00044 void push (const T& t)
00045 {
00046 #ifndef NDEBUG
00047 if (full())
00048 DUNE_THROW(Dune::RangeError,
00049 "trying to call push on a full FiniteStack");
00050 #endif
00051 s[f++] = t;
00052 }
00053
00055 T pop ()
00056 {
00057 #ifndef NDEBUG
00058 if (empty())
00059 DUNE_THROW(Dune::RangeError,
00060 "trying to call top on an empty FiniteStack");
00061 #endif
00062 return s[--f];
00063 }
00064
00066 T top () const
00067 {
00068 #ifndef NDEBUG
00069 if (empty())
00070 DUNE_THROW(Dune::RangeError,
00071 "trying to call pop on an empty FiniteStack");
00072 #endif
00073 return s[f-1];
00074 }
00075
00077 int size () const
00078 {
00079 return f;
00080 }
00081
00083 FiniteStack ()
00084 {
00085 f = 0;
00086 }
00087
00088 private:
00089 T s[n];
00090 int f;
00091 };
00092
00093 }
00094
00096
00097 #endif