36template <
class ObjectType>
66 : object (std::move (
other.object)),
67 shouldDelete (std::move (
other.shouldDelete))
109 operator ObjectType*()
const noexcept {
return object.get(); }
188 bool shouldDelete =
false;
Holds a pointer to an object which can optionally be deleted when this pointer goes out of scope.
OptionalScopedPointer(ObjectType *objectToHold, bool takeOwnership)
Creates an OptionalScopedPointer to point to a given object, and specifying whether the OptionalScope...
void setNonOwned(ObjectType *newObject)
Makes this OptionalScopedPointer point at a new object, but will not take ownership of that object.
void set(ObjectType *newObject, bool takeOwnership)
Makes this OptionalScopedPointer point at a new object, specifying whether the OptionalScopedPointer ...
OptionalScopedPointer & operator=(OptionalScopedPointer &&other) noexcept
Takes ownership of the object that another OptionalScopedPointer holds.
void clear()
Does the same thing as reset().
void reset() noexcept
Resets this pointer to null, possibly deleting the object that it holds, if it has ownership of it.
OptionalScopedPointer(std::unique_ptr< ObjectType > &&ptr) noexcept
Takes ownership of the object owned by ptr.
OptionalScopedPointer()=default
Creates an empty OptionalScopedPointer.
ObjectType * get() const noexcept
Returns the object that this pointer is managing.
OptionalScopedPointer(ObjectType &ref) noexcept
Points to the same object as ref, but does not take ownership.
ObjectType & operator*() const noexcept
Returns the object that this pointer is managing.
ObjectType * release() noexcept
Removes the current object from this OptionalScopedPointer without deleting it.
void setOwned(ObjectType *newObject)
Makes this OptionalScopedPointer point at a new object, and take ownership of that object.
void swapWith(OptionalScopedPointer< ObjectType > &other) noexcept
Swaps this object with another OptionalScopedPointer.
bool willDeleteObject() const noexcept
Returns true if the target object will be deleted when this pointer object is deleted.
ObjectType * operator->() const noexcept
Lets you access methods and properties of the object that this pointer is holding.
OptionalScopedPointer(OptionalScopedPointer &&other) noexcept
Takes ownership of the object that another OptionalScopedPointer holds.
~OptionalScopedPointer() noexcept
The destructor may or may not delete the object that is being held, depending on the takeOwnership fl...
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...