Bifrost SDK
Bifrost SDK documentation
BifrostGraph::Executor::Owner< T > Class Template Reference

The Owner<T> class template represents ownership of an object pointer. It indicates that the pointed object must either be transferred to another owner (like another Owner, or a std::unique_ptr) or deleted. Owner provides exception safety to classes and functions that handle objects with dynamic lifetime, by guaranteeing deletion of the pointed object on both normal exit or exit through exception. More...

#include <Owner.h>

Inheritance diagram for BifrostGraph::Executor::Owner< T >:

Public Types

template<typename P >
using DeleterFunc = void(*)(P *p)
 The signature for the custom pointer deleter of a pointee p. This is the custom deleter type to use with the constructor Owner(P* p, DeleterFunc d). More...
 

Public Member Functions

 Owner () noexcept
 Construct an empty Owner. More...
 
template<typename P , typename = if_compliant_and_convertible_from<P>>
 Owner (P *p) noexcept
 Construct an Owner that owns the object pointed by p. The owned object will be destructed using the expression delete p. The pointer p used for deletion is captured at the construction time of the Owner. More...
 
template<typename P , typename = if_compliant_and_convertible_from<P>>
 Owner (P *p, DeleterFunc< P > d) noexcept
 Construct an Owner that owns the object pointed by p, with a custom pointer deleter set to d. The owned object will be destructed using the expression d(p). The deleter (if any) is invoked in all cases, even when the object pointer p is null. The pointer p used for deletion is captured at the construction time of the Owner. More...
 
 ~Owner () noexcept=default
 Destruct this Owner. If no custom deleter was provided, the owned object is disposed using a delete p expression, otherwise the owned object is disposed using a d(p) expression. More...
 
 Owner (Owner &&rhs) noexcept=default
 Move constructor. More...
 
template<typename P , typename = if_convertible_from<P>>
 Owner (Owner< P > &&rhs) noexcept
 Move conversion This move conversion is only considered if a P* can be implicitly converted to a T*. More...
 
Owneroperator= (Owner &&rhs) noexcept=default
 Move assignment operator Move assign the Owner rhs to *this. More...
 
constexpr operator bool () const noexcept
 Check if the wrapped pointer is null. More...
 
const T & operator* () const noexcept
 Indirection operator. More...
 
T & operator* () noexcept
 Indirection operator. More...
 
const T * operator-> () const noexcept
 Indirection operator. More...
 
T * operator-> () noexcept
 Indirection operator. More...
 
const T * get () const noexcept
 Accessor. More...
 
T * get () noexcept
 Accessor. More...
 
Ownerreset () noexcept
 Reset this Owner object to its uninitialized state, deleting the currently owned object (if any). More...
 
void swap (Owner &other) noexcept
 Swap the content of this Owner with another one. More...
 

Friends

template<class P >
class Owner
 Friendship to allow conversion between Owners of different types. More...
 

Detailed Description

template<typename T>
class BifrostGraph::Executor::Owner< T >

The Owner<T> class template represents ownership of an object pointer. It indicates that the pointed object must either be transferred to another owner (like another Owner, or a std::unique_ptr) or deleted. Owner provides exception safety to classes and functions that handle objects with dynamic lifetime, by guaranteeing deletion of the pointed object on both normal exit or exit through exception.

Template Parameters
Tthe owned object's exposed type used by indirection operators and by accessors.

Definition at line 38 of file Owner.h.

Member Typedef Documentation

◆ DeleterFunc

template<typename T >
template<typename P >
using BifrostGraph::Executor::Owner< T >::DeleterFunc = void (*)(P* p)

The signature for the custom pointer deleter of a pointee p. This is the custom deleter type to use with the constructor Owner(P* p, DeleterFunc d).

Template Parameters
Pthe storage type used for the owned object.
Parameters
[in]pa pointer to the owned object to destruct. Can be nullptr.

Definition at line 96 of file Owner.h.

Constructor & Destructor Documentation

◆ Owner() [1/5]

template<typename T >
BifrostGraph::Executor::Owner< T >::Owner ( )
inlinenoexcept

Construct an empty Owner.

Definition at line 68 of file Owner.h.

◆ Owner() [2/5]

template<typename T >
template<typename P , typename = if_compliant_and_convertible_from<P>>
BifrostGraph::Executor::Owner< T >::Owner ( P *  p)
inlinenoexcept

Construct an Owner that owns the object pointed by p. The owned object will be destructed using the expression delete p. The pointer p used for deletion is captured at the construction time of the Owner.

This constructor is only considered if a P* can be implicitly converted to a T*.

If an error occurs while initializing the new Owner, the object pointed by p is deleted before returning control to the caller and the resulting Owner will be empty.

Postcondition
get() == p if the initialization of the new Owner succeeded; get() == nullptr otherwise.
Template Parameters
Pthe storage type used for the owned object.
Parameters
[in]pa pointer to an object to be owned by the Owner or a null pointer.

Definition at line 87 of file Owner.h.

◆ Owner() [3/5]

template<typename T >
template<typename P , typename = if_compliant_and_convertible_from<P>>
BifrostGraph::Executor::Owner< T >::Owner ( P *  p,
DeleterFunc< P >  d 
)
inlinenoexcept

Construct an Owner that owns the object pointed by p, with a custom pointer deleter set to d. The owned object will be destructed using the expression d(p). The deleter (if any) is invoked in all cases, even when the object pointer p is null. The pointer p used for deletion is captured at the construction time of the Owner.

This constructor is only considered if a P* can be implicitly converted to a T*.

If an error occurs while initializing the new Owner and the custom deleter is valid, the object pointed by p is deleted using the custom deleter before returning control to the caller; if the custom deleter is invalid (nullptr), the object pointed by p is not deleted before returning control to the caller. In all error cases, the resulting Owner will be empty.

Precondition
the custom pointer deleter must not be null
Postcondition
get() == p if the initialization of the new Owner succeeded; get() == nullptr otherwise.
Template Parameters
Pthe storage type used for the owned object.
Parameters
[in]pa pointer to an object to be owned by the Owner or a null pointer.
[in]dthe deleter to invoke when this Owner is destructed.

Definition at line 120 of file Owner.h.

◆ ~Owner()

template<typename T >
BifrostGraph::Executor::Owner< T >::~Owner ( )
defaultnoexcept

Destruct this Owner. If no custom deleter was provided, the owned object is disposed using a delete p expression, otherwise the owned object is disposed using a d(p) expression.

◆ Owner() [4/5]

template<typename T >
BifrostGraph::Executor::Owner< T >::Owner ( Owner< T > &&  rhs)
defaultnoexcept

Move constructor.

Postcondition
*this contains the old value of rhs
rhs is empty
Parameters
[in]rhsthe Owner to be moved

◆ Owner() [5/5]

template<typename T >
template<typename P , typename = if_convertible_from<P>>
BifrostGraph::Executor::Owner< T >::Owner ( Owner< P > &&  rhs)
inlinenoexcept

Move conversion This move conversion is only considered if a P* can be implicitly converted to a T*.

Postcondition
*this contains the old value of rhs
rhs is empty
Template Parameters
Pthe storage type used for the owned object.
Parameters
[in]rhsthe Owner to be moved

Definition at line 143 of file Owner.h.

Member Function Documentation

◆ get() [1/2]

template<typename T >
const T * BifrostGraph::Executor::Owner< T >::get ( ) const
inlinenoexcept

Accessor.

Returns
The pointer to the pointed object

Definition at line 179 of file Owner.h.

◆ get() [2/2]

template<typename T >
T * BifrostGraph::Executor::Owner< T >::get ( )
inlinenoexcept

Accessor.

Returns
The pointer to the pointed object

Definition at line 183 of file Owner.h.

◆ operator bool()

template<typename T >
constexpr BifrostGraph::Executor::Owner< T >::operator bool ( ) const
inlineexplicitconstexprnoexcept

Check if the wrapped pointer is null.

Returns
true if the wrapped pointer is not null; false otherwise.

Definition at line 155 of file Owner.h.

◆ operator*() [1/2]

template<typename T >
const T & BifrostGraph::Executor::Owner< T >::operator* ( ) const
inlinenoexcept

Indirection operator.

Precondition
the wrapped pointer must not be null
Returns
The reference to the pointed object

Definition at line 160 of file Owner.h.

◆ operator*() [2/2]

template<typename T >
T & BifrostGraph::Executor::Owner< T >::operator* ( )
inlinenoexcept

Indirection operator.

Precondition
the wrapped pointer must not be null
Returns
The reference to the pointed object

Definition at line 165 of file Owner.h.

◆ operator->() [1/2]

template<typename T >
const T * BifrostGraph::Executor::Owner< T >::operator-> ( ) const
inlinenoexcept

Indirection operator.

Precondition
the wrapped pointer must not be null
Returns
The pointer to the pointed object

Definition at line 170 of file Owner.h.

◆ operator->() [2/2]

template<typename T >
T * BifrostGraph::Executor::Owner< T >::operator-> ( )
inlinenoexcept

Indirection operator.

Precondition
the wrapped pointer must not be null
Returns
The pointer to the pointed object

Definition at line 175 of file Owner.h.

◆ operator=()

template<typename T >
Owner & BifrostGraph::Executor::Owner< T >::operator= ( Owner< T > &&  rhs)
defaultnoexcept

Move assignment operator Move assign the Owner rhs to *this.

Postcondition
*this contains the old value of rhs
rhs is empty
Parameters
[in]rhsthe source of the assignment
Returns
*this

◆ reset()

template<typename T >
Owner & BifrostGraph::Executor::Owner< T >::reset ( )
inlinenoexcept

Reset this Owner object to its uninitialized state, deleting the currently owned object (if any).

Postcondition
get() == nullptr
Returns
*this

Definition at line 189 of file Owner.h.

◆ swap()

template<typename T >
void BifrostGraph::Executor::Owner< T >::swap ( Owner< T > &  other)
inlinenoexcept

Swap the content of this Owner with another one.

Parameters
[in,out]otherThe other Owner to swap with.
Postcondition
*this contains the old value of other
other contains the old value of *this

Definition at line 198 of file Owner.h.

References Amino::swap().

Friends And Related Function Documentation

◆ Owner

template<typename T >
template<class P >
friend class Owner
friend

Friendship to allow conversion between Owners of different types.

Definition at line 209 of file Owner.h.