Diff for /parser3/src/include/pa_pool.h between versions 1.42 and 1.56

version 1.42, 2001/03/22 17:13:43 version 1.56, 2001/09/21 07:30:25
Line 11 Line 11
 #ifndef PA_POOL_H  #ifndef PA_POOL_H
 #define PA_POOL_H  #define PA_POOL_H
   
 #include <stddef.h>  #include "pa_config_includes.h"
   
   #include <XalanDOM/XalanDOMString.hpp>
   #include <util/TransService.hpp>
   #include <PlatformSupport/XSLException.hpp>
   
   
   // forwards
   
 class Exception;  class Exception;
 class Temp_exception;  class Temp_exception;
   class String;
   
 /**   /** 
         Pool mechanizm allows users not to free up allocated memory,          Pool mechanizm allows users not to free up allocated memory,
Line 30  class Pool { Line 38  class Pool {
         friend Temp_exception;          friend Temp_exception;
 public:  public:
   
         Pool() : fstorage(0), fcontext(0), fexception(0) {}          Pool(void *astorage);
         ~Pool();          ~Pool();
   
         void set_storage(void *astorage) { fstorage=astorage; }  
         void set_context(void *acontext) { fcontext=acontext; }          void set_context(void *acontext) { fcontext=acontext; }
   
         void *storage() { return fstorage; }  
         void *context() { return fcontext; }          void *context() { return fcontext; }
   
         /// current exception object of the pool          void set_tag(void *atag) { ftag=atag; }
         Exception& exception() const { return *fexception; }          void *tag() { return ftag; }
   
         /// allocates some bytes on pool          /// allocates some bytes on pool
         void *malloc(size_t size) {          void *malloc(size_t size/*, int place=0*/) {
                 return check(real_malloc(size), size);                  return check(real_malloc(size/*, place*/), size);
         }          }
         /// allocates some bytes clearing them with zeros          /// allocates some bytes clearing them with zeros
         void *calloc(size_t size) {          void *calloc(size_t size) {
                 return check(real_calloc(size), size);                  return check(real_calloc(size), size);
         }          }
   
           /// registers a routine to clean up non-pooled allocations
           void register_cleanup(void (*cleanup) (void *), void *data) {
                   if(!real_register_cleanup(cleanup, data))
                           fail_register_cleanup();
           }
   
           /// current exception object of the pool
           Exception& exception() const { return *fexception; }
   
           /// resets transcoder if they change charset 
           void set_charset(const String &charset);
           /// converts Xalan string to char *
           const char *transcode(const XalanDOMString& s);
           /// converts XSL exception to parser exception
           void _throw(const String *source, const XSLException& e);
   
   private:
   
           void set_charset(const char *new_scharset);
           void update_transcoder();
   
 private:  private:
   
         void *fstorage;          void *fstorage;
         void *fcontext;          void *fcontext;
           void *ftag;
           const String *scharset; const char *charset;
           XMLTranscoder *transcoder;
   
 private: // implementation defined  private: 
           
     void *real_malloc(size_t size);          //{
           /// @name implementation defined
       void *real_malloc(size_t size/*, int place*/);
     void *real_calloc(size_t size);      void *real_calloc(size_t size);
           bool real_register_cleanup(void (*cleanup) (void *), void *data);
           //}
   
 private:   private: 
   
Line 68  private: Line 101  private:
                 if(ptr)                  if(ptr)
                         return ptr;                          return ptr;
   
                 fail(size);                  fail_alloc(size);
   
                 // never reached                  // never reached
                 return 0;                  return 0;
         }          }
         /// throws proper exception          /// throws allocation exception
         void fail(size_t size) const;          void fail_alloc(size_t size) const;
   
           /// throws register cleanup exception
           void fail_register_cleanup() const;
   
 private: // exception handling  private: // exception handling
   
         // exception replacement mechanism is 'protected' from direct usage          // exception replacement mechanism is 'private'zed from direct usage
         // Temp_exception object enforces paired set/restore          // Temp_exception object enforces paired set/restore
         Exception *set_exception(Exception *e){          Exception *set_exception(Exception *e){
                 Exception *r=fexception;                  Exception *r=fexception;
Line 109  private: //disabled Line 145  private: //disabled
 */  */
 class Pooled {  class Pooled {
         // the pool i'm allocated on          // the pool i'm allocated on
         Pool& fpool;          Pool *fpool;
 public:  public:
   
         /// the Pooled-sole: Pooled instances can be allocated in Pool rather then on heap          /// the Pooled-sole: Pooled instances can be allocated in Pool rather then on heap
         static void *operator new(size_t size, Pool& apool) {           static void *operator new(size_t size, Pool& apool) { 
                 return apool.malloc(size);                  return apool.malloc(size/*, 1*/);
         }          }
   
         Pooled(Pool& apool) : fpool(apool) {          Pooled(Pool& apool) : fpool(&apool) {}
         }  
   
         /// my pool          /// my pool
         Pool& pool() const { return fpool; }          Pool& pool() const { return *fpool; }
   
           /** used for moving objects from one pool to another. 
                   in between object can have no pool and can not be used
                   @see SQL_Driver_manager
           */
           void set_pool(Pool *apool) { fpool=apool; }
   
           /// useful wrapper around pool
           void *malloc(size_t size) const { return fpool->malloc(size); }
           /// useful wrapper around pool
           void *calloc(size_t size) const { return fpool->calloc(size); }
         /// useful wrapper around pool          /// useful wrapper around pool
         void *malloc(size_t size) const { return fpool.malloc(size); }          void register_cleanup(void (*cleanup) (void *), void *data) { 
                   fpool->register_cleanup(cleanup, data);
           }
           /// useful wrapper around pool
           Exception& exception() const { return fpool->exception(); }
         /// useful wrapper around pool          /// useful wrapper around pool
         void *calloc(size_t size) const { return fpool.calloc(size); }          const char *transcode(const XalanDOMString& s) { return fpool->transcode(s); }
         /// useful wrapper around pool          /// useful wrapper around pool
         Exception& exception() const { return fpool.exception(); }          void _throw(const String *source, const XSLException& e) { fpool->_throw(source, e); }
 };  };
 /// useful macro for creating objects on current Pooled object Pooled::pool()  /// useful macro for creating objects on current Pooled object Pooled::pool()
 #define NEW new(pool())  #define NEW new(pool())
Line 191  public: Line 240  public:
 #define PTHROW XTHROW(pool.exception())  #define PTHROW XTHROW(pool.exception())
 #define PCATCH(e) XCATCH(e)  #define PCATCH(e) XCATCH(e)
 #define PEND_CATCH XEND_CATCH   #define PEND_CATCH XEND_CATCH 
   
 #define RTHROW XTHROW(r.pool().exception())  
 //@}  //@}
   
 #endif  #endif

Removed from v.1.42  
changed lines
  Added in v.1.56


E-mail: