--- parser3/src/include/pa_memory.h 2003/02/21 10:58:57 1.1.2.2 +++ parser3/src/include/pa_memory.h 2003/03/06 16:15:25 1.1.2.8 @@ -9,7 +9,7 @@ #ifndef PA_MEMORY_H #define PA_MEMORY_H -static const char* IDENT_MEMORY_H="$Date: 2003/02/21 10:58:57 $"; +static const char* IDENT_MEMORY_H="$Date: 2003/03/06 16:15:25 $"; // include @@ -51,13 +51,6 @@ inline void *pa_realloc(void *ptr, size_ return pa_fail_alloc("reallocate to", size); } -// forwards - -class Exception; -class String; -class Charset; -class GdomeDOMString_auto_ptr; - template class object_ptr { T *ptr; public: @@ -131,7 +124,7 @@ public: {if (this != &src) {if (ptr != src.get()) {if (owns) - delete ptr; + delete[] ptr; owns = src.owns; } else if (src.owns) owns = true; @@ -139,7 +132,7 @@ public: return (*this); } ~smart_ptr() {if (owns) - delete ptr; } + delete[] ptr; } T& operator*() const {return (*get()); } T *get() const @@ -150,11 +143,17 @@ public: operator bool() const { return get()!=0; } + bool operator !() const { + return get()==0; + } operator T*() const { return ptr; } }; +#define DECLARE_SMART_PTR(name) \ + typedef smart_ptr name##Ptr + // defines #define override @@ -165,6 +164,9 @@ public: inline void *operator new[] (size_t size) { return pa_malloc(size); } +inline void *operator new[] (size_t size, int /*zero, just flag to use calloc instead of malloc*/) { + return pa_calloc(size); +} inline void operator delete[] (void *ptr) { pa_free(ptr); } @@ -214,6 +216,7 @@ public: delete this; } } + unsigned long references() { return freferences; } }; DECLARE_OBJECT_PTR(PA_Object);