--- parser3/src/include/pa_array.h 2001/01/29 10:15:14 1.5 +++ parser3/src/include/pa_array.h 2001/01/29 16:37:57 1.8 @@ -1,5 +1,5 @@ /* - $Id: pa_array.h,v 1.5 2001/01/29 10:15:14 paf Exp $ + $Id: pa_array.h,v 1.8 2001/01/29 16:37:57 paf Exp $ */ /* @@ -24,21 +24,31 @@ class Pool; -class Array { +template class Array { public: - typedef void *Item; enum { - CR_PREALLOCATED_COUNT=10, + CR_INITIAL_ROWS_DEFAULT=10, CR_GROW_PERCENT=60 }; -private: - friend Pool; +public: + + void *operator new(size_t size, Pool *apool); + Array(Pool *apool, int initial_rows=CR_INITIAL_ROWS_DEFAULT); + + int size() { return fused_rows; } + Array& operator += (Item src); + Array& operator += (Array& src); + Item& operator [] (int index); + +protected: // the pool I'm allocated on Pool *pool; +private: + struct Chunk { // the number of rows in chunk int count; @@ -62,6 +72,7 @@ private: Chunk::Row *link_row; private: + // array size int fused_rows; @@ -69,34 +80,17 @@ private: Chunk *cache_chunk; private: - // new&constructors made private to enforce factory manufacturing at pool - void *operator new(size_t size, Pool *apool); - - void construct(Pool *apool, int initial_rows); - Array(Pool *apool) { - construct(apool, CR_PREALLOCATED_COUNT); - } - Array(Pool *apool, int initial_rows) { - construct(apool, initial_rows); - } - bool chunk_is_full() { return append_here == link_row; } void expand(int chunk_rows); -public: - - int size() { return fused_rows; } - Array& operator += (Item src); - Item& operator [] (int index); - Array& operator += (Array& src); - private: //disabled - Array& operator = (Array& src) { return *this; } - Array(Array& src) {} + Array() {} + Array(Array&) {} + Array& operator = (Array&) { return *this; } }; #endif