Annotation of parser3/src/include/pa_array.h, revision 1.11

1.1       paf         1: /*
1.11    ! paf         2:   $Id: pa_array.h,v 1.10 2001/01/29 16:57:08 paf Exp $
1.1       paf         3: */
                      4: 
                      5: /*
                      6: 
                      7:        Array               Chunk0
                      8:        ======              ========
                      9:        head--------------->[ptr]
                     10:        append_here-------->[ptr]
                     11:        link_row            ........
                     12:                        .                       .
                     13:                        .                       [ptr]
                     14:                        ...........>[link to the next chunk]
                     15: 
                     16: */
                     17: 
                     18: #ifndef PA_ARRAY_H
                     19: #define PA_ARRAY_H
                     20: 
                     21: #include <stddef.h>
                     22: 
                     23: #include "pa_types.h"
1.11    ! paf        24: #include "pa_string.h"
1.1       paf        25: 
                     26: class Pool;
                     27: 
1.10      paf        28: class Array {
1.1       paf        29: public:
1.7       paf        30: 
1.11    ! paf        31:        typedef void Item;
1.10      paf        32: 
1.1       paf        33:        enum {
1.7       paf        34:                CR_INITIAL_ROWS_DEFAULT=10,
1.1       paf        35:                CR_GROW_PERCENT=60
                     36:        };
                     37: 
1.6       paf        38: public:
                     39: 
1.11    ! paf        40:        void *operator new(size_t size, Pool& apool);
        !            41:        Array(Pool& apool, int initial_rows=CR_INITIAL_ROWS_DEFAULT);
1.7       paf        42: 
1.6       paf        43:        int size() { return fused_rows; }
1.11    ! paf        44:        Array& operator += (Item *src);
        !            45:        Array& append_array(Array& src);
        !            46:        Item *get(int index);
        !            47:        char *get_cstr(int index) { return static_cast<char *>(get(index)); }
        !            48:        String *get_string(int index) { return static_cast<String *>(get(index)); }
1.6       paf        49: 
1.7       paf        50: protected:
1.1       paf        51: 
                     52:        // the pool I'm allocated on
1.11    ! paf        53:        Pool& pool;
1.1       paf        54: 
1.7       paf        55: private:
                     56: 
1.1       paf        57:        struct Chunk {
                     58:                // the number of rows in chunk
                     59:                int count;
                     60:                union Row {
1.11    ! paf        61:                        Item *item;
1.1       paf        62:                        Chunk *link;  // link to the next chunk in chain
                     63:                } rows[1];
                     64:                // next rows are here
                     65:        }
                     66:                *head;  // the head chunk of the chunk chain
                     67: 
1.5       paf        68:        // last allocated chunk
                     69:        // helps appending Arrays
                     70:        Chunk *tail;
                     71: 
1.1       paf        72:        // next append would write to this record
                     73:        Chunk::Row *append_here;
                     74:        
                     75:        // the address of place where lies address 
                     76:        // of the link to the next chunk to allocate
                     77:        Chunk::Row *link_row;
                     78: 
                     79: private:
1.7       paf        80: 
1.1       paf        81:        // array size
                     82:        int fused_rows;
                     83: 
1.3       paf        84:        int cache_chunk_base;
                     85:        Chunk *cache_chunk;
1.2       paf        86:        
1.1       paf        87: private:
                     88: 
                     89:        bool chunk_is_full() {
                     90:                return append_here == link_row;
                     91:        }
1.5       paf        92:        void expand(int chunk_rows);
1.2       paf        93: 
1.1       paf        94: private: //disabled
                     95: 
1.11    ! paf        96:        //Array(Array&) { }
1.7       paf        97:        Array& operator = (Array&) { return *this; }
1.1       paf        98: };
                     99: 
                    100: #endif

E-mail: