1 #ifndef DUNE_ALBERTAGRID_INDEXSTACK_HH
2 #define DUNE_ALBERTAGRID_INDEXSTACK_HH
7 #include <dune/common/exceptions.hh>
8 #include <dune/common/reservedvector.hh>
20 template <
class T,
int length>
23 class MyFiniteStack :
public ReservedVector<T,length>
25 typedef ReservedVector<T,length> BaseType ;
28 bool full ()
const {
return this->
size() >= length; }
31 void push(
const T& t ) { BaseType :: push_back( t ); }
36 assert( !this->empty() );
37 assert( this->
size() <= length );
47 typedef MyFiniteStack StackType;
48 typedef typename std::stack < StackType * > StackListType;
50 StackListType fullStackList_;
51 StackListType emptyStackList_;
66 inline void checkAndSetMax(T index) {
if(index > maxIndex_) maxIndex_ = index; }
96 IndexStack<T,length> & operator = (
const IndexStack<T,length> & s)
98 DUNE_THROW(Exception,
"IndexStack::operator = () not allowed!");
110 template <
class T,
int length>
112 : stack_ ( new StackType () ) , maxIndex_ (0) {}
114 template <
class T,
int length>
117 if(stack_)
delete stack_;
120 while( !fullStackList_.empty() )
122 StackType * st = fullStackList_.top();
124 fullStackList_.pop();
126 while( !emptyStackList_.empty() )
128 StackType * st = emptyStackList_.top();
130 emptyStackList_.pop();
134 template <
class T,
int length>
137 if((*stack_).empty())
139 if( fullStackList_.size() <= 0)
145 emptyStackList_.push( stack_ );
146 stack_ = fullStackList_.top();
147 fullStackList_.pop();
150 return (*stack_).topAndPop();
153 template <
class T,
int length>
158 fullStackList_.push( stack_ );
159 if(emptyStackList_.size() <= 0)
161 stack_ =
new StackType ();
165 stack_ = emptyStackList_.top();
166 emptyStackList_.pop();
169 (*stack_).push(index);
172 template <
class T,
int length>
177 for(
int i=0; i<2*length; i++)
180 for(
int i=0; i<2*length; i++)
183 for(
int i=0; i<2*length; i++)
186 for(
int i=0; i<2*length; i++)
187 printf(
" index [%d] = %d \n",i,vec[i]);
190 template <
class T,
int length>
194 os.write( ((
const char *) &maxIndex_ ),
sizeof(
int) ) ;
198 template <
class T,
int length>
201 is.read ( ((
char *) &maxIndex_),
sizeof(
int) );
207 template <
class T,
int length>
213 stack_ =
new StackType();
217 while( !fullStackList_.empty() )
219 StackType * st = fullStackList_.top();
221 fullStackList_.pop();