--- parser3/src/include/pa_array.h 2016/11/24 19:24:45 1.84 +++ parser3/src/include/pa_array.h 2024/09/07 16:30:26 1.89 @@ -1,14 +1,14 @@ /** @file Parser: Array & Array_iterator classes decls. - Copyright (c) 2001-2015 Art. Lebedev Studio (http://www.artlebedev.com) - Author: Alexandr Petrosian (http://paf.design.ru) + Copyright (c) 2001-2023 Art. Lebedev Studio (http://www.artlebedev.com) + Authors: Konstantin Morshnev , Alexandr Petrosian */ #ifndef PA_ARRAY_H #define PA_ARRAY_H -#define IDENT_PA_ARRAY_H "$Id: pa_array.h,v 1.84 2016/11/24 19:24:45 moko Exp $" +#define IDENT_PA_ARRAY_H "$Id: pa_array.h,v 1.89 2024/09/07 16:30:26 moko Exp $" // includes @@ -40,6 +40,8 @@ protected: size_t fused; public: + typedef Array_iterator Iterator; + struct Action_options { size_t offset; size_t limit; //< ARRAY_OPTION_LIMIT_ALL means 'all'. zero limit means 'nothing' @@ -209,11 +211,26 @@ public: 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: bool is_full() { return fused == fallocated; } + void expand(size_t delta) { if(fallocated){ size_t new_allocated=fallocated+delta; @@ -235,7 +252,7 @@ private: //disabled /** Array iterator, usage: @code // Array a; - for(Array_iterator i(a); i.has_next(); ) { + for(Array_iterator i(a); i; ) { T& element=i.next(); ... } @@ -255,14 +272,24 @@ public: } /// there are still elements - bool has_next() { + operator bool () { return fcurrent