17 #ifndef DISTRHO_SCOPED_POINTER_HPP_INCLUDED
18 #define DISTRHO_SCOPED_POINTER_HPP_INCLUDED
20 #include "../DistrhoUtils.hpp"
24 START_NAMESPACE_DISTRHO
63 template<
class ObjectType>
74 : object(objectToTakePossessionOf) {}
83 : object(objectToTransferFrom.object)
85 objectToTransferFrom.object =
nullptr;
107 if (
this != objectToTransferFrom.getAddress())
111 DISTRHO_SAFE_ASSERT_RETURN(
object ==
nullptr ||
object != objectToTransferFrom.object, *
this);
113 ObjectType*
const oldObject = object;
114 object = objectToTransferFrom.object;
115 objectToTransferFrom.object =
nullptr;
131 if (
object != newObjectToTakePossessionOf)
133 ObjectType*
const oldObject = object;
134 object = newObjectToTakePossessionOf;
143 operator ObjectType*()
const noexcept {
return object; }
146 ObjectType*
get() const noexcept {
return object; }
149 ObjectType&
operator*() const noexcept {
return *object; }
158 ObjectType*
release() noexcept { ObjectType*
const o = object;
object =
nullptr;
return o; }
168 DISTRHO_SAFE_ASSERT_RETURN(
object != other.object ||
this == other.getAddress() ||
object ==
nullptr,);
170 std::swap(
object, other.object);
178 const ScopedPointer* getAddress() const noexcept {
return this; }
180 #ifndef _MSC_VER // (MSVC can't deal with multiple copy constructors)
197 # ifdef DISTRHO_PROPER_CPP11_SUPPORT
211 template<
class ObjectType>
214 return static_cast<ObjectType*
>(pointer1) == pointer2;
220 template<
class ObjectType>
223 return static_cast<ObjectType*
>(pointer1) != pointer2;
228 END_NAMESPACE_DISTRHO
230 #endif // DISTRHO_SCOPED_POINTER_HPP_INCLUDED
ScopedPointer & operator=(ObjectType *const newObjectToTakePossessionOf)
Definition: ScopedPointer.hpp:129
ObjectType * release() noexcept
Definition: ScopedPointer.hpp:158
ObjectType * operator->() const noexcept
Definition: ScopedPointer.hpp:152
~ScopedPointer()
Definition: ScopedPointer.hpp:91
ScopedPointer & operator=(ScopedPointer &objectToTransferFrom)
Definition: ScopedPointer.hpp:105
Definition: ScopedPointer.hpp:64
ScopedPointer(ScopedPointer &objectToTransferFrom) noexcept
Definition: ScopedPointer.hpp:82
ScopedPointer() noexcept
Definition: ScopedPointer.hpp:69
ScopedPointer(ObjectType *const objectToTakePossessionOf) noexcept
Definition: ScopedPointer.hpp:73
ObjectType * get() const noexcept
Definition: ScopedPointer.hpp:146
ObjectType & operator*() const noexcept
Definition: ScopedPointer.hpp:149
void swapWith(ScopedPointer< ObjectType > &other) noexcept
Definition: ScopedPointer.hpp:164