Diff for /parser3/src/include/pa_stack.h between versions 1.14 and 1.20

version 1.14, 2002/03/18 15:29:46 version 1.20, 2003/10/02 07:26:46
Line 1 Line 1
 /** @file  /** @file
         Parser: stack class decl.          Parser: stack class decl.
   
         Copyright (c) 2001, 2002 ArtLebedev Group (http://www.artlebedev.com)          Copyright (c) 2001-2003 ArtLebedev Group (http://www.artlebedev.com)
         Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)          Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
   
         $Id$  
 */  */
   
 #ifndef PA_STACK_H  #ifndef PA_STACK_H
 #define PA_STACK_H  #define PA_STACK_H
   
   static const char* IDENT_STACK_H="$Date$";
   
 #include "pa_config_includes.h"  #include "pa_config_includes.h"
 #include "pa_array.h"  #include "pa_array.h"
   
 /// simple stack based on Array  /// simple stack based on Array
 class Stack : public Array {  template<typename T> class Stack: public Array<T> {
 public:  public:
   
         Stack(Pool& apool) : Array(apool), ftop(0) {          Stack(): ftop(0) {}
         }  
   
         void push(Item *item) {          void push(T item) {
                 if(ftop<size()) // cell is already allocated?                  if(ftop<count()) // cell is already allocated?
                         put(ftop, item); // use it                          put(ftop, item); // use it
                 else                  else
                         *this+=item; // append it                          *this+=item; // append it
                 ftop++;                  ftop++;
         }          }
         Item *pop() {  
           T pop() {
                 return get(--ftop);                  return get(--ftop);
         }          }
   
         int top_index() { return ftop-1; }          bool is_empty() { return ftop==0; }
         void top_index(int top_index) { ftop=top_index+1; }          size_t top_index() { return ftop; }
         Item *top_value() { return get(top_index()); }          void set_top_index(size_t atop) { ftop=atop; }
           T top_value() { 
                   assert(!is_empty());
                   return get(ftop-1); 
           }
   
 private:          /// call this prior to collecting garbage [in unused part of stack there may be pointers(unused)]
           void wipe_unused() {
                   if(size_t above_top_size=fused-ftop)
                           memset(&felements[ftop], 0, above_top_size*sizeof(T));
           }
   
         // deepest used index  protected:
         int ftop;  
   
           // deepest used index+1
           size_t ftop;
 };  };
   
 #endif  #endif

Removed from v.1.14  
changed lines
  Added in v.1.20


E-mail: