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