--- parser3/src/include/pa_pool.h 2003/01/23 16:08:01 1.86.2.4 +++ parser3/src/include/pa_pool.h 2003/01/28 12:11:49 1.86.2.16 @@ -9,7 +9,7 @@ #ifndef PA_POOL_H #define PA_POOL_H -static const char* IDENT_POOL_H="$Date: 2003/01/23 16:08:01 $"; +static const char* IDENT_POOL_H="$Date: 2003/01/28 12:11:49 $"; #include "pa_config_includes.h" @@ -219,6 +219,7 @@ public: */ #define override +#define rethrow throw void *operator new(size_t size) { return pa_malloc(size); @@ -236,23 +237,33 @@ public: static void operator delete(void *ptr) { pa_free(ptr); } + static void *malloc(size_t size) { + return pa_malloc(size); + } + static void *calloc(size_t size) { + return pa_calloc(size); + } + static void *realloc(void *ptr, size_t size) { + return pa_realloc(ptr, size); + } + }; /** Base for all Parser classes, memory allocation/dallocation goes via pa_malloc/pa_free. */ class PA_Object: public PA_Allocated { - mutable unsigned long references; + mutable unsigned long freferences; public: - PA_Object(): references(0) {} + PA_Object(): freferences(0) {} virtual ~PA_Object()=0; void ref() const { - references++; + freferences++; } void unref() const { - if(references) { - if(--references==0) + if(freferences) { + if(--freferences==0) delete this; } } @@ -273,7 +284,7 @@ public: ptr=src.get(); ptr->ref(); } - object_ptr& operator=(const object_ptr& src) { + object_ptr& operator=(const object_ptr& src) { if(this!=&src) if(ptr!=src.get()) { if(ptr) @@ -282,6 +293,7 @@ public: if(ptr) ptr->ref(); } + return *this; } ~object_ptr() { if(ptr) @@ -296,8 +308,22 @@ public: T *get() const { return ptr; } + // so one could object_ptr = object_ptr + operator object_ptr() const{ + return *this; + } + operator bool() const { + return get()!=0; + } + operator !() const { + return get()==0; + } }; +#define DECLARE_OBJECT_PTR(name) \ + typedef object_ptr name##Ptr; \ + const object_ptr name##PtrZero(0); + /// TEMPLATE CLASS smart_ptr, stolen from stl:auto_ptr template class smart_ptr { @@ -327,10 +353,24 @@ public: T *release() const {((smart_ptr *)this)->_Owns = false; return (_Ptr); } + // so one could smart_ptr = smart_ptr + operator smart_ptr() const { + return *this; + } + operator bool() const { + return get()!=0; + } + operator T*() const { + return _Ptr; + } private: bool _Owns; T *_Ptr; }; +// convinient types + +typedef smart_ptr CharPtr; +const CharPtr CharPtrZero(0); #endif