17 #ifndef DISTRHO_SCOPED_POINTER_HPP_INCLUDED
18 #define DISTRHO_SCOPED_POINTER_HPP_INCLUDED
20 #include "../DistrhoUtils.hpp"
24 START_NAMESPACE_DISTRHO
38 template<
typename ObjectType>
41 static void destroy(ObjectType*
const object)
80 template<
class ObjectType>
91 : object(objectToTakePossessionOf) {}
100 : object(objectToTransferFrom.object)
102 objectToTransferFrom.object =
nullptr;
124 if (
this != objectToTransferFrom.getAddress())
128 DISTRHO_SAFE_ASSERT_RETURN(
object ==
nullptr ||
object != objectToTransferFrom.object, *
this);
130 ObjectType*
const oldObject = object;
131 object = objectToTransferFrom.object;
132 objectToTransferFrom.object =
nullptr;
148 if (
object != newObjectToTakePossessionOf)
150 ObjectType*
const oldObject = object;
151 object = newObjectToTakePossessionOf;
160 operator ObjectType*()
const noexcept {
return object; }
163 ObjectType*
get()
const noexcept {
return object; }
166 ObjectType&
operator*() const noexcept {
return *object; }
175 ObjectType*
release() noexcept { ObjectType*
const o = object;
object =
nullptr;
return o; }
185 DISTRHO_SAFE_ASSERT_RETURN(
object != other.object ||
this == other.getAddress() ||
object ==
nullptr,);
187 std::swap(
object, other.object);
195 const ScopedPointer* getAddress() const noexcept {
return this; }
197 #ifndef _MSC_VER // (MSVC can't deal with multiple copy constructors)
214 # ifdef DISTRHO_PROPER_CPP11_SUPPORT
228 template<
class ObjectType>
231 return static_cast<ObjectType*
>(pointer1) == pointer2;
237 template<
class ObjectType>
240 return static_cast<ObjectType*
>(pointer1) != pointer2;
245 END_NAMESPACE_DISTRHO
247 #endif // DISTRHO_SCOPED_POINTER_HPP_INCLUDED
ObjectType * release() noexcept
Definition: d_scopedpointer.hpp:175
~ScopedPointer()
Definition: d_scopedpointer.hpp:108
ObjectType & operator*() const noexcept
Definition: d_scopedpointer.hpp:166
ScopedPointer(ObjectType *const objectToTakePossessionOf) noexcept
Definition: d_scopedpointer.hpp:90
ObjectType * operator->() const noexcept
Definition: d_scopedpointer.hpp:169
ScopedPointer(ScopedPointer &objectToTransferFrom) noexcept
Definition: d_scopedpointer.hpp:99
void swapWith(ScopedPointer< ObjectType > &other) noexcept
Definition: d_scopedpointer.hpp:181
Definition: d_scopedpointer.hpp:81
ScopedPointer() noexcept
Definition: d_scopedpointer.hpp:86
Definition: d_scopedpointer.hpp:39
ScopedPointer & operator=(ObjectType *const newObjectToTakePossessionOf)
Definition: d_scopedpointer.hpp:146
ScopedPointer & operator=(ScopedPointer &objectToTransferFrom)
Definition: d_scopedpointer.hpp:122