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

1.34      paf         1: /** @file
1.36      paf         2:        Parser: pool class decl.
                      3: 
1.86      paf         4:        Copyright (c) 2001, 2003 ArtLebedev Group (http://www.artlebedev.com)
1.36      paf         5: 
1.78      paf         6:        Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
1.1       paf         7: */
                      8: 
                      9: #ifndef PA_POOL_H
                     10: #define PA_POOL_H
1.82      paf        11: 
1.87      paf        12: static const char* IDENT_POOL_H="$Date: 2003/01/21 15:51:10 $";
1.1       paf        13: 
1.52      parser     14: #include "pa_config_includes.h"
1.88    ! paf        15: #include "pa_array.h"
1.55      parser     16: 
1.35      paf        17: /** 
1.88    ! paf        18:        Pool mechanizm allows users not to free up allocated objects,
1.34      paf        19:        leaving that problem to 'pools'.
                     20: 
1.38      paf        21:        @see Pooled
1.34      paf        22: */
1.47      paf        23: 
1.1       paf        24: class Pool {
                     25: public:
1.18      paf        26: 
1.88    ! paf        27:        struct Cleanup {
        !            28:                void (*cleanup) (void *);
        !            29:                void *data;
        !            30: 
        !            31:                Cleanup(void (*acleanup) (void *), void *adata): cleanup(acleanup), data(adata) {}
        !            32:        };
1.18      paf        33: 
1.88    ! paf        34:        Pool();
        !            35:        ~Pool();
1.39      paf        36: 
1.53      parser     37:        /// registers a routine to clean up non-pooled allocations
1.88    ! paf        38:        void register_cleanup(void (*cleanup) (void *), void *data);
        !            39:        /// unregister it, looking it up by it's data
        !            40:        void unregister_cleanup(void *cleanup_data);
1.60      parser     41: 
1.39      paf        42: private:
                     43: 
1.88    ! paf        44:        Array<Cleanup> cleanups;
1.8       paf        45: 
1.50      parser     46: private: 
                     47:        
                     48:        //{
                     49:        /// @name implementation defined
1.54      parser     50:        bool real_register_cleanup(void (*cleanup) (void *), void *data);
1.50      parser     51:        //}
1.17      paf        52: 
1.23      paf        53: private: 
1.17      paf        54: 
1.54      parser     55:        /// throws register cleanup exception
                     56:        void fail_register_cleanup() const;
1.70      paf        57: 
1.8       paf        58: private: //disabled
                     59: 
1.64      parser     60:        Pool(const Pool&);
                     61:        Pool& operator= (const Pool&);
1.21      paf        62: };
                     63: 
1.35      paf        64: /** 
1.34      paf        65:        Base for all classes that are allocated in 'pools'.
1.88    ! paf        66:        Holds Pool object.
1.34      paf        67: */
1.21      paf        68: class Pooled {
1.23      paf        69:        // the pool i'm allocated on
1.88    ! paf        70:        Pool& fpool;
1.21      paf        71: public:
1.37      paf        72: 
1.88    ! paf        73:        Pooled(Pool& apool);
1.23      paf        74: 
1.34      paf        75:        /// my pool
1.88    ! paf        76:        //Pool& pool() const { return *fpool; }
1.49      paf        77: 
1.88    ! paf        78:        /// Sole: this got called automatically from Pool::~Pool()
        !            79:        virtual ~Pooled();
1.21      paf        80: 
1.23      paf        81: };
1.1       paf        82: 
                     83: #endif

E-mail: