Base Framework
Public Member Functions | List of all members
OwnershipPointer< TYPE > Class Template Reference

Ownership automation pointer. More...

#include <base/mem/OwnershipPointer.h>

Inherits AutomationObject.

Public Member Functions

 OwnershipPointer () noexcept
 
 OwnershipPointer (TYPE *_object) noexcept
 
 OwnershipPointer (OwnershipPointer &copy) noexcept
 
OwnershipPointeroperator= (OwnershipPointer &assign)
 
template<class POLY >
OwnershipPointeroperator= (OwnershipPointer< POLY > &assign)
 
OwnershipPointeroperator= (TYPE *object)
 
TYPE * relinquishOwnership () noexcept
 
TYPE * getValue () noexcept
 
const TYPE * getValue () const noexcept
 
TYPE & operator* ()
 
const TYPE & operator* () const
 
TYPE * operator-> ()
 
const TYPE * operator-> () const
 
 ~OwnershipPointer ()
 

Detailed Description

template<class TYPE>
class OwnershipPointer< TYPE >

Ownership automation pointer.

Automation pointer that allows transfer of ownership and automatic deletion of the object. Do not construct more than one automation pointer from the 'normal' pointer.

void MyOtherClass::myOtherMethod(MyResource resource) {
// ...
bassert(condition, MyException(this));
// ...
}
void MyClass::myMethod() {
OwnershipPointer<MyResource> resource = new MyResource();
MyOtherClass* myOtherObject = getOtherObject();
myOtherObject->myOtherMethod(resource);
MyResource* result = resource.relinquishOwnership();
// ...
}
Version
1.0

Constructor & Destructor Documentation

◆ OwnershipPointer() [1/3]

template<class TYPE >
OwnershipPointer< TYPE >::OwnershipPointer ( )
inlinenoexcept

Initializes the ownership pointer as nullptr.

◆ OwnershipPointer() [2/3]

template<class TYPE >
OwnershipPointer< TYPE >::OwnershipPointer ( TYPE *  _object)
inlinenoexcept

Initializes the ownership pointer.

Parameters
objectThe object pointer to be automated.

◆ OwnershipPointer() [3/3]

template<class TYPE >
OwnershipPointer< TYPE >::OwnershipPointer ( OwnershipPointer< TYPE > &  copy)
inlinenoexcept

Copy constructor. Transfers ownership from copy to this object. The original owner loses the ownership.

◆ ~OwnershipPointer()

template<class TYPE >
OwnershipPointer< TYPE >::~OwnershipPointer ( )
inline

Destroys the ownership pointer (and the object).

Member Function Documentation

◆ getValue() [1/2]

template<class TYPE >
const TYPE* OwnershipPointer< TYPE >::getValue ( ) const
inlinenoexcept

Returns the pointer to constant object.

◆ getValue() [2/2]

template<class TYPE >
TYPE* OwnershipPointer< TYPE >::getValue ( )
inlinenoexcept

Returns the pointer to mutable object.

◆ operator*() [1/2]

template<class TYPE >
TYPE& OwnershipPointer< TYPE >::operator* ( )
inline

Returns mutable object.

◆ operator*() [2/2]

template<class TYPE >
const TYPE& OwnershipPointer< TYPE >::operator* ( ) const
inline

Returns constant object.

◆ operator->() [1/2]

template<class TYPE >
TYPE* OwnershipPointer< TYPE >::operator-> ( )
inline

Returns object for modifying access.

◆ operator->() [2/2]

template<class TYPE >
const TYPE* OwnershipPointer< TYPE >::operator-> ( ) const
inline

Returns object for non-modifying access.

◆ operator=() [1/3]

template<class TYPE >
OwnershipPointer& OwnershipPointer< TYPE >::operator= ( OwnershipPointer< TYPE > &  assign)
inline

Assignment operator.

◆ operator=() [2/3]

template<class TYPE >
template<class POLY >
OwnershipPointer& OwnershipPointer< TYPE >::operator= ( OwnershipPointer< POLY > &  assign)
inline

Assignment operator.

◆ operator=() [3/3]

template<class TYPE >
OwnershipPointer& OwnershipPointer< TYPE >::operator= ( TYPE *  object)
inline

Assignment operator.

◆ relinquishOwnership()

template<class TYPE >
TYPE* OwnershipPointer< TYPE >::relinquishOwnership ( )
inlinenoexcept

Makes the automation pointer relinquish its ownership. Please note that the pointer may not have the ownership to begin with.

Returns
Pointer to object.
OwnershipPointer::relinquishOwnership
TYPE * relinquishOwnership() noexcept
Definition: OwnershipPointer.h:138
OwnershipPointer
Ownership automation pointer.
Definition: OwnershipPointer.h:48