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

1.7     ! paf         1: /** @file
1.5       paf         2:        Parser
                      3:        Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com)
1.6       paf         4:        Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf)
1.5       paf         5: 
1.7     ! paf         6:        $Id: pa_stack.h,v 1.6 2001/03/11 08:16:33 paf Exp $
1.1       paf         7: */
                      8: 
                      9: #ifndef PA_STACK_H
                     10: #define PA_STACK_H
                     11: 
                     12: #include "pa_array.h"
                     13: 
1.7     ! paf        14: /// simple stack based on Array
1.1       paf        15: class Stack : public Array {
                     16: public:
                     17: 
1.2       paf        18:        Stack(Pool& apool) : Array(apool), ftop(0) {
1.1       paf        19:        }
                     20: 
                     21:        void push(Item *item) {
1.2       paf        22:                if(ftop<size()) // cell is already allocated?
                     23:                        put(ftop, item); // use it
1.1       paf        24:                else
                     25:                        *this+=item; // append it
1.2       paf        26:                ftop++;
1.1       paf        27:        }
                     28:        Item *pop() {
1.2       paf        29:                return get(--ftop);
1.1       paf        30:        }
                     31: 
1.4       paf        32:        int top_index() { return ftop-1; }
                     33:        Item *top_value() { return get(top_index()); }
1.2       paf        34: 
1.1       paf        35: private:
                     36: 
                     37:        // deepest used index
1.2       paf        38:        int ftop;
1.1       paf        39: 
                     40: };
                     41: 
                     42: #endif

E-mail: