--- parser3/src/include/pa_pool.h 2001/01/26 18:55:55 1.6 +++ parser3/src/include/pa_pool.h 2001/02/20 18:45:51 1.22 @@ -1,5 +1,5 @@ /* - $Id: pa_pool.h,v 1.6 2001/01/26 18:55:55 paf Exp $ + $Id: pa_pool.h,v 1.22 2001/02/20 18:45:51 paf Exp $ */ #ifndef PA_POOL_H @@ -7,26 +7,55 @@ #include -#include "pa_string.h" -#include "pa_hash.h" +class String; +class Exception; class Pool { public: - Pool(); - ~Pool(); - void *malloc(size_t size); - void *calloc(size_t size); - String *make_string() { - return new(this) String(this); + // Exception to report pool errors + Pool(Exception& aexception) : fexception(aexception) {} + ~Pool() {} + + Exception& exception() { return fexception; } + + void *malloc(size_t size) { + return check(real_malloc(size), size); } - String *make_string(char *src) { - return new(this) String(this, src); + void *calloc(size_t size) { + return check(real_calloc(size), size); } - Hash *make_hash() { - return new(this) Hash(this); +protected: // implementation defined + + 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); + +private: //disabled + + // Pool(const Pool&) {} + 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