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,133 +1,135 @@ #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) + // Move constructor + LAutoPtr(LAutoPtr &&from) noexcept { 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; + Ptr = NULL; } void Swap(LAutoPtr &p) { LSwap(Ptr, p.Ptr); } operator X*() const { return Ptr; } X* operator->() const { - LAssert(Ptr != 0); + LAssert(Ptr != NULL); return Ptr; } X* Get() const { return Ptr; } X* Release() { X *p = Ptr; - Ptr = 0; + Ptr = NULL; return p; } bool Reset(X* p=NULL) { if (Ptr == p) - return Ptr != 0; + return Ptr != NULL; if (Arr) delete [] Ptr; else delete Ptr; Ptr = p; - return Ptr != 0; + + return Ptr != NULL; } 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