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

version 1.84, 2016/11/24 19:24:45 version 1.89, 2024/09/07 16:30:26
Line 1 Line 1
 /** @file  /** @file
         Parser: Array & Array_iterator classes decls.          Parser: Array & Array_iterator classes decls.
   
         Copyright (c) 2001-2015 Art. Lebedev Studio (http://www.artlebedev.com)          Copyright (c) 2001-2023 Art. Lebedev Studio (http://www.artlebedev.com)
         Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)          Authors: Konstantin Morshnev <moko@design.ru>, Alexandr Petrosian <paf@design.ru>
 */  */
   
 #ifndef PA_ARRAY_H  #ifndef PA_ARRAY_H
Line 40  protected: Line 40  protected:
         size_t fused;          size_t fused;
   
 public:  public:
           typedef Array_iterator<T> Iterator;
   
         struct Action_options {          struct Action_options {
                 size_t offset;                  size_t offset;
                 size_t limit; //< ARRAY_OPTION_LIMIT_ALL means 'all'. zero limit means 'nothing'                  size_t limit; //< ARRAY_OPTION_LIMIT_ALL means 'all'. zero limit means 'nothing'
Line 209  public: Line 211  public:
                 return felements + index;                  return felements + index;
         }          }
   
           void fit(size_t index, T element){
                   if(index >= fallocated){
                           size_t new_allocated=fallocated>0 ? fallocated : 3;
                           while(new_allocated <= index){
                                   new_allocated+=2 + new_allocated/32;
                           }
                           expand(new_allocated - fallocated);
                   }
                   felements[index]=element;
                   if(index >= fused){
                           fused=index+1;
                   }
           }
   
 protected:  protected:
   
         bool is_full() {          bool is_full() {
                 return fused == fallocated;                  return fused == fallocated;
         }          }
   
         void expand(size_t delta) {          void expand(size_t delta) {
                 if(fallocated){                  if(fallocated){
                         size_t new_allocated=fallocated+delta;                          size_t new_allocated=fallocated+delta;
Line 235  private: //disabled Line 252  private: //disabled
 /** Array iterator, usage:  /** Array iterator, usage:
         @code          @code
         // Array<T> a;          // Array<T> a;
         for(Array_iterator<T> i(a); i.has_next(); ) {          for(Array_iterator<T> i(a); i; ) {
                 T& element=i.next();                  T& element=i.next();
                 ...                  ...
         }                 }       
Line 255  public: Line 272  public:
         }          }
   
         /// there are still elements          /// there are still elements
         bool has_next() {          operator bool () {
                 return fcurrent<flast;                  return fcurrent<flast;
         }          }
   
         /// quickly extracts next Array element          /// returns the current element and advances the iterator
         T next() {          T next() {
                 return *(fcurrent++);                  return *(fcurrent++);
         }          }
   
           /// returns the current element
           T value() {
                   return *(fcurrent);
           }
   
           // returns the current index of the iterator
           size_t index() {
                   return fcurrent - farray.felements;
           }
   
 };  };
 #endif  #endif

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


E-mail: