From f277fb639d41b247c93edec845641a5257290338 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Fri, 11 Mar 2005 17:44:55 +0000 Subject: [PATCH] * Prevent double deletion when setting to an object that is already set. * Added Unset() and Delete() methods. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@11680 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/private/shared/AutoDeleter.h | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/headers/private/shared/AutoDeleter.h b/headers/private/shared/AutoDeleter.h index c2d40ed2ce..88903cad22 100644 --- a/headers/private/shared/AutoDeleter.h +++ b/headers/private/shared/AutoDeleter.h @@ -36,7 +36,7 @@ namespace BPrivate { // AutoDeleter -template +template class AutoDeleter { public: inline AutoDeleter() @@ -56,8 +56,20 @@ public: inline void SetTo(C *object) { - fDelete(fObject); - fObject = object; + if (object != fObject) { + fDelete(fObject); + fObject = object; + } + } + + inline void Unset() + { + SetTo(NULL); + } + + inline void Delete() + { + SetTo(NULL); } inline C *Detach() @@ -68,8 +80,8 @@ public: } private: - C *fObject; - Delete fDelete; + C *fObject; + DeleteFunc fDelete; };