61template <
class ObjectType>
74 : object (objectToTakePossessionOf)
85 : object (objectToTransferFrom.release())
105 if (
this != objectToTransferFrom.getAddress())
109 jassert (
object ==
nullptr ||
object != objectToTransferFrom.object);
122 reset (newObjectToTakePossessionOf);
129 other.object =
nullptr;
135 reset (other.release());
141 inline operator ObjectType*()
const noexcept {
return object; }
144 inline ObjectType*
get() const noexcept {
return object; }
147 inline ObjectType&
operator*() const noexcept {
return *object; }
150 inline ObjectType*
operator->() const noexcept {
return object; }
156 auto* oldObject = object;
164 if (
object != newObject)
166 auto* oldObject = object;
174 jassert (newObject ==
nullptr);
187 ObjectType*
release() noexcept {
auto* o = object;
object = {};
return o; }
197 jassert (
object != other.object ||
this == other.getAddress() ||
object ==
nullptr);
199 std::swap (
object, other.object);
205 inline ObjectType*
createCopy()
const {
return createCopyIfNotNull (
object); }
209 ObjectType*
object =
nullptr;
211 const ScopedPointer* getAddress() const noexcept {
return this; }
221template <
typename ObjectType1,
typename ObjectType2>
222bool operator== (ObjectType1* pointer1,
const ScopedPointer<ObjectType2>& pointer2)
noexcept
224 return pointer1 == pointer2.
get();
228template <
typename ObjectType1,
typename ObjectType2>
229bool operator!= (ObjectType1* pointer1,
const ScopedPointer<ObjectType2>& pointer2)
noexcept
231 return pointer1 != pointer2.get();
235template <
typename ObjectType1,
typename ObjectType2>
236bool operator== (
const ScopedPointer<ObjectType1>& pointer1, ObjectType2* pointer2)
noexcept
238 return pointer1.get() == pointer2;
242template <
typename ObjectType1,
typename ObjectType2>
243bool operator!= (
const ScopedPointer<ObjectType1>& pointer1, ObjectType2* pointer2)
noexcept
245 return pointer1.get() != pointer2;
249template <
typename ObjectType1,
typename ObjectType2>
250bool operator== (
const ScopedPointer<ObjectType1>& pointer1,
const ScopedPointer<ObjectType2>& pointer2)
noexcept
252 return pointer1.get() == pointer2.get();
256template <
typename ObjectType1,
typename ObjectType2>
257bool operator!= (
const ScopedPointer<ObjectType1>& pointer1,
const ScopedPointer<ObjectType2>& pointer2)
noexcept
259 return pointer1.get() != pointer2.get();
263template <
class ObjectType>
264bool operator== (
decltype (
nullptr),
const ScopedPointer<ObjectType>& pointer)
noexcept
266 return pointer.get() ==
nullptr;
270template <
class ObjectType>
271bool operator!= (
decltype (
nullptr),
const ScopedPointer<ObjectType>& pointer)
noexcept
273 return pointer.get() !=
nullptr;
277template <
class ObjectType>
278bool operator== (
const ScopedPointer<ObjectType>& pointer,
decltype (
nullptr)) noexcept
280 return pointer.get() ==
nullptr;
284template <
class ObjectType>
285bool operator!= (
const ScopedPointer<ObjectType>& pointer,
decltype (
nullptr)) noexcept
287 return pointer.get() !=
nullptr;
293template <
typename Type>
294void deleteAndZero (ScopedPointer<Type>&) {
static_assert (
sizeof (Type) == 12345,
295 "Attempt to call deleteAndZero() on a ScopedPointer"); }
This class is deprecated.
ScopedPointer(decltype(nullptr)) noexcept
Creates a ScopedPointer containing a null pointer.
ObjectType * get() const noexcept
Returns the object that this ScopedPointer refers to.
ScopedPointer & operator=(ScopedPointer &objectToTransferFrom)
Changes this ScopedPointer to point to a new object.
ScopedPointer(ScopedPointer &objectToTransferFrom) noexcept
Creates a ScopedPointer that takes its pointer from another ScopedPointer.
ObjectType & operator*() const noexcept
Returns the object that this ScopedPointer refers to.
ScopedPointer()=default
Creates a ScopedPointer containing a null pointer.
ObjectType * operator->() const noexcept
Lets you access methods and properties of the object that this ScopedPointer refers to.
void swapWith(ScopedPointer< ObjectType > &other) noexcept
Swaps this object with that of another ScopedPointer.
void reset(ScopedPointer &newObject)
Sets this pointer to a new object, deleting the old object that it was previously pointing to if ther...
ScopedPointer(ScopedPointer &&other) noexcept
Take ownership of another ScopedPointer.
ScopedPointer(ObjectType *objectToTakePossessionOf) noexcept
Creates a ScopedPointer that owns the specified object.
~ScopedPointer()
Destructor.
ObjectType * release() noexcept
Detaches and returns the current object from this ScopedPointer without deleting it.
void reset()
Clears this pointer, deleting the object it points to if there is one.
ObjectType * createCopy() const
If the pointer is non-null, this will attempt to return a new copy of the object that is pointed to.
void reset(ObjectType *newObject)
Sets this pointer to a new object, deleting the old object that it was previously pointing to if ther...
Used by container classes as an indirect way to delete an object of a particular type.