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&
getObject() const noexcept {
return *object; }
152 ObjectType&
operator*() const noexcept {
return *object; }
161 ObjectType*
release() noexcept { ObjectType*
const o = object;
object =
nullptr;
return o; }
171 DISTRHO_SAFE_ASSERT_RETURN(
object != other.object ||
this == other.getAddress() ||
object ==
nullptr,);
173 std::swap(
object, other.object);
181 const ScopedPointer* getAddress() const noexcept {
return this; }
183 #ifndef _MSC_VER // (MSVC can't deal with multiple copy constructors)
200 # ifdef DISTRHO_PROPER_CPP11_SUPPORT
214 template<
class ObjectType>
217 return static_cast<ObjectType*
>(pointer1) == pointer2;
223 template<
class ObjectType>
226 return static_cast<ObjectType*
>(pointer1) != pointer2;
231 END_NAMESPACE_DISTRHO
233 #endif // DISTRHO_SCOPED_POINTER_HPP_INCLUDED
ScopedPointer & operator=(ObjectType *const newObjectToTakePossessionOf)
Definition: ScopedPointer.hpp:129
ObjectType * release() noexcept
Definition: ScopedPointer.hpp:161
ObjectType * operator->() const noexcept
Definition: ScopedPointer.hpp:155
~ScopedPointer()
Definition: ScopedPointer.hpp:91
ObjectType & getObject() const noexcept
Definition: ScopedPointer.hpp:149
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:152
void swapWith(ScopedPointer< ObjectType > &other) noexcept
Definition: ScopedPointer.hpp:167