Annotation of parser3/src/include/pa_stack.h, revision 1.8
1.7 paf 1: /** @file
1.8 ! paf 2: Parser: stack class decl.
! 3:
1.5 paf 4: Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com)
1.8 ! paf 5:
1.6 paf 6: Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf)
1.5 paf 7:
1.8 ! paf 8: $Id: pa_stack.h,v 1.7 2001/03/19 15:29:38 paf Exp $
1.1 paf 9: */
10:
11: #ifndef PA_STACK_H
12: #define PA_STACK_H
13:
14: #include "pa_array.h"
15:
1.7 paf 16: /// simple stack based on Array
1.1 paf 17: class Stack : public Array {
18: public:
19:
1.2 paf 20: Stack(Pool& apool) : Array(apool), ftop(0) {
1.1 paf 21: }
22:
23: void push(Item *item) {
1.2 paf 24: if(ftop<size()) // cell is already allocated?
25: put(ftop, item); // use it
1.1 paf 26: else
27: *this+=item; // append it
1.2 paf 28: ftop++;
1.1 paf 29: }
30: Item *pop() {
1.2 paf 31: return get(--ftop);
1.1 paf 32: }
33:
1.4 paf 34: int top_index() { return ftop-1; }
35: Item *top_value() { return get(top_index()); }
1.2 paf 36:
1.1 paf 37: private:
38:
39: // deepest used index
1.2 paf 40: int ftop;
1.1 paf 41:
42: };
43:
44: #endif
E-mail: