3#ifndef DUNE_ALBERTAGRID_INDEXSTACK_HH
4#define DUNE_ALBERTAGRID_INDEXSTACK_HH
22 template <
class T,
int length>
30 bool full ()
const {
return this->
size() >= length; }
38 assert( !this->empty() );
39 assert( this->
size() <= length );
49 typedef MyFiniteStack StackType;
50 typedef typename std::stack < StackType * > StackListType;
52 StackListType fullStackList_;
53 StackListType emptyStackList_;
68 inline void checkAndSetMax(T index) {
if(index > maxIndex_) maxIndex_ = index;}
89 inline void backupIndexSet ( std::ostream & os );
92 inline void restoreIndexSet ( std::istream & is );
98 IndexStack<T,length> & operator = (
const IndexStack<T,length> & s)
100 DUNE_THROW(Exception,
"IndexStack::operator = () not allowed!");
112 template <
class T,
int length>
114 : stack_ ( new StackType () ) , maxIndex_ (0) {}
116 template <
class T,
int length>
119 if(stack_)
delete stack_;
122 while( !fullStackList_.empty() )
124 StackType * st = fullStackList_.top();
126 fullStackList_.pop();
128 while( !emptyStackList_.empty() )
130 StackType * st = emptyStackList_.top();
132 emptyStackList_.pop();
136 template <
class T,
int length>
139 if((*stack_).empty())
141 if( fullStackList_.size() <= 0)
147 emptyStackList_.push( stack_ );
148 stack_ = fullStackList_.top();
149 fullStackList_.pop();
152 return (*stack_).topAndPop();
155 template <
class T,
int length>
160 fullStackList_.push( stack_ );
161 if(emptyStackList_.size() <= 0)
163 stack_ =
new StackType ();
167 stack_ = emptyStackList_.top();
168 emptyStackList_.pop();
171 (*stack_).push(index);
174 template <
class T,
int length>
179 for(
int i=0; i<2*length; i++)
182 for(
int i=0; i<2*length; i++)
185 for(
int i=0; i<2*length; i++)
188 for(
int i=0; i<2*length; i++)
189 printf(
" index [%d] = %d \n",i,vec[i]);
192 template <
class T,
int length>
196 os.write( ((
const char *) &maxIndex_ ),
sizeof(
int) ) ;
200 template <
class T,
int length>
201 inline void IndexStack<T,length>::restoreIndexSet ( std::istream & is )
203 is.read ( ((
char *) &maxIndex_),
sizeof(
int) );
209 template <
class T,
int length>
210 inline void IndexStack<T,length>::clearStack ()
215 stack_ =
new StackType();
219 while( !fullStackList_.empty() )
221 StackType * st = fullStackList_.top();
223 fullStackList_.pop();
Definition: indexstack.hh:24
void checkAndSetMax(T index)
set index as maxIndex if index is bigger than maxIndex
Definition: indexstack.hh:68
~IndexStack()
Destructor, deleting all stacks.
Definition: indexstack.hh:117
T getIndex()
restore index from stack or create new index
Definition: indexstack.hh:137
IndexStack()
Constructor, create new IndexStack.
Definition: indexstack.hh:113
void setMaxIndex(T index)
set index as maxIndex
Definition: indexstack.hh:71
int size() const
return maxIndex which is also the
Definition: indexstack.hh:77
void test()
test stack functionality
Definition: indexstack.hh:175
void freeIndex(T index)
store index on stack
Definition: indexstack.hh:156
int getMaxIndex() const
return maxIndex which is also the
Definition: indexstack.hh:74
A Vector class with statically reserved memory.
Definition: reservedvector.hh:42
void push_back(const T &t)
Appends an element to the end of a vector, up to the maximum size n, O(1) time.
Definition: reservedvector.hh:104
A few common exception classes.
#define DUNE_THROW(E, m)
Definition: exceptions.hh:216
Dune namespace.
Definition: alignedallocator.hh:10
An stl-compliant random-access container which stores everything on the stack.