Diff for /parser3/src/include/pa_string.h between versions 1.2 and 1.24

version 1.2, 2001/01/26 18:34:02 version 1.24, 2001/02/21 12:43:41
Line 6 Line 6
   
         String                          Chunk0          String                          Chunk0
         ======                          ========          ======                          ========
         head--------->[ptr, size]          head--------------->[ptr, size, ...]
         append_here-------->[ptr, size]          append_here-------->[ptr, size, ...]
         link_row      ........                                                  .
                         .                       .                                                  .
                         .                       [ptr, size]                                                  [ptr, size, ...]
                         ...........>[link to the next chunk]          link_row----------->[link to the next chunk]
   
 */  */
   
 #ifndef PA_STRING_H  #ifndef PA_STRING_H
 #define PA_STRING_H  #define PA_STRING_H
   
   #ifdef HAVE_CONFIG_H
   #include "pa_config.h"
   #endif
   
 #include <stddef.h>  #include <stddef.h>
   
 class Pool;  #include "pa_pool.h"
   #include "pa_types.h"
   
   #ifndef NO_STRING_ORIGIN
   #       define STRING_APPEND_PARAMS const char *src, size_t size, char *file, uint line
   #       define APPEND(src, size, file, line) real_append(src, size, file, line)
   #else
   #       define STRING_APPEND_PARAMS const char *src, size_t size
   #       define APPEND(src, size, file, line) real_append(src, size)
   #endif
   #define APPEND_CONST(src) APPEND(src, 0, 0, 0)
   
   //class String_iterator;
   
 class String {  class String : public Pooled {
   //      friend String_iterator;
 public:  public:
         enum {          enum {
                 CR_PREALLOCATED_COUNT=5,                  CR_PREALLOCATED_COUNT=5,
                 CR_GROW_PERCENT=60                  CR_GROW_PERCENT=60
         };          };
   
 private:  public:
         friend Pool;  
   
         // the pool I'm allocated on          String(Pool& apool);
         Pool *pool;          String(const String& src);
           //String(const String_iterator& begin, const String_iterator& end);
           size_t size() const { return fsize; }
           int used_rows() const { return fused_rows; }
           char *cstr() const;
           String& real_append(STRING_APPEND_PARAMS);
           bool operator == (const String& src) const;
           bool operator == (char* src) const;
   //      String& append(const String_iterator& begin, const String_iterator& end);
   
           uint hash_code() const;
   
           const Origin& origin() const { return head.rows[0].item.origin; }
   
   private:
   
         // last chank allocated count cache  
         int curr_chunk_rows;  
         struct Chunk {          struct Chunk {
                 // the number of rows per chunk                  // the number of rows in chunk
                 int count;                  int count;
                 union Row {                  union Row {
                         // chunk item                          // chunk item
                         struct {                          struct {
                                 char *ptr;  // pointer to the start of string fragment                                  const char *ptr;  // pointer to the start of string fragment
                                 size_t size;  // length of the fragment                                  size_t size;  // length of the fragment
                                   Origin origin;  // origin of this fragment
                         } item;                          } item;
                         Chunk *link;  // link to the next chunk in chain                          Chunk *link;  // link to the next chunk in chain
                 } rows[CR_PREALLOCATED_COUNT];                  } rows[CR_PREALLOCATED_COUNT];
Line 60  private: Line 89  private:
         // of the link to the next chunk to allocate          // of the link to the next chunk to allocate
         Chunk::Row *link_row;          Chunk::Row *link_row;
   
         // new&constructors made private to enforce factory manufacturing at pool  private:
         void *operator new(size_t size, Pool *apool);          // last chank allocated count
           int curr_chunk_rows;
   
         void construct(Pool *apool);          // string size
         String() { /* never */}          size_t fsize;
         String(Pool *apool) {   
                 construct(apool);           // used rows in all chunks
         }          int fused_rows;
         String(Pool *apool, char *src) {  
                 construct(apool);  private:
                 *this+=src;  
         }  
   
         bool chunk_is_full() {          bool chunk_is_full() {
                 return append_here == link_row;                  return append_here == link_row;
         }          }
         void expand();          void expand();
         int used_rows();  
   
   private: //disabled
   
           String& operator = (const String&) { return *this; }
   
   };
   
   /*
   class Char_types {
   public:
           Char_types();
           void set(char from, char to, int type);
           void set(char c, int type) { 
                   types[static_cast<unsigned int>(c)]=static_cast<char>(type); 
           }
           int get(char c) { 
                   return static_cast<int>(types[static_cast<unsigned int>(c)]); 
           }
   private:        
           char types[0x100];
   };
   
   class String_iterator {
 public:  public:
           String_iterator(String& astring);
           String_iterator(String_iterator& asi);
   
         String(String& src);          void operator ++() { skip(); }
         size_t size();          void operator ++(int) { skip(); }
         char *c_str();  
         String& operator += (char *src);  
         bool operator == (String& src);  
   
         unsigned int hash_code();          int skip_to(Char_types& types);
           bool skip_to(char c);
   
           bool eof() { return position==0; }
   
           // current char
           char operator() () const;
   
   protected:
           // home string
           String& string;
           // the row in which we are
           String::Chunk::Row *read_here;
           // position in text, eof when 0 
           const char *position;
           // when read_here reaches this row, move to the next chunk
           String::Chunk::Row *link_row;
   
   protected:
   
           // advances position by one char
           void skip();
 };  };
   */
   
 #endif  #endif

Removed from v.1.2  
changed lines
  Added in v.1.24


E-mail: