* 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
This commit is contained in:
Ingo Weinhold 2005-03-11 17:44:55 +00:00
parent cc3255267c
commit f277fb639d

View File

@ -36,7 +36,7 @@ namespace BPrivate {
// AutoDeleter
template<typename C, typename Delete>
template<typename C, typename DeleteFunc>
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;
};