From 85bfff5605d0d6dc686f29f44449f924ae352566 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Kl=C3=B6fkorn?= <robertk@mathematik.uni-stuttgart.de> Date: Wed, 23 Mar 2005 10:27:27 +0000 Subject: [PATCH] Alle methods outside and inline. git-svn-id: https://dune.mathematik.uni-freiburg.de/svn/alugrid/trunk@142 0d966ed9-3843-0410-af09-ebfb50bd7c74 --- src/indexstack.h | 218 +++++++++++++++++++++++++---------------------- 1 file changed, 116 insertions(+), 102 deletions(-) diff --git a/src/indexstack.h b/src/indexstack.h index f4c7684e8..b29d23600 100644 --- a/src/indexstack.h +++ b/src/indexstack.h @@ -69,126 +69,34 @@ class IndexStack int maxIndex_; public: //! Constructor, create new IndexStack - IndexStack() : maxIndex_ (0) - { - stack_ = new StackType (); - } + IndexStack(); //! Destructor, deleting all stacks - ~IndexStack () - { - if(stack_) - { - delete stack_; - stack_ = new StackType(); - assert(stack_); - } - - while( !fullStackList_.empty() ) - { - StackType * st = fullStackList_.top(); - if(st) delete st; - fullStackList_.pop(); - } - while( !emptyStackList_.empty() ) - { - StackType * st = emptyStackList_.top(); - if(st) delete st; - emptyStackList_.pop(); - } - } + inline ~IndexStack (); //! set index as maxIndex if index is bigger than maxIndex - void checkAndSetMax(T index) - { - if(index > maxIndex_) maxIndex_ = index; - } + void checkAndSetMax(T index) { if(index > maxIndex_) maxIndex_ = index; } //! set index as maxIndex - void setMaxIndex(T index) - { - maxIndex_ = index; - } + void setMaxIndex(T index) { maxIndex_ = index; } //! set index as maxIndex - int getMaxIndex() const - { - return maxIndex_; - } + int getMaxIndex() const { return maxIndex_; } //! restore index from stack or create new index - T getIndex () - { - if((*stack_).empty()) - { - if( fullStackList_.size() <= 0) - { - return maxIndex_++; - } - else - { - emptyStackList_.push( stack_ ); - stack_ = fullStackList_.top(); - fullStackList_.pop(); - } - } - return (*stack_).pop(); - } + T getIndex (); //! store index on stack - void freeIndex(T index) - { - if(stack_->full()) - { - fullStackList_.push( stack_ ); - if(emptyStackList_.size() <= 0) - { - stack_ = new StackType (); - } - else - { - stack_ = emptyStackList_.top(); - emptyStackList_.pop(); - } - } - stack_->push(index); - } + void freeIndex(T index); //! test stack funtcionality - void test () - { - T vec[2*length]; - - for(int i=0; i<2*length; i++) - vec[i] = getIndex(); - - for(int i=0; i<2*length; i++) - freeIndex(vec[i]); - - for(int i=0; i<2*length; i++) - vec[i] = getIndex(); - - for(int i=0; i<2*length; i++) - printf(" index [%d] = %d \n",i,vec[i]); - } + void test (); // backup set to out stream - void backupIndexSet ( std::ostream & os ) - { - // holes are not stored at the moment - os.write( ((const char *) &maxIndex_ ), sizeof(int) ) ; - return ; - } + void backupIndexSet ( ostream & os ); // restore from in stream - void restoreIndexSet ( std::istream & is ) - { - is.read ( ((char *) &maxIndex_), sizeof(int) ); - clearStack (); - - return ; - } - + void restoreIndexSet ( istream & is ); private: // no copy constructor allowed IndexStack( const IndexStack<T,length> & s) : maxIndex_ (0) , stack_(0) {} @@ -221,6 +129,112 @@ private: } }; // end class IndexStack +//**************************************************************** +// Inline implementation +// *************************************************************** +template <class T, int length> +inline IndexStack<T,length>::IndexStack() + : stack_ ( new StackType () ) , maxIndex_ (0) {} + +template <class T, int length> +inline IndexStack<T,length>::~IndexStack () +{ + if(stack_) + { + delete stack_; + stack_ = new StackType(); + assert(stack_); + } + + while( !fullStackList_.empty() ) + { + StackType * st = fullStackList_.top(); + if(st) delete st; + fullStackList_.pop(); + } + while( !emptyStackList_.empty() ) + { + StackType * st = emptyStackList_.top(); + if(st) delete st; + emptyStackList_.pop(); + } +} + +template <class T, int length> +inline T IndexStack<T,length>::getIndex () +{ + if((*stack_).empty()) + { + if( fullStackList_.size() <= 0) + { + return maxIndex_++; + } + else + { + emptyStackList_.push( stack_ ); + stack_ = fullStackList_.top(); + fullStackList_.pop(); + } + } + return (*stack_).pop(); +} + +template <class T, int length> +inline void IndexStack<T,length>::freeIndex ( T index ) +{ + if((*stack_).full()) + { + fullStackList_.push( stack_ ); + if(emptyStackList_.size() <= 0) + { + stack_ = new StackType (); + } + else + { + stack_ = emptyStackList_.top(); + emptyStackList_.pop(); + } + } + (*stack_).push(index); +} + +template <class T, int length> +inline void IndexStack<T,length>::test () +{ + T vec[2*length]; + + for(int i=0; i<2*length; i++) + vec[i] = getIndex(); + + for(int i=0; i<2*length; i++) + freeIndex(vec[i]); + + for(int i=0; i<2*length; i++) + vec[i] = getIndex(); + + for(int i=0; i<2*length; i++) + printf(" index [%d] = %d \n",i,vec[i]); +} + +template <class T, int length> +inline void IndexStack<T,length>::backupIndexSet ( ostream & os ) +{ + // holes are not stored at the moment + os.write( ((const char *) &maxIndex_ ), sizeof(int) ) ; + return ; +} + +template <class T, int length> +inline void IndexStack<T,length>::restoreIndexSet ( istream & is ) +{ + is.read ( ((char *) &maxIndex_), sizeof(int) ); + clearStack (); + + return ; +} + + + #else //********************************************************************* -- GitLab