Annotation of parser3/src/main/pa_pool.C, revision 1.59.4.1

1.13      paf         1: /** @file
1.14      paf         2:        Parser: pool class.
                      3: 
1.59      paf         4:        Copyright (c) 2001, 2003 ArtLebedev Group (http://www.artlebedev.com)
1.51      paf         5:        Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
1.54      paf         6: */
1.14      paf         7: 
1.59.4.1! paf         8: static const char* IDENT_POOL_C="$Date: 2003/01/21 15:51:14 $";
1.1       paf         9: 
                     10: #include "pa_pool.h"
1.7       paf        11: #include "pa_exception.h"
1.22      parser     12: #include "pa_common.h"
1.41      paf        13: #include "pa_sapi.h"
1.46      paf        14: #include "pa_charset.h"
1.22      parser     15: 
                     16: Pool::Pool(void *astorage) : 
1.43      paf        17:        fstorage(astorage), fcontext(0)1.46      paf        18:        ftotal_allocated(0), ftotal_times(0),
                     19:        source_charset(0), client_charset(0)
1.26      parser     20:        {
1.59.4.1! paf        21:        real_init();
        !            22: }
        !            23: 
        !            24: Pool::~Pool() {
        !            25:        real_finit();
1.22      parser     26: }
1.56      paf        27: 
                     28: void *Pool::copy(const void *buf, const size_t size) {
1.58      paf        29:        if(!buf || !size)
                     30:                return 0;
                     31: 
1.56      paf        32:        void *result=malloc(size);
                     33:        memcpy(result, buf, size);
                     34:        return result;
                     35: }
                     36: 
                     37: char *Pool::copy(const char *cstr) {
                     38:        if(cstr) {
                     39:                size_t size=strlen(cstr)+1;
                     40:                return (char *)copy(cstr, size);
                     41:        }
                     42:        return 0;
                     43: }
                     44: 
1.1       paf        45: 
1.21      parser     46: void Pool::fail_alloc(size_t size) const {
1.45      paf        47:        SAPI::die("out of pool memory: failed to allocate %u bytes; "
                     48:                "already allocated on pool: %u bytes in %u times", 
1.41      paf        49:                size, 
                     50:                ftotal_allocated, ftotal_times);
1.7       paf        51: }
1.21      parser     52: 
                     53: void Pool::fail_register_cleanup() const {
1.41      paf        54:        SAPI::die("failed to register cleanup");
1.22      parser     55: }
                     56: 
1.46      paf        57: void Pool::set_source_charset(Charset& acharset) { 
                     58:        source_charset=&acharset; 
                     59: }
                     60: Charset& Pool::get_source_charset() { 
                     61:        if(!source_charset)
1.52      paf        62:                throw Exception(0,
1.46      paf        63:                        0,
                     64:                        "no source charset defined yet");
                     65:        return *source_charset; 
1.22      parser     66: }
                     67: 
1.46      paf        68: void Pool::set_client_charset(Charset& acharset) { 
                     69:        client_charset=&acharset; 
                     70: }
                     71: Charset& Pool::get_client_charset() { 
                     72:        if(!client_charset)
1.52      paf        73:                throw Exception(0,
1.46      paf        74:                        0,
                     75:                        "no client charset defined yet");
                     76:        return *client_charset; 
1.22      parser     77: }
                     78: 
1.46      paf        79: #ifdef XML
1.49      paf        80: 
                     81: const char *Pool::transcode_cstr(xmlChar *s) {
                     82:        return get_source_charset().transcode_cstr(s); 
                     83: }
                     84: 
1.57      paf        85: String& Pool::transcode(xmlChar *s
                     86: #ifndef NO_STRING_ORIGIN
                     87:                , const String *origin
                     88: #endif
                     89:                                                ) {
                     90:        return get_source_charset().transcode(s, origin); 
1.49      paf        91: }
1.46      paf        92: 
1.47      paf        93: const char *Pool::transcode_cstr(GdomeDOMString *s) { 
1.46      paf        94:        return get_source_charset().transcode_cstr(s); 
                     95: }
1.22      parser     96: 
1.57      paf        97: String& Pool::transcode(GdomeDOMString *s
                     98: #ifndef NO_STRING_ORIGIN
                     99:                , const String *origin
                    100: #endif
                    101:        ) { 
                    102:        return get_source_charset().transcode(s, origin);
1.53      paf       103: }
                    104: 
                    105: xmlChar *Pool::transcode_buf2xchar(const char *buf, size_t buf_size) {
                    106:        return get_source_charset().transcode_buf2xchar(buf, buf_size); 
1.32      parser    107: }
                    108: 
1.48      paf       109: GdomeDOMString_auto_ptr Pool::transcode(const String& s) {
1.46      paf       110:        return get_source_charset().transcode(s); 
1.32      parser    111: }
                    112: 
1.26      parser    113: 
                    114: #endif

E-mail: