stack.hh

Go to the documentation of this file.
00001 #ifndef DUNE_STACK_HH
00002 #define DUNE_STACK_HH
00003 
00004 #include <dune/common/dlist.hh>
00005 #include <dune/common/exceptions.hh>
00006 #include <dune/common/deprecated.hh>
00007 
00008 // Backward compatibility
00009 #include <dune/common/finitestack.hh>
00010 
00011 #warning This header is deprecated.  Use std::stack instead of Dune::Stack.  The class Dune::FiniteStack has been moved to finitestack.hh.
00012 
00013 namespace Dune {
00014   
00028 
00029     class StackException : public RangeError {};
00030 
00039   template<class T>
00040   class Stack : private DoubleLinkedList<T> {
00041   public :
00042 
00044         bool empty () const;
00045 
00047         bool full () const; 
00048 
00050         void push (T& t) DUNE_DEPRECATED;
00051       
00053         T pop () DUNE_DEPRECATED;
00054 
00056         T top () const;
00057 
00059         int size() const;
00060   } DUNE_DEPRECATED ;
00061 
00062   template<class T>
00063   inline int Stack<T>::size () const
00064   {
00065         return DoubleLinkedList<T>::size();
00066   }
00067 
00068   template<class T>
00069   inline bool Stack<T>::empty () const
00070   {
00071         return size()==0;
00072   }
00073 
00074   template<class T>
00075   inline bool Stack<T>::full () const
00076   {
00077         return false;
00078   }
00079 
00080   template<class T>
00081   inline void Stack<T>::push (T& t)
00082   {
00083         insert_after(this->rbegin(),t);
00084   }
00085 
00086   template<class T>
00087   inline T Stack<T>::pop ()
00088   {
00089       if (empty()) 
00090           DUNE_THROW(StackException,  "cannot pop() empty stack!");
00091       
00092       typename DoubleLinkedList<T>::Iterator i=this->rbegin();
00093       T t = *i;
00094       erase(i);
00095       return t;
00096   }
00097 
00098   template<class T>
00099   inline T Stack<T>::top () const
00100   {
00101       if (empty()) 
00102           DUNE_THROW(StackException,  "no top() in empty stack!");
00103       
00104       typename DoubleLinkedList<T>::Iterator i=this->rbegin();
00105       T t = *i;
00106       return t;
00107   }
00108 
00109 }
00110 
00112 
00113 #endif

Generated on Tue Jul 28 22:27:50 2009 for dune-common by  doxygen 1.5.6