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

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    ! paf         8: static const char* IDENT_POOL_C="$Date: 2002/12/24 09:55:34 $";
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.22      parser     21: }
1.56      paf        22: 
                     23: void *Pool::copy(const void *buf, const size_t size) {
1.58      paf        24:        if(!buf || !size)
                     25:                return 0;
                     26: 
1.56      paf        27:        void *result=malloc(size);
                     28:        memcpy(result, buf, size);
                     29:        return result;
                     30: }
                     31: 
                     32: char *Pool::copy(const char *cstr) {
                     33:        if(cstr) {
                     34:                size_t size=strlen(cstr)+1;
                     35:                return (char *)copy(cstr, size);
                     36:        }
                     37:        return 0;
                     38: }
                     39: 
1.1       paf        40: 
1.21      parser     41: void Pool::fail_alloc(size_t size) const {
1.45      paf        42:        SAPI::die("out of pool memory: failed to allocate %u bytes; "
                     43:                "already allocated on pool: %u bytes in %u times", 
1.41      paf        44:                size, 
                     45:                ftotal_allocated, ftotal_times);
1.7       paf        46: }
1.21      parser     47: 
                     48: void Pool::fail_register_cleanup() const {
1.41      paf        49:        SAPI::die("failed to register cleanup");
1.22      parser     50: }
                     51: 
1.46      paf        52: void Pool::set_source_charset(Charset& acharset) { 
                     53:        source_charset=&acharset; 
                     54: }
                     55: Charset& Pool::get_source_charset() { 
                     56:        if(!source_charset)
1.52      paf        57:                throw Exception(0,
1.46      paf        58:                        0,
                     59:                        "no source charset defined yet");
                     60:        return *source_charset; 
1.22      parser     61: }
                     62: 
1.46      paf        63: void Pool::set_client_charset(Charset& acharset) { 
                     64:        client_charset=&acharset; 
                     65: }
                     66: Charset& Pool::get_client_charset() { 
                     67:        if(!client_charset)
1.52      paf        68:                throw Exception(0,
1.46      paf        69:                        0,
                     70:                        "no client charset defined yet");
                     71:        return *client_charset; 
1.22      parser     72: }
                     73: 
1.46      paf        74: #ifdef XML
1.49      paf        75: 
                     76: const char *Pool::transcode_cstr(xmlChar *s) {
                     77:        return get_source_charset().transcode_cstr(s); 
                     78: }
                     79: 
1.57      paf        80: String& Pool::transcode(xmlChar *s
                     81: #ifndef NO_STRING_ORIGIN
                     82:                , const String *origin
                     83: #endif
                     84:                                                ) {
                     85:        return get_source_charset().transcode(s, origin); 
1.49      paf        86: }
1.46      paf        87: 
1.47      paf        88: const char *Pool::transcode_cstr(GdomeDOMString *s) { 
1.46      paf        89:        return get_source_charset().transcode_cstr(s); 
                     90: }
1.22      parser     91: 
1.57      paf        92: String& Pool::transcode(GdomeDOMString *s
                     93: #ifndef NO_STRING_ORIGIN
                     94:                , const String *origin
                     95: #endif
                     96:        ) { 
                     97:        return get_source_charset().transcode(s, origin);
1.53      paf        98: }
                     99: 
                    100: xmlChar *Pool::transcode_buf2xchar(const char *buf, size_t buf_size) {
                    101:        return get_source_charset().transcode_buf2xchar(buf, buf_size); 
1.32      parser    102: }
                    103: 
1.48      paf       104: GdomeDOMString_auto_ptr Pool::transcode(const String& s) {
1.46      paf       105:        return get_source_charset().transcode(s); 
1.32      parser    106: }
                    107: 
1.26      parser    108: 
                    109: #endif

E-mail: