/* ----------------------------------------------------------------------------- GSFramework Copyright 2001-2013 Emmanuel Julien. All Rights Reserved. ----------------------------------------------------------------------------- */ #ifndef __NAUTO_PTR__ #define __NAUTO_PTR__ #include "alloc/ialloc.h" #include "billing/billing.h" namespace GS { /*! @short Auto pointer. @author Emmanuel Julien (ejulien@gsworks.fr) */ template class AutoPtr { private: T *o; public: inline operator T*() const { return o; } inline T *c_ptr() const { return o; } inline bool IsNull() const { return o ? false : true; } inline bool IsValid() const { return o ? true : false; } T *operator = (T *p) { if (o != p) { delete(o); o = p; } return o; } inline T &operator[] (size_t n) { return o[n]; } inline bool operator == (const T *p) const { return o == p; } inline bool operator != (const T *p) const { return o != p; } inline T *operator -> () const { return o; } inline T &operator * () const { return *o; } inline T *Detach() { T *p = o; o = 0; return p; } explicit AutoPtr(T *p = 0) : o(p) {} ~AutoPtr() { delete(o); o = 0; } }; } // GS #endif // __NAUTO_PTR__