Annotation of parser3/src/include/pa_stack.h, revision 1.18
1.7 paf 1: /** @file
1.8 paf 2: Parser: stack class decl.
3:
1.18 ! 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.18 ! paf 11: static const char* IDENT_STACK_H="$Date: 2003/07/23 08:40:54 $";
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.18 ! paf 17: template<typename T> class Stack: public Array<T> {
1.1 paf 18: public:
19:
1.18 ! paf 20: Stack(): ftop(0) {}
1.1 paf 21:
1.18 ! paf 22: void push(T item) {
! 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.18 ! paf 29:
! 30: T pop() {
1.2 paf 31: return get(--ftop);
1.1 paf 32: }
33:
1.18 ! paf 34: bool is_empty() { return ftop==0; }
! 35: size_t top() { return ftop; }
! 36: void top(size_t atop) { ftop=atop; }
! 37: T upper_value() {
! 38: assert(!is_empty());
! 39: return get(ftop-1);
! 40: }
1.2 paf 41:
1.18 ! paf 42: /// call this prior to collecting garbage [in unused part of stack there may be pointers(unused)]
! 43: void wipe_unused() {
! 44: if(!is_full())
! 45: memset(&felements[fused], 0, (fallocated-fused)*sizeof(T));
! 46: }
1.1 paf 47:
1.18 ! paf 48: protected:
1.1 paf 49:
1.18 ! paf 50: // deepest used index+1
! 51: size_t ftop;
1.1 paf 52: };
53:
54: #endif
E-mail: