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; }
33 void push(
const T& t ) { BaseType :: push_back( t ); }
38 assert( !this->
empty() );
39 assert( this->
size() <= length );
49 typedef MyFiniteStack StackType;
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>
203 is.
read ( ((
char *) &maxIndex_),
sizeof(
int) );
209 template <
class T,
int length>
215 stack_ =
new StackType();
219 while( !fullStackList_.empty() )
221 StackType * st = fullStackList_.top();
223 fullStackList_.pop();
std::ptrdiff_t index() const
Include standard header files.
Definition indexstack.hh:24
void restoreIndexSet(std::istream &is)
Definition indexstack.hh:201
void checkAndSetMax(T index)
set index as maxIndex if index is bigger than maxIndex
Definition indexstack.hh:68
void backupIndexSet(std::ostream &os)
Definition indexstack.hh:193
~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