|
|
| version 1.17, 2003/01/21 15:51:11 | version 1.17.2.2, 2003/01/28 09:48:16 |
|---|---|
| Line 14 static const char* IDENT_STACK_H="$Date$ | Line 14 static const char* IDENT_STACK_H="$Date$ |
| #include "pa_array.h" | #include "pa_array.h" |
| /// simple stack based on Array | /// simple stack based on Array |
| class Stack : public Array { | template<typename T> class Stack: public Array<T> { |
| public: | public: |
| Stack(Pool& apool) : Array(apool), ftop(0) { | Stack(): ftop(0) {} |
| } | |
| void push(Item *item) { | void push(T item) { |
| if(ftop<size()) // cell is already allocated? | if(ftop<count()) // cell is already allocated? |
| put(ftop, item); // use it | put(ftop, item); // use it |
| else | else |
| *this+=item; // append it | *this+=item; // append it |
| ftop++; | ftop++; |
| } | } |
| Item *pop() { | T pop() { |
| return get(--ftop); | return get(--ftop); |
| } | } |
| int top_index() { return ftop-1; } | int top_index() { return ftop-1; } |
| void top_index(int top_index) { ftop=top_index+1; } | void top_index(int top_index) { ftop=top_index+1; } |
| Item *top_value() { return get(top_index()); } | T top_value() { return get(top_index()); } |
| private: | private: |