--- parser3/src/include/pa_pool.h 2003/01/23 15:38:05 1.86.2.3 +++ parser3/src/include/pa_pool.h 2003/01/24 14:36:10 1.86.2.8 @@ -9,7 +9,7 @@ #ifndef PA_POOL_H #define PA_POOL_H -static const char* IDENT_POOL_H="$Date: 2003/01/23 15:38:05 $"; +static const char* IDENT_POOL_H="$Date: 2003/01/24 14:36:10 $"; #include "pa_config_includes.h" @@ -247,10 +247,10 @@ public: PA_Object(): references(0) {} virtual ~PA_Object()=0; - void ref() { + void ref() const { references++; } - void unref() { + void unref() const { if(references) { if(--references==0) delete this; @@ -273,7 +273,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 +282,7 @@ public: if(ptr) ptr->ref(); } + return *this; } ~object_ptr() { if(ptr) @@ -296,8 +297,20 @@ public: T *get() const { return ptr; } + // so one could assign object_ptr to 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; + /// TEMPLATE CLASS smart_ptr, stolen from stl:auto_ptr template class smart_ptr { @@ -327,10 +340,21 @@ public: T *release() const {((smart_ptr *)this)->_Owns = false; return (_Ptr); } + // so one could assign smart_ptr to smart_ptr + operator smart_ptr() const { + return *this; + } + operator bool() const { + return get(); + } private: bool _Owns; T *_Ptr; }; +// convinient types + +typedef smart_ptr CharPtr; +typedef smart_ptr ConstCharPtr; #endif