Diff for /parser3/src/main/pa_pool.C between versions 1.54 and 1.62

version 1.54, 2002/08/01 11:26:50 version 1.62, 2003/11/20 16:34:26
Line 1 Line 1
 /** @file  /** @file
         Parser: pool class.          Parser: pool class.
   
         Copyright (c) 2001, 2002 ArtLebedev Group (http://www.artlebedev.com)          Copyright (c) 2001, 2003 ArtLebedev Group (http://www.artlebedev.com)
         Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)          Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
 */  */
   
 static const char* IDENT_POOL_C="$Id$";  static const char * const IDENT_POOL_C="$Date$";
   
 #include "pa_pool.h"  #include "pa_pool.h"
 #include "pa_exception.h"  #include "pa_exception.h"
Line 13  static const char* IDENT_POOL_C="$Id$"; Line 13  static const char* IDENT_POOL_C="$Id$";
 #include "pa_sapi.h"  #include "pa_sapi.h"
 #include "pa_charset.h"  #include "pa_charset.h"
   
 Pool::Pool(void *astorage) :   // Pool
         fstorage(astorage), fcontext(0)  
         ftotal_allocated(0), ftotal_times(0),  
         source_charset(0), client_charset(0)  
         {  
 }  
   
 void Pool::fail_alloc(size_t size) const {  Pool::Pool(){}
         SAPI::die("out of pool memory: failed to allocate %u bytes; "  
                 "already allocated on pool: %u bytes in %u times",   
                 size,   
                 ftotal_allocated, ftotal_times);  
 }  
   
 void Pool::fail_register_cleanup() const {  static void cleanup(Pool::Cleanup item, int) {
         SAPI::die("failed to register cleanup");          if(item.cleanup)
                   item.cleanup(item.data);
 }  }
   Pool::~Pool() {
 void Pool::set_source_charset(Charset& acharset) {           //__asm__("int3");
         source_charset=&acharset;           //_asm int 3;
 }          //fprintf(stderr, "cleanups: %d\n", cleanups.size());
 Charset& Pool::get_source_charset() {           // cleanups first, because they use some object's memory pointers
         if(!source_charset)          cleanups.for_each(cleanup, 0);
                 throw Exception(0,  
                         0,  
                         "no source charset defined yet");  
         return *source_charset;   
 }  }
   
 void Pool::set_client_charset(Charset& acharset) {   void Pool::register_cleanup(void (*cleanup) (void *), void *data) {
         client_charset=&acharset;           cleanups+=Cleanup(cleanup, data);
 }  
 Charset& Pool::get_client_charset() {   
         if(!client_charset)  
                 throw Exception(0,  
                         0,  
                         "no client charset defined yet");  
         return *client_charset;   
 }  }
   
 #ifdef XML  static void unregister_cleanup(Pool::Cleanup& item, void* cleanup_data) {
           if(item.data==cleanup_data)
 const char *Pool::transcode_cstr(xmlChar *s) {                  item.cleanup=0;
         return get_source_charset().transcode_cstr(s);   
 }  }
   void Pool::unregister_cleanup(void *cleanup_data) {
 String& Pool::transcode(xmlChar *s) {          cleanups.for_each_ref(::unregister_cleanup, cleanup_data);
         return get_source_charset().transcode(s);   
 }  }
   
 const char *Pool::transcode_cstr(GdomeDOMString *s) {   // Pooled
         return get_source_charset().transcode_cstr(s);   
 }  
   
 String& Pool::transcode(GdomeDOMString *s) {   static void cleanup(void *data) {
         return get_source_charset().transcode(s);           static_cast<Pooled*>(data)->~Pooled();
 }  }
   
 xmlChar *Pool::transcode_buf2xchar(const char *buf, size_t buf_size) {  Pooled::Pooled(Pool& apool): fpool(apool) {
         return get_source_charset().transcode_buf2xchar(buf, buf_size);           fpool.register_cleanup(cleanup, this);
 }  }
   
 GdomeDOMString_auto_ptr Pool::transcode(const String& s) {  /// Sole: this got called automatically from Pool::~Pool()
         return get_source_charset().transcode(s);   Pooled::~Pooled() {
           fpool.unregister_cleanup(this);
 }  }
   
   
 #endif  

Removed from v.1.54  
changed lines
  Added in v.1.62


E-mail: