--- parser3/src/include/pa_pool.h 2001/01/29 20:46:22 1.16 +++ parser3/src/include/pa_pool.h 2001/01/30 13:07:31 1.18 @@ -1,5 +1,5 @@ /* - $Id: pa_pool.h,v 1.16 2001/01/29 20:46:22 paf Exp $ + $Id: pa_pool.h,v 1.18 2001/01/30 13:07:31 paf Exp $ */ #ifndef PA_POOL_H @@ -11,13 +11,23 @@ #include "pa_hash.h" #include "pa_array.h" //#include "pa_table.h" +#include "pa_exception.h" class Pool { public: - Pool(); - ~Pool(); - void *malloc(size_t size); - void *calloc(size_t size); + + // 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); + } + void *calloc(size_t size) { + return check(real_calloc(size), size); + } String& make_string() { return *new(*this) String(*this); @@ -38,9 +48,28 @@ public: return *new(this) Table(this, afile, aline, acolumns, initial_rows); }*/ +protected: // pure virtuals + + virtual void *real_malloc(size_t size)=0; + virtual void *real_calloc(size_t size)=0; + +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; + } + private: //disabled - Pool(Pool&) {} + // Pool(const Pool&) {} Pool& operator = (const Pool&) { return *this; } };