|
|
| version 1.1, 2001/02/21 17:36:30 | version 1.8, 2001/03/19 17:42:12 |
|---|---|
| Line 1 | Line 1 |
| /* | /** @file |
| $Id$ | Parser: stack class decl. |
| Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) | |
| Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf) | |
| $Id$ | |
| */ | */ |
| #ifndef PA_STACK_H | #ifndef PA_STACK_H |
| Line 7 | Line 13 |
| #include "pa_array.h" | #include "pa_array.h" |
| /// simple stack based on Array | |
| class Stack : public Array { | class Stack : public Array { |
| public: | public: |
| Stack(Pool& apool) : Array(apool), top(0) { | Stack(Pool& apool) : Array(apool), ftop(0) { |
| } | } |
| void push(Item *item) { | void push(Item *item) { |
| if(top<size()) // cell is already allocated? | if(ftop<size()) // cell is already allocated? |
| put(top, item); // use it | put(ftop, item); // use it |
| else | else |
| *this+=item; // append it | *this+=item; // append it |
| top++; | ftop++; |
| } | } |
| Item *pop() { | Item *pop() { |
| return get(--top); | return get(--ftop); |
| } | } |
| Item *operator [] (int top_offset) { | int top_index() { return ftop-1; } |
| return get(top-top_offset-1); | Item *top_value() { return get(top_index()); } |
| } | |
| private: | private: |
| // deepest used index | // deepest used index |
| int top; | int ftop; |
| }; | }; |