--- parser3/src/include/pa_stack.h 2003/03/27 10:04:06 1.17.2.6.2.2 +++ parser3/src/include/pa_stack.h 2003/10/02 07:26:46 1.20 @@ -8,7 +8,7 @@ #ifndef PA_STACK_H #define PA_STACK_H -static const char* IDENT_STACK_H="$Date: 2003/03/27 10:04:06 $"; +static const char* IDENT_STACK_H="$Date: 2003/10/02 07:26:46 $"; #include "pa_config_includes.h" #include "pa_array.h" @@ -31,19 +31,23 @@ public: return get(--ftop); } - size_t top_index() { return ftop-1; } - void top_index(int top_index) { ftop=top_index+1; } - T top_value() { return get(top_index()); } + bool is_empty() { return ftop==0; } + size_t top_index() { return ftop; } + void set_top_index(size_t atop) { ftop=atop; } + T top_value() { + assert(!is_empty()); + return get(ftop-1); + } /// call this prior to collecting garbage [in unused part of stack there may be pointers(unused)] void wipe_unused() { - if(!is_full()) - memset(&felements[fused], 0, (fallocated-fused)*sizeof(T)); + if(size_t above_top_size=fused-ftop) + memset(&felements[ftop], 0, above_top_size*sizeof(T)); } -private: +protected: - // deepest used index + // deepest used index+1 size_t ftop; };