Annotation of parser3/src/include/pa_pool.h, revision 1.21
1.1 paf 1: /*
1.21 ! paf 2: $Id: pa_pool.h,v 1.20 2001/01/30 14:57:41 paf Exp $
1.1 paf 3: */
4:
5: #ifndef PA_POOL_H
6: #define PA_POOL_H
7:
8: #include <stddef.h>
9:
1.21 ! paf 10: ///#include "pa_string.h"
! 11: ///#include "pa_hash.h"
! 12: ///#include "pa_array.h"
1.13 paf 13: //#include "pa_table.h"
1.21 ! paf 14: //#include "pa_exception.h"
! 15:
! 16: class String;
! 17: class Exception;
1.1 paf 18:
19: class Pool {
20: public:
1.18 paf 21:
22: // Exception to report pool errors
23: Pool(Exception& aexception) : fexception(aexception) {}
24: ~Pool() {}
25:
26: Exception& exception() { return fexception; }
27:
28: void *malloc(size_t size) {
29: return check(real_malloc(size), size);
30: }
31: void *calloc(size_t size) {
32: return check(real_calloc(size), size);
33: }
1.21 ! paf 34: /*
1.15 paf 35: String& make_string() {
36: return *new(*this) String(*this);
1.5 paf 37: }
1.9 paf 38: Hash& make_hash() {
1.15 paf 39: return *new(*this) Hash(*this, false);
1.10 paf 40: }
41: Hash& make_thread_safe_hash() {
1.15 paf 42: return *new(*this) Hash(*this, true);
1.7 paf 43: }
1.14 paf 44: Array& make_array() {
1.15 paf 45: return *new(*this) Array(*this);
1.7 paf 46: }
1.9 paf 47: Array& make_array(int initial_rows) {
1.15 paf 48: return *new(*this) Array(*this, initial_rows);
1.14 paf 49: }
1.21 ! paf 50: */
! 51:
1.13 paf 52: /*Table& make_table(char *afile, uint aline, Array *acolumns, int initial_rows) {
1.12 paf 53: return *new(this) Table(this, afile, aline, acolumns, initial_rows);
1.13 paf 54: }*/
1.8 paf 55:
1.20 paf 56: protected: // implementation defined
1.18 paf 57:
1.20 paf 58: void *real_malloc(size_t size);
59: void *real_calloc(size_t size);
1.17 paf 60:
61: protected:
62:
1.18 paf 63: Exception& fexception;
1.17 paf 64:
1.18 paf 65: // checks whether mem allocated OK. throws exception otherwise
1.21 ! paf 66: void *check(void *ptr, size_t size);
1.17 paf 67:
1.8 paf 68: private: //disabled
69:
1.18 paf 70: // Pool(const Pool&) {}
1.16 paf 71: Pool& operator = (const Pool&) { return *this; }
1.21 ! paf 72: };
! 73:
! 74: class Pooled {
! 75: public:
! 76: static void *operator new(size_t size, Pool& apool) {
! 77: return apool.malloc(size);
! 78: }
! 79:
! 80: Pooled(Pool& apool) : pool(apool) {}
! 81:
! 82: protected:
! 83: // the pool I'm allocated on
! 84: Pool& pool;
1.1 paf 85: };
86:
87: #endif
E-mail: