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

1.1     ! paf         1: /*
        !             2:   $Id: pa_string.h,v 1.5 2001/01/27 12:04:53 paf Exp $
        !             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: 
        !            67: private:
        !            68:        // new&constructors made private to enforce factory manufacturing at pool
        !            69:        void *operator new(size_t size, Pool *apool);
        !            70: 
        !            71:        void construct(Pool *apool, int initial_rows);
        !            72:        Array(Pool *apool) {
        !            73:                construct(apool, CR_PREALLOCATED_COUNT); 
        !            74:        }
        !            75:        Array(Pool *apool, int initial_rows) {
        !            76:                construct(apool, initial_rows); 
        !            77:        }
        !            78: 
        !            79: 
        !            80:        bool chunk_is_full() {
        !            81:                return append_here == link_row;
        !            82:        }
        !            83:        void expand();
        !            84: 
        !            85: private: //disabled
        !            86: 
        !            87:        Array& operator = (Array& src) { return *this; }
        !            88:        Array(Array& src) {}
        !            89: 
        !            90: public:
        !            91: 
        !            92:        int size() { return fused_rows; }
        !            93:        Array& operator += (Item src);
        !            94: };
        !            95: 
        !            96: #endif

E-mail: