--- parser3/src/include/pa_pool.h 2001/03/19 15:29:38 1.34 +++ parser3/src/include/pa_pool.h 2001/03/22 16:38:19 1.41 @@ -1,9 +1,11 @@ /** @file - Parser + Parser: pool class decl. + Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) + Author: Alexander Petrosyan (http://design.ru/paf) - $Id: pa_pool.h,v 1.34 2001/03/19 15:29:38 paf Exp $ + $Id: pa_pool.h,v 1.41 2001/03/22 16:38:19 paf Exp $ */ #ifndef PA_POOL_H @@ -14,20 +16,30 @@ class Exception; class Temp_exception; -/** @brief +/** Pool mechanizm allows users not to free up allocated memory, leaving that problem to 'pools'. Also holds Exception object, which can be temporary set using Temp_exception auto-object. + + @see Pooled */ class Pool { friend Temp_exception; public: - Pool() : fexception(0) {} - ~Pool() {} + Pool() : fstorage(0), fcontext(0), ftag(0), fexception(0) {} + ~Pool(); + + void set_storage(void *astorage) { fstorage=astorage; } + void set_context(void *acontext) { fcontext=acontext; } + void set_tag(void *atag) { ftag=atag; } + + void *storage() { return fstorage; } + void *context() { return fcontext; } + void *tag() { return ftag; } /// current exception object of the pool Exception& exception() const { return *fexception; } @@ -41,6 +53,12 @@ public: return check(real_calloc(size), size); } +private: + + void *fstorage; + void *fcontext; + void *ftag; + private: // implementation defined void *real_malloc(size_t size); @@ -85,16 +103,19 @@ private: //disabled Pool& operator = (const Pool&) { return *this; } }; -/** @brief +/** Base for all classes that are allocated in 'pools'. Holds Pool object. Contains useful wrappers to it's methods. + + @see NEW, Temp_exception */ class Pooled { // the pool i'm allocated on Pool& fpool; public: - + + /// the Pooled-sole: Pooled instances can be allocated in Pool rather then on heap static void *operator new(size_t size, Pool& apool) { return apool.malloc(size); } @@ -115,22 +136,24 @@ public: /// useful macro for creating objects on current Pooled object Pooled::pool() #define NEW new(pool()) -/** @brief +/** Auto-object used for temporary changing Pool's exception(). Use by with these macros: - \code + @code TRY { - ... + // ... if(?) THROW(?); - ...; + // ... } CATCH(e) { - code, using e fields - e.comment() + // code, using e fields + // e.comment() } END_CATCH - \endcode + @endcode + + @see TRY, THROW */ class Temp_exception { Pool& fpool;