Annotation of parser3/src/include/pa_stack.h, revision 1.11

1.7       paf         1: /** @file
1.8       paf         2:        Parser: stack class decl.
                      3: 
1.5       paf         4:        Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com)
1.11    ! paf         5:        Author: Alexander Petrosyan <paf@design.ru> (http://paf.design.ru)
1.5       paf         6: 
1.11    ! paf         7:        $Id: pa_stack.h,v 1.10 2001/09/26 10:32:25 parser Exp $
1.1       paf         8: */
                      9: 
                     10: #ifndef PA_STACK_H
                     11: #define PA_STACK_H
                     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.1       paf        17: class Stack : public Array {
                     18: public:
                     19: 
1.2       paf        20:        Stack(Pool& apool) : Array(apool), ftop(0) {
1.1       paf        21:        }
                     22: 
                     23:        void push(Item *item) {
1.2       paf        24:                if(ftop<size()) // cell is already allocated?
                     25:                        put(ftop, item); // use it
1.1       paf        26:                else
                     27:                        *this+=item; // append it
1.2       paf        28:                ftop++;
1.1       paf        29:        }
                     30:        Item *pop() {
1.2       paf        31:                return get(--ftop);
1.1       paf        32:        }
                     33: 
1.4       paf        34:        int top_index() { return ftop-1; }
                     35:        Item *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: