Annotation of parser3/src/include/pa_stack.h, revision 1.17.2.6.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.6.2.3! paf        11: static const char* IDENT_STACK_H="$Date: 2003/03/27 10:04:06 $";
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.5  paf        29: 
1.17.2.1  paf        30:        T pop() {
1.17.2.6.2.2  paf        31:                return get(--ftop);
1.1       paf        32:        }
                     33: 
1.17.2.6.2.1  paf        34:        size_t top_index() { return ftop-1; }
1.17.2.6.2.3! paf        35:        void top_index(size_t top_index) { ftop=top_index+1; }
1.17.2.1  paf        36:        T top_value() { return get(top_index()); }
1.2       paf        37: 
1.17.2.6.2.2  paf        38:        /// call this prior to collecting garbage [in unused part of stack there may be pointers(unused)]
                     39:        void wipe_unused() {
                     40:                if(!is_full())
                     41:                        memset(&felements[fused], 0, (fallocated-fused)*sizeof(T));
                     42:        }
                     43: 
1.1       paf        44: private:
                     45: 
1.17.2.6.2.3! paf        46:        // deepest used index+1
1.17.2.6.2.1  paf        47:        size_t ftop;
1.1       paf        48: };
                     49: 
                     50: #endif

E-mail: