5#ifndef DUNE_ALBERTAGRID_INDEXSTACK_HH
6#define DUNE_ALBERTAGRID_INDEXSTACK_HH
24 template <
class T,
int length>
32 bool full ()
const {
return this->
size() >= length; }
40 assert( !this->empty() );
41 assert( this->
size() <= length );
51 typedef MyFiniteStack StackType;
52 typedef typename std::stack < StackType * > StackListType;
54 StackListType fullStackList_;
55 StackListType emptyStackList_;
70 inline void checkAndSetMax(T index) {
if(index > maxIndex_) maxIndex_ = index;}
91 inline void backupIndexSet ( std::ostream & os );
94 inline void restoreIndexSet ( std::istream & is );
100 IndexStack<T,length> & operator = (
const IndexStack<T,length> & s)
102 DUNE_THROW(Exception,
"IndexStack::operator = () not allowed!");
114 template <
class T,
int length>
116 : stack_ ( new StackType () ) , maxIndex_ (0) {}
118 template <
class T,
int length>
121 if(stack_)
delete stack_;
124 while( !fullStackList_.empty() )
126 StackType * st = fullStackList_.top();
128 fullStackList_.pop();
130 while( !emptyStackList_.empty() )
132 StackType * st = emptyStackList_.top();
134 emptyStackList_.pop();
138 template <
class T,
int length>
141 if((*stack_).empty())
143 if( fullStackList_.size() <= 0)
149 emptyStackList_.push( stack_ );
150 stack_ = fullStackList_.top();
151 fullStackList_.pop();
154 return (*stack_).topAndPop();
157 template <
class T,
int length>
162 fullStackList_.push( stack_ );
163 if(emptyStackList_.size() <= 0)
165 stack_ =
new StackType ();
169 stack_ = emptyStackList_.top();
170 emptyStackList_.pop();
173 (*stack_).push(index);
176 template <
class T,
int length>
181 for(
int i=0; i<2*length; i++)
184 for(
int i=0; i<2*length; i++)
187 for(
int i=0; i<2*length; i++)
190 for(
int i=0; i<2*length; i++)
191 printf(
" index [%d] = %d \n",i,vec[i]);
194 template <
class T,
int length>
198 os.write( ((
const char *) &maxIndex_ ),
sizeof(
int) ) ;
202 template <
class T,
int length>
203 inline void IndexStack<T,length>::restoreIndexSet ( std::istream & is )
205 is.read ( ((
char *) &maxIndex_),
sizeof(
int) );
211 template <
class T,
int length>
212 inline void IndexStack<T,length>::clearStack ()
217 stack_ =
new StackType();
221 while( !fullStackList_.empty() )
223 StackType * st = fullStackList_.top();
225 fullStackList_.pop();
Definition: indexstack.hh:26
void checkAndSetMax(T index)
set index as maxIndex if index is bigger than maxIndex
Definition: indexstack.hh:70
~IndexStack()
Destructor, deleting all stacks.
Definition: indexstack.hh:119
T getIndex()
restore index from stack or create new index
Definition: indexstack.hh:139
IndexStack()
Constructor, create new IndexStack.
Definition: indexstack.hh:115
void setMaxIndex(T index)
set index as maxIndex
Definition: indexstack.hh:73
int size() const
return maxIndex which is also the
Definition: indexstack.hh:79
void test()
test stack functionality
Definition: indexstack.hh:177
void freeIndex(T index)
store index on stack
Definition: indexstack.hh:158
int getMaxIndex() const
return maxIndex which is also the
Definition: indexstack.hh:76
A Vector class with statically reserved memory.
Definition: reservedvector.hh:47
constexpr void push_back(const value_type &t) noexcept(std::is_nothrow_copy_assignable_v< value_type >)
Appends an element to the end of a vector, up to the maximum size n, O(1) time.
Definition: reservedvector.hh:194
A few common exception classes.
#define DUNE_THROW(E, m)
Definition: exceptions.hh:218
Dune namespace.
Definition: alignedallocator.hh:13
An stl-compliant random-access container which stores everything on the stack.