--- parser3/src/include/pa_pool.h 2001/01/30 13:07:31 1.18 +++ parser3/src/include/pa_pool.h 2001/02/20 18:45:51 1.22 @@ -1,5 +1,5 @@ /* - $Id: pa_pool.h,v 1.18 2001/01/30 13:07:31 paf Exp $ + $Id: pa_pool.h,v 1.22 2001/02/20 18:45:51 paf Exp $ */ #ifndef PA_POOL_H @@ -7,11 +7,8 @@ #include -#include "pa_string.h" -#include "pa_hash.h" -#include "pa_array.h" -//#include "pa_table.h" -#include "pa_exception.h" +class String; +class Exception; class Pool { public: @@ -29,43 +26,17 @@ public: return check(real_calloc(size), size); } - String& make_string() { - return *new(*this) String(*this); - } - Hash& make_hash() { - return *new(*this) Hash(*this, false); - } - Hash& make_thread_safe_hash() { - return *new(*this) Hash(*this, true); - } - Array& make_array() { - return *new(*this) Array(*this); - } - Array& make_array(int initial_rows) { - return *new(*this) Array(*this, initial_rows); - } - /*Table& make_table(char *afile, uint aline, Array *acolumns, int initial_rows) { - return *new(this) Table(this, afile, aline, acolumns, initial_rows); - }*/ - -protected: // pure virtuals +protected: // implementation defined - virtual void *real_malloc(size_t size)=0; - virtual void *real_calloc(size_t size)=0; + void *real_malloc(size_t size); + void *real_calloc(size_t size); protected: Exception& fexception; // checks whether mem allocated OK. throws exception otherwise - void *check(void *ptr, size_t size) { - if(!ptr) - fexception.raise(0, 0, - 0, - "allocating %ud bytes", size); - - return ptr; - } + void *check(void *ptr, size_t size); private: //disabled @@ -73,4 +44,18 @@ private: //disabled Pool& operator = (const Pool&) { return *this; } }; +class Pooled { +public: + static void *operator new(size_t size, Pool& apool) { + return apool.malloc(size); + } + + Pooled(Pool& apool) : fpool(apool) {} + Pool& pool() const { return fpool; } + +protected: + // the pool I'm allocated on + Pool& fpool; +}; + #endif