Annotation of parser3/src/include/pa_stack.h, revision 1.17.2.4
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.4! paf 11: static const char* IDENT_STACK_H="$Date: 2003/01/31 12:34:31 $";
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.17.2.4! paf 30: T result=get(--ftop);
! 31: put(ftop, T());
! 32: return result;
1.1 paf 33: }
34:
1.4 paf 35: int top_index() { return ftop-1; }
1.14 paf 36: void top_index(int top_index) { ftop=top_index+1; }
1.17.2.1 paf 37: T top_value() { return get(top_index()); }
1.2 paf 38:
1.1 paf 39: private:
40:
41: // deepest used index
1.2 paf 42: int ftop;
1.1 paf 43:
44: };
45:
46: #endif
E-mail: