Annotation of parser3/src/include/pa_stack.h, revision 1.17.2.3
1.7 paf 1: /** @file
1.8 paf 2: Parser: stack class decl.
3:
1.17.2.3! paf 4: Copyright (c) 2001-2003 ArtLebedev Group (http://www.artlebedev.com)
1.13 paf 5: Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
1.1 paf 6: */
7:
8: #ifndef PA_STACK_H
9: #define PA_STACK_H
1.15 paf 10:
1.17.2.3! paf 11: static const char* IDENT_STACK_H="$Date: 2003/01/28 09:48:16 $";
1.1 paf 12:
1.9 parser 13: #include "pa_config_includes.h"
1.1 paf 14: #include "pa_array.h"
15:
1.7 paf 16: /// simple stack based on Array
1.17.2.1 paf 17: template<typename T> class Stack: public Array<T> {
1.1 paf 18: public:
19:
1.17.2.1 paf 20: Stack(): ftop(0) {}
1.1 paf 21:
1.17.2.1 paf 22: void push(T item) {
1.17.2.2 paf 23: if(ftop<count()) // cell is already allocated?
1.2 paf 24: put(ftop, item); // use it
1.1 paf 25: else
26: *this+=item; // append it
1.2 paf 27: ftop++;
1.1 paf 28: }
1.17.2.1 paf 29: T pop() {
1.2 paf 30: return get(--ftop);
1.1 paf 31: }
32:
1.4 paf 33: int top_index() { return ftop-1; }
1.14 paf 34: void top_index(int top_index) { ftop=top_index+1; }
1.17.2.1 paf 35: T 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: