Annotation of parser3/src/include/pa_string.h, revision 1.5

1.1       paf         1: /*
1.5     ! paf         2:   $Id: pa_string.h,v 1.4 2001/01/27 10:02:59 paf Exp $
1.1       paf         3: */
                      4: 
                      5: /*
                      6: 
                      7:        String                          Chunk0
                      8:        ======                          ========
                      9:        head--------->[ptr, size]
                     10:        append_here-------->[ptr, size]
                     11:        link_row      ........
                     12:                        .                       .
                     13:                        .                       [ptr, size]
                     14:                        ...........>[link to the next chunk]
                     15: 
                     16: */
                     17: 
                     18: #ifndef PA_STRING_H
                     19: #define PA_STRING_H
                     20: 
                     21: #include <stddef.h>
                     22: 
1.4       paf        23: #include "pa_types.h"
                     24: 
1.1       paf        25: class Pool;
                     26: 
                     27: class String {
                     28: public:
                     29:        enum {
                     30:                CR_PREALLOCATED_COUNT=5,
                     31:                CR_GROW_PERCENT=60
                     32:        };
                     33: 
                     34: private:
                     35:        friend Pool;
                     36: 
                     37:        // the pool I'm allocated on
                     38:        Pool *pool;
                     39: 
                     40:        struct Chunk {
                     41:                // the number of rows per chunk
                     42:                int count;
                     43:                union Row {
                     44:                        // chunk item
                     45:                        struct {
                     46:                                char *ptr;  // pointer to the start of string fragment
                     47:                                size_t size;  // length of the fragment
                     48:                        } item;
                     49:                        Chunk *link;  // link to the next chunk in chain
1.2       paf        50:                } rows[CR_PREALLOCATED_COUNT];
1.1       paf        51:                // next rows are here
                     52:                Chunk *preallocated_link;
                     53:        }
                     54:                head;  // the head chunk of the chunk chain
                     55: 
                     56:        // next append would write to this record
                     57:        Chunk::Row *append_here;
                     58:        
                     59:        // the address of place where lies address 
                     60:        // of the link to the next chunk to allocate
                     61:        Chunk::Row *link_row;
                     62: 
1.5     ! paf        63: private:
        !            64:        // last chank allocated count
        !            65:        int curr_chunk_rows;
        !            66: 
        !            67:        // string size
        !            68:        size_t fsize;
        !            69: 
        !            70:        // used rows in all chunks
        !            71:        int fused_rows;
        !            72: 
        !            73: private:
1.1       paf        74:        // new&constructors made private to enforce factory manufacturing at pool
                     75:        void *operator new(size_t size, Pool *apool);
                     76: 
                     77:        void construct(Pool *apool);
                     78:        String(Pool *apool) { 
                     79:                construct(apool); 
                     80:        }
                     81:        String(Pool *apool, char *src) {
                     82:                construct(apool);
                     83:                *this+=src;
                     84:        }
                     85: 
                     86:        bool chunk_is_full() {
                     87:                return append_here == link_row;
                     88:        }
                     89:        void expand();
1.5     ! paf        90: 
        !            91: private: //disabled
        !            92: 
        !            93:        String& operator = (String& src) { return *this; }
1.1       paf        94: 
                     95: public:
                     96: 
1.2       paf        97:        String(String& src);
1.5     ! paf        98:        size_t size() { return fsize; }
        !            99:        int used_rows() { return fused_rows; }
1.1       paf       100:        char *c_str();
                    101:        String& operator += (char *src);
1.2       paf       102:        bool operator == (String& src);
                    103: 
1.4       paf       104:        uint hash_code();
1.1       paf       105: };
                    106: 
                    107: #endif

E-mail: