Annotation of parser3/src/include/pa_stack.h, revision 1.9
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.9 ! parser 8: $Id: pa_stack.h,v 1.8 2001/03/19 17:42:12 paf Exp $
1.1 paf 9: */
10:
11: #ifndef PA_STACK_H
12: #define PA_STACK_H
13:
1.9 ! parser 14: #include "pa_config_includes.h"
1.1 paf 15: #include "pa_array.h"
16:
1.7 paf 17: /// simple stack based on Array
1.1 paf 18: class Stack : public Array {
19: public:
20:
1.2 paf 21: Stack(Pool& apool) : Array(apool), ftop(0) {
1.1 paf 22: }
23:
24: void push(Item *item) {
1.2 paf 25: if(ftop<size()) // cell is already allocated?
26: put(ftop, item); // use it
1.1 paf 27: else
28: *this+=item; // append it
1.2 paf 29: ftop++;
1.1 paf 30: }
31: Item *pop() {
1.2 paf 32: return get(--ftop);
1.1 paf 33: }
34:
1.4 paf 35: int top_index() { return ftop-1; }
36: Item *top_value() { return get(top_index()); }
1.2 paf 37:
1.1 paf 38: private:
39:
40: // deepest used index
1.2 paf 41: int ftop;
1.1 paf 42:
43: };
44:
45: #endif
E-mail: