Diff for /parser3/src/include/pa_array.h between versions 1.89 and 1.91

version 1.89, 2024/09/07 16:30:26 version 1.91, 2024/09/11 21:07:36
Line 13 Line 13
 // includes  // includes
   
 #include "pa_memory.h"  #include "pa_memory.h"
   #include "pa_types.h"
 #include "pa_exception.h"  #include "pa_exception.h"
   
 // forwards  // forwards
   
 template<typename T> class Array_iterator;  template<typename T> class Array_iterator;
   template<typename T> class Array_reverse_iterator;
   
 // defines  // defines
   
Line 27  template<typename T> class Array_iterato Line 29  template<typename T> class Array_iterato
 template<typename T> class Array: public PA_Object {  template<typename T> class Array: public PA_Object {
   
         friend class Array_iterator<T>;          friend class Array_iterator<T>;
           friend class Array_reverse_iterator<T>;
   
 protected:  protected:
   
Line 41  protected: Line 44  protected:
   
 public:  public:
         typedef Array_iterator<T> Iterator;          typedef Array_iterator<T> Iterator;
           typedef Array_reverse_iterator<T> ReverseIterator;
   
         struct Action_options {          struct Action_options {
                 size_t offset;                  size_t offset;
Line 172  public: Line 176  public:
         inline T operator [](size_t index) const { return get(index); }          inline T operator [](size_t index) const { return get(index); }
   
         inline void clear() {          inline void clear() {
                   if(fused)
                           memset(felements, 0, fused * sizeof(T));
                 fused=0;                  fused=0;
         }          }
   
Line 248  private: //disabled Line 254  private: //disabled
         Array& operator = (const Array&) { return *this; }          Array& operator = (const Array&) { return *this; }
 };  };
   
   /// Commonly used, templated to work with any integer type
   
   template<typename T> char* pa_itoa(T n, T base=10){
           char buf[MAX_NUMBER + 1];
           char* pos=buf + MAX_NUMBER;
           *pos='\0';
   
           bool negative=n < 0;
           if (n < 0){
                   n=-n;
           }
   
           do {
                   *(--pos)=(n % base) + '0';
                   n/=base;
           } while (n > 0);
   
           if (negative) {
                   *(--pos) = '-';
           }
           return pa_strdup(pos, buf + MAX_NUMBER - pos);
   }
   
   template<typename T> char* pa_uitoa(T n, T base=10){
           char buf[MAX_NUMBER + 1];
           char* pos=buf + MAX_NUMBER;
           *pos='\0';
   
           do {
                   *(--pos)=(n % base) + '0';
                   n/=base;
           } while (n > 0);
   
           return pa_strdup(pos, buf + MAX_NUMBER - pos);
   }
   
   
 /** Array iterator, usage:  /** Array iterator, usage:
         @code          @code
Line 268  public: Line 310  public:
   
         Array_iterator(const Array<T>& aarray): farray(aarray) {          Array_iterator(const Array<T>& aarray): farray(aarray) {
                 fcurrent=farray.felements;                  fcurrent=farray.felements;
                 flast=farray.felements+farray.count();                  flast=farray.felements + farray.count();
         }          }
   
         /// there are still elements          /// there are still elements
         operator bool () {          inline operator bool () {
                 return fcurrent<flast;                  return fcurrent < flast;
         }          }
   
         /// returns the current element and advances the iterator          /// returns the current element and advances the iterator
         T next() {          inline T next() {
                 return *(fcurrent++);                  return *(fcurrent++);
         }          }
   
         /// returns the current element          /// returns the current element
         T value() {          inline T value() {
                 return *(fcurrent);                  return *(fcurrent);
         }          }
   
         // returns the current index of the iterator          // returns the current index of the iterator
         size_t index() {          inline size_t index() {
                   return fcurrent - farray.felements;
           }
   
           inline char *key(){
                   return pa_uitoa(index());
           }
   
   };
   
   template<typename T> class Array_reverse_iterator {
   
           const Array<T>& farray;
           T *fcurrent;
   
   public:
   
           Array_reverse_iterator(const Array<T>& aarray): farray(aarray) {
                   fcurrent=farray.felements+farray.count();
           }
   
           /// there are still elements
           inline operator bool () {
                   return fcurrent > farray.felements;
           }
   
           /// returns the current element and advances the iterator
           inline T prev() {
                   return *(--fcurrent);
           }
   
           // returns the current index of the iterator
           inline size_t index() {
                 return fcurrent - farray.felements;                  return fcurrent - farray.felements;
         }          }
   
           inline char *key(){
                   return pa_uitoa(index());
           }
   
 };  };
 #endif  #endif

Removed from v.1.89  
changed lines
  Added in v.1.91


E-mail: