#ifndef _utl_LameShadowPtr_h_ #define _utl_LameShadowPtr_h_ // $Id$ #include #include #include #include namespace utl { /*! \class LameShadowPointer LameShadowPtr.h utl/LameShadowPtr.h \author Darko Veberic \version $Id$ \ingroup stl */ template class LameShadowPtr : public SafeBoolCast > { public: explicit LameShadowPtr(T* const ptr = 0) : fPtr(ptr) { } explicit LameShadowPtr(const LameShadowPtr& shadow) { DeepCopy(shadow.fPtr); } ~LameShadowPtr() { Delete(); } T* Get() { return fPtr; } const T* Get() const { return fPtr; } LameShadowPtr& operator=(const LameShadowPtr& shadow) { Delete(); DeepCopy(shadow.fPtr); return *this; } LameShadowPtr& operator=(T* const ptr) { Delete(); fPtr = ptr; return *this; } T& operator*(); const T& operator*() const; T* operator->() { DereferenceCheck::Examine(fPtr); return fPtr; } const T* operator->() const { DereferenceCheck::Examine(fPtr); return fPtr; } bool operator==(const LameShadowPtr& shadow) const { return fPtr == shadow.fPtr; } bool operator!=(const LameShadowPtr& shadow) const { return fPtr != shadow.fPtr; } bool operator==(const T* const ptr) const { return fPtr == ptr; } bool operator!=(const T* const ptr) const { return fPtr != ptr; } bool BoolCast() const { return fPtr; } void Swap(LameShadowPtr& shadow) { std::swap(fPtr, shadow.fPtr); } private: void Delete(); protected: void DeepCopy(const T* const ptr); T* fPtr; }; template class InitializedLameShadowPtr : public LameShadowPtr { public: InitializedLameShadowPtr() : LameShadowPtr(new T) { } }; template inline bool DeepEqual(const LameShadowPtr& s1, const LameShadowPtr& s2) { return (!s1 && !s2) || (s1 && s2 && *s1 == *s2); } /// this helps LameShadowPtr in STL containers template inline void swap(LameShadowPtr& a, LameShadowPtr& b) { a.Swap(b); } } #endif // Configure (x)emacs for this file ... // Local Variables: // mode: c++ // End: