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

1.1       paf         1: /*
1.3     ! paf         2:   $Id: pa_array.h,v 1.2 2001/01/27 15:21:05 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"
                     24: 
                     25: class Pool;
                     26: 
                     27: class Array {
                     28: public:
                     29:        typedef void *Item;
                     30: 
                     31:        enum {
                     32:                CR_PREALLOCATED_COUNT=10,
                     33:                CR_GROW_PERCENT=60
                     34:        };
                     35: 
                     36: private:
                     37:        friend Pool;
                     38: 
                     39:        // the pool I'm allocated on
                     40:        Pool *pool;
                     41: 
                     42:        struct Chunk {
                     43:                // the number of rows in chunk
                     44:                int count;
                     45:                union Row {
                     46:                        Item item;
                     47:                        Chunk *link;  // link to the next chunk in chain
                     48:                } rows[1];
                     49:                // next rows are here
                     50:        }
                     51:                *head;  // the head chunk of the chunk chain
                     52: 
                     53:        // next append would write to this record
                     54:        Chunk::Row *append_here;
                     55:        
                     56:        // the address of place where lies address 
                     57:        // of the link to the next chunk to allocate
                     58:        Chunk::Row *link_row;
                     59: 
                     60: private:
                     61:        // last chank allocated count
                     62:        int curr_chunk_rows;
                     63: 
                     64:        // array size
                     65:        int fused_rows;
                     66: 
1.3     ! paf        67:        int cache_chunk_base;
        !            68:        Chunk *cache_chunk;
1.2       paf        69:        
1.1       paf        70: private:
                     71:        // new&constructors made private to enforce factory manufacturing at pool
                     72:        void *operator new(size_t size, Pool *apool);
                     73: 
                     74:        void construct(Pool *apool, int initial_rows);
                     75:        Array(Pool *apool) {
                     76:                construct(apool, CR_PREALLOCATED_COUNT); 
                     77:        }
                     78:        Array(Pool *apool, int initial_rows) {
                     79:                construct(apool, initial_rows); 
                     80:        }
                     81: 
                     82: 
                     83:        bool chunk_is_full() {
                     84:                return append_here == link_row;
                     85:        }
                     86:        void expand();
                     87: 
1.2       paf        88: public:
                     89: 
                     90:        int size() { return fused_rows; }
                     91:        Array& operator += (Item src);
                     92: 
                     93:        /*
                     94:        void put(int index, Item item);
                     95:        Item get(int index);
                     96:        */
                     97:        Item& operator [] (int index);
                     98: 
1.1       paf        99: private: //disabled
                    100: 
                    101:        Array& operator = (Array& src) { return *this; }
                    102:        Array(Array& src) {}
                    103: };
                    104: 
                    105: #endif

E-mail: