61 template <
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; }
213 #if ! JUCE_MSVC // (MSVC can't deal with multiple copy constructors) 221 template <
typename ObjectType1,
typename ObjectType2>
224 return pointer1 == pointer2.
get();
228 template <
typename ObjectType1,
typename ObjectType2>
231 return pointer1 != pointer2.
get();
235 template <
typename ObjectType1,
typename ObjectType2>
238 return pointer1.
get() == pointer2;
242 template <
typename ObjectType1,
typename ObjectType2>
245 return pointer1.
get() != pointer2;
249 template <
typename ObjectType1,
typename ObjectType2>
252 return pointer1.
get() == pointer2.
get();
256 template <
typename ObjectType1,
typename ObjectType2>
259 return pointer1.
get() != pointer2.
get();
263 template <
class ObjectType>
266 return pointer.
get() ==
nullptr;
270 template <
class ObjectType>
273 return pointer.
get() !=
nullptr;
277 template <
class ObjectType>
280 return pointer.
get() ==
nullptr;
284 template <
class ObjectType>
287 return pointer.
get() !=
nullptr;
293 template <
typename Type>
295 "Attempt to call deleteAndZero() on a ScopedPointer"); }
void reset(ObjectType *newObject)
Sets this pointer to a new object, deleting the old object that it was previously pointing to if ther...
ScopedPointer(ScopedPointer &objectToTransferFrom) noexcept
Creates a ScopedPointer that takes its pointer from another ScopedPointer.
ScopedPointer & operator=(ScopedPointer &objectToTransferFrom)
Changes this ScopedPointer to point to a new object.
ScopedPointer(ScopedPointer &&other) noexcept
Take ownership of another ScopedPointer.
ObjectType * release() noexcept
Detaches and returns the current object from this ScopedPointer without deleting it.
ScopedPointer(decltype(nullptr)) noexcept
Creates a ScopedPointer containing a null pointer.
ObjectType * createCopy() const
If the pointer is non-null, this will attempt to return a new copy of the object that is pointed to...
~ScopedPointer()
Destructor.
void swapWith(ScopedPointer< ObjectType > &other) noexcept
Swaps this object with that of another ScopedPointer.
ScopedPointer()=default
Creates a ScopedPointer containing a null pointer.
ObjectType & operator*() const noexcept
Returns the object that this ScopedPointer refers to.
ObjectType * operator->() const noexcept
Lets you access methods and properties of the object that this ScopedPointer refers to...
ObjectType * get() const noexcept
Returns the object that this ScopedPointer refers to.
ScopedPointer(ObjectType *objectToTakePossessionOf) noexcept
Creates a ScopedPointer that owns the specified object.
Used by container classes as an indirect way to delete an object of a particular type.
void reset()
Clears this pointer, deleting the object it points to if there is one.
void reset(ScopedPointer &newObject)
Sets this pointer to a new object, deleting the old object that it was previously pointing to if ther...
This class is deprecated.