Annotation of parser3/src/include/pa_pool.h, revision 1.22

1.1       paf         1: /*
1.22    ! paf         2:   $Id: pa_pool.h,v 1.21 2001/02/11 11:27:24 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: class String;
                     11: class Exception;
1.1       paf        12: 
                     13: class Pool {
                     14: public:
1.18      paf        15: 
                     16:        // Exception to report pool errors 
                     17:        Pool(Exception& aexception) : fexception(aexception) {}
                     18:        ~Pool() {}
                     19: 
                     20:        Exception& exception() { return fexception; }
                     21: 
                     22:        void *malloc(size_t size) {
                     23:                return check(real_malloc(size), size);
                     24:        }
                     25:        void *calloc(size_t size) {
                     26:                return check(real_calloc(size), size);
                     27:        }
1.8       paf        28: 
1.20      paf        29: protected: // implementation defined
1.18      paf        30: 
1.20      paf        31:     void *real_malloc(size_t size);
                     32:     void *real_calloc(size_t size);
1.17      paf        33: 
                     34: protected:
                     35: 
1.18      paf        36:        Exception& fexception;
1.17      paf        37: 
1.18      paf        38:        // checks whether mem allocated OK. throws exception otherwise
1.21      paf        39:        void *check(void *ptr, size_t size);
1.17      paf        40: 
1.8       paf        41: private: //disabled
                     42: 
1.18      paf        43:        // Pool(const Pool&) {}
1.16      paf        44:        Pool& operator = (const Pool&) { return *this; }
1.21      paf        45: };
                     46: 
                     47: class Pooled {
                     48: public:
                     49:        static void *operator new(size_t size, Pool& apool) { 
                     50:                return apool.malloc(size);
                     51:        }
                     52: 
1.22    ! paf        53:        Pooled(Pool& apool) : fpool(apool) {}
        !            54:        Pool& pool() const { return fpool; }
1.21      paf        55: 
                     56: protected:
                     57:        // the pool I'm allocated on
1.22    ! paf        58:        Pool& fpool;
1.1       paf        59: };
                     60: 
                     61: #endif

E-mail: