From 5577b07dfd1018e99f7b80da294c8e40d581405f Mon Sep 17 00:00:00 2001 From: hyzboy Date: Mon, 15 Jul 2019 22:36:33 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0AutoDeleteArray=E6=A8=A1?= =?UTF-8?q?=E6=9D=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- inc/hgl/type/Smart.h | 45 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/inc/hgl/type/Smart.h b/inc/hgl/type/Smart.h index 85d3ee9e..5d52e0d7 100644 --- a/inc/hgl/type/Smart.h +++ b/inc/hgl/type/Smart.h @@ -487,6 +487,51 @@ namespace hgl { obj=nullptr; } + + T *Finish() + { + T *reuslt=obj; + + obj=nullptr; + + return reuslt; + } };//template class AutoDelete + + template class AutoDeleteArray + { + T *obj; + + public: + + AutoDeleteArray(T *o) + { + obj=o; + } + + ~AutoDeleteArray() + { + if(obj) + delete[] obj; + } + + void operator = (T *o) + { + obj=o; + } + + T *operator -> (){return obj;} + + operator T *(){return obj;} + operator const T *()const{return obj;} + + T &operator[](int index){return obj[index];} + const T &operator[](int index)const{return obj[index];} + + void Clear() + { + obj=nullptr; + } + };//template class AutoDeleteArray }//namespace hgl #endif//HGL_SMART_INCLUDE