diff --git a/include/lgi/common/AutoPtr.h b/include/lgi/common/AutoPtr.h --- a/include/lgi/common/AutoPtr.h +++ b/include/lgi/common/AutoPtr.h @@ -1,128 +1,133 @@ #ifndef _GAUTOPTR_H_ #define _GAUTOPTR_H_ #ifdef __cplusplus template class LAutoPtrRef { typedef LAutoPtrRef Self; Self& operator = (Self const&) {} public: X *Ptr; explicit LAutoPtrRef(X *p) { Ptr = p; } }; template class LAutoPtr { X *Ptr; public: explicit LAutoPtr(X* p=NULL) { Ptr = p; } LAutoPtr(LAutoPtr &ap) { Ptr = ap.Release(); } + LAutoPtr(LAutoPtr &&from) + { + Ptr = from.Release(); + } + LAutoPtr(LAutoPtrRef apr) { Ptr = apr.Ptr; } LAutoPtr& operator=(LAutoPtr ap) { Reset(ap.Release()); return *this; } LAutoPtr& operator=(LAutoPtrRef ap) { if (ap.Ptr != Ptr) { Reset(ap.Ptr); } return *this; } ~LAutoPtr() { if (Arr) delete [] Ptr; else delete Ptr; // This is needed to be able to use LAutoPtr inside LArray's. Ptr = 0; } void Swap(LAutoPtr &p) { LSwap(Ptr, p.Ptr); } operator X*() const { return Ptr; } X* operator->() const { LAssert(Ptr != 0); return Ptr; } X* Get() const { return Ptr; } X* Release() { X *p = Ptr; Ptr = 0; return p; } bool Reset(X* p=NULL) { if (Ptr == p) return Ptr != 0; if (Arr) delete [] Ptr; else delete Ptr; Ptr = p; return Ptr != 0; } template operator LAutoPtrRef() { return LAutoPtrRef(Release()); } template operator LAutoPtr() { return LAutoPtr(Release()); } }; typedef LAutoPtr LAutoString; typedef LAutoPtr LAutoWString; #endif // __cplusplus #endif // _GAUTOPTR_H_ \ No newline at end of file