|
|
| version 1.70, 2001/11/16 11:03:34 | version 1.85, 2002/10/15 15:12:57 |
|---|---|
| Line 1 | Line 1 |
| /** @file | /** @file |
| Parser: pool class decl. | Parser: pool class decl. |
| Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) | Copyright (c) 2001, 2002 ArtLebedev Group (http://www.artlebedev.com) |
| Author: Alexander Petrosyan <paf@design.ru> (http://paf.design.ru) | Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru) |
| $Id$ | |
| */ | */ |
| #ifndef PA_POOL_H | #ifndef PA_POOL_H |
| #define PA_POOL_H | #define PA_POOL_H |
| static const char* IDENT_POOL_H="$Date$"; | |
| #include "pa_config_includes.h" | #include "pa_config_includes.h" |
| #ifdef XML | #ifdef XML |
| #include <memory> | # include "gdome.h" |
| #include <XalanDOM/XalanDOMString.hpp> | // for xmlChar |
| #include <util/TransService.hpp> | # include "libxml/tree.h" |
| #endif | #endif |
| // forwards | // forwards |
| class Exception; | class Exception; |
| class String; | class String; |
| class Charset; | |
| class GdomeDOMString_auto_ptr; | |
| /** | /** |
| Pool mechanizm allows users not to free up allocated memory, | Pool mechanizm allows users not to free up allocated memory, |
| Line 35 class Pool { | Line 37 class Pool { |
| public: | public: |
| Pool(void *astorage); | Pool(void *astorage); |
| ~Pool(); | |
| ///{@ statistics | //{@ statistics |
| size_t total_allocated() { return ftotal_allocated; } | size_t total_allocated() { return ftotal_allocated; } |
| unsigned int total_times() { return ftotal_times; } | unsigned int total_times() { return ftotal_times; } |
| ///}@ | //}@ |
| void set_context(void *acontext) { fcontext=acontext; } | void set_context(void *acontext) { fcontext=acontext; } |
| void *get_context() { return fcontext; } | void *get_context() { return fcontext; } |
| void set_tag(void *atag) { ftag=atag; } | |
| void *tag() { return ftag; } | |
| /// allocates some bytes on pool | /// allocates some bytes on pool |
| void *malloc(size_t size, int place=0) { | void *malloc(size_t size, int place=0) { |
| return check(real_malloc(size, place), size); | return check(real_malloc(size, place), size); |
| Line 63 public: | Line 61 public: |
| fail_register_cleanup(); | fail_register_cleanup(); |
| } | } |
| /// resets transcoder if they change charset | //{@ helpers |
| void set_charset(const String &charset); | void *copy(const void *buf, const size_t size); |
| /// returns current charset | char *copy(const char *cstr); |
| const String& get_charset() { return *charset; } | //}@ |
| //{@ source charset | |
| void set_source_charset(Charset& acharset); | |
| Charset& get_source_charset(); | |
| //}@ | |
| //{@ client charset | |
| void set_client_charset(Charset& charset); | |
| Charset& get_client_charset(); | |
| //}@ | |
| #ifdef XML | |
| /// @see Charset::transcode_cstr(xmlChar *s); | |
| const char *transcode_cstr(xmlChar *s); | |
| /// @see Charset::transcode(xmlChar *s); | |
| String& transcode(xmlChar *s | |
| #ifndef NO_STRING_ORIGIN | |
| , const String *origin | |
| #endif | |
| ); | |
| /// @see Charset::transcode_cstr(GdomeDOMString *s); | |
| const char *transcode_cstr(GdomeDOMString *s); | |
| /// @see Charset::transcode(GdomeDOMString *s); | |
| String& transcode(GdomeDOMString *s | |
| #ifndef NO_STRING_ORIGIN | |
| , const String *origin | |
| #endif | |
| ); | |
| /// @see Charset::transcode_cstr(const char *buf, size_t buf_size=0); | |
| xmlChar *transcode_buf2xchar(const char *buf, size_t buf_size=0); | |
| /// @see Charset::transcode(const String& s) | |
| GdomeDOMString_auto_ptr transcode(const String& s); | |
| #endif | |
| private: | private: |
| void *fstorage; | void *fstorage; |
| void *fcontext; | void *fcontext; |
| void *ftag; | Charset *source_charset; |
| const String *charset; | Charset *client_charset; |
| private: | private: |
| Line 105 private: | Line 138 private: |
| /// throws register cleanup exception | /// throws register cleanup exception |
| void fail_register_cleanup() const; | void fail_register_cleanup() const; |
| #ifdef XML | |
| public: | |
| /// converts Xalan string to char * | |
| const char *transcode_cstr(const XalanDOMString& s); | |
| /// converts Xalan string to parser String | |
| String& transcode(const XalanDOMString& s); | |
| /// converts char * to Xalan string | |
| std::auto_ptr<XalanDOMString> transcode_buf(const char *buf, size_t buf_size); | |
| /// converts parser String to Xalan string | |
| std::auto_ptr<XalanDOMString> transcode(const String& s); | |
| private: | |
| void set_charset(const char *new_scharset); | |
| void update_transcoder(); | |
| private: | |
| XMLTranscoder *transcoder; | |
| #endif | |
| private: // statistics | private: // statistics |
| size_t ftotal_allocated; | size_t ftotal_allocated; |
| Line 146 private: //disabled | Line 156 private: //disabled |
| @see NEW | @see NEW |
| */ | */ |
| // all classes that are members parents of packed class [String] | |
| // sould be packed also to avoid sparc odd st/lduh problem | |
| #include "pa_pragma_pack_begin.h" | |
| class Pooled { | class Pooled { |
| // the pool i'm allocated on | // the pool i'm allocated on |
| Pool *fpool; | Pool *fpool; |
| Line 172 public: | Line 186 public: |
| void *malloc(size_t size, int place=0) const { return fpool->malloc(size, place); } | void *malloc(size_t size, int place=0) const { return fpool->malloc(size, place); } |
| void *calloc(size_t size) const { return fpool->calloc(size); } | void *calloc(size_t size) const { return fpool->calloc(size); } |
| void register_cleanup(void (*cleanup) (void *), void *data) { fpool->register_cleanup(cleanup, data); } | void register_cleanup(void (*cleanup) (void *), void *data) { fpool->register_cleanup(cleanup, data); } |
| void *copy(const void *buf, const size_t size) { return fpool->copy(buf, size); } | |
| char *copy(const char *cstr) { return fpool->copy(cstr); } | |
| #ifdef XML | #ifdef XML |
| const char *transcode_cstr(const XalanDOMString& s) { return fpool->transcode_cstr(s); } | |
| String& transcode(const XalanDOMString& s) { return fpool->transcode(s); } | const char *transcode_cstr(GdomeDOMString *s) { return fpool->transcode_cstr(s); } |
| String& transcode(GdomeDOMString *s | |
| #ifndef NO_STRING_ORIGIN | |
| , const String *origin | |
| #endif | |
| ) { | |
| return fpool->transcode(s | |
| #ifndef NO_STRING_ORIGIN | |
| , origin | |
| #endif | |
| ); | |
| } | |
| #endif | #endif |
| //} | //} |
| }; | }; |
| #include "pa_pragma_pack_end.h" | |
| /// 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()) |