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