From eea30cdab327cf94bf8f898ef862d888a350f5c4 Mon Sep 17 00:00:00 2001 From: HuYingzhuo Date: Fri, 19 Apr 2019 16:31:42 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0AutoDelete=E6=A8=A1=E6=9D=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- inc/hgl/type/Smart.h | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/inc/hgl/type/Smart.h b/inc/hgl/type/Smart.h index 03287ade..1bf07eb8 100644 --- a/inc/hgl/type/Smart.h +++ b/inc/hgl/type/Smart.h @@ -455,5 +455,35 @@ namespace hgl return(*this); } };//template class WeakArray + + template class AutoDelete + { + T *obj; + + public: + + AutoDelete(T *o) + { + obj=o; + } + + ~AutoDelete() + { + if(obj) + delete obj; + } + + void operator = (T *o) + { + obj=o; + } + + T *operator -> (){return obj;} + + void Clear() + { + obj=nullptr; + } + };//template class AutoDelete }//namespace hgl #endif//HGL_SMART_INCLUDE