Skip to content
Snippets Groups Projects
Commit 85bfff56 authored by Robert Klöfkorn's avatar Robert Klöfkorn
Browse files

Alle methods outside and inline.

git-svn-id: https://dune.mathematik.uni-freiburg.de/svn/alugrid/trunk@142 0d966ed9-3843-0410-af09-ebfb50bd7c74
parent fad76fe0
No related branches found
No related tags found
No related merge requests found
......@@ -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
//*********************************************************************
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment