ACTS
Experiment-independent tracking
Loading...
Searching...
No Matches
Acts::CloneablePtr< T > Class Template Reference

A copyable smart pointer that uses a cloner function to copy the managed object. More...

#include <Acts/Utilities/CloneablePtr.hpp>

Inheritance diagram for Acts::CloneablePtr< T >:
[legend]

Public Types

using Cloner = std::function<std::unique_ptr<T>(const T&)>
 The type of the cloner function.
using element_type = T
 Define the type of the managed object.

Public Member Functions

 CloneablePtr ()=default
 Default constructor, creates a null pointer.
 CloneablePtr (CloneablePtr &&) noexcept=default
 Move constructor.
 CloneablePtr (const CloneablePtr &other)
 Copy constructor.
 CloneablePtr (std::unique_ptr< T > ptr)
 Construct from a unique_ptr using copy construction as the cloner.
 CloneablePtr (std::unique_ptr< T > ptr, Cloner cloner)
 Construct from a unique_ptr with a custom cloner.
 CloneablePtr (T *raw)
 Construct by taking ownership of a raw pointer using copy construction as the cloner.
 CloneablePtr (T *raw, Cloner cloner)
 Construct by taking ownership of a raw pointer with a custom cloner.
 ~CloneablePtr ()=default
 Destructor.
T * get () const
 Get the raw pointer.
 operator bool () const
 Boolean conversion, true if non-null.
T & operator* () const
 Dereference operator.
T * operator-> () const
 Arrow operator.
CloneablePtroperator= (CloneablePtr &&) noexcept=default
 Move assignment.
CloneablePtroperator= (const CloneablePtr &other) noexcept
 Copy assignment.
template<typename T1>
requires (std::is_copy_constructible_v<T1> && std::is_base_of_v<T, T1>)
CloneablePtroperator= (std::unique_ptr< T1 > &&ptr) noexcept
 Move assignment from a unique_ptr.
std::unique_ptr< T > release ()
 Release ownership of the managed object.
void reset (T *ptr=nullptr)
 Reset the managed object.

Detailed Description

template<typename T>
class Acts::CloneablePtr< T >

A copyable smart pointer that uses a cloner function to copy the managed object.

This enables polymorphic value semantics: you can copy a pointer to a base class by invoking a stored cloner function (typically calling a virtual clone() method or a copy constructor).

Template Parameters
TThe type of the managed object

Constructor & Destructor Documentation

◆ CloneablePtr() [1/5]

template<typename T>
Acts::CloneablePtr< T >::CloneablePtr ( std::unique_ptr< T > ptr,
Cloner cloner )

Construct from a unique_ptr with a custom cloner.

Parameters
ptrThe unique_ptr to take ownership of
clonerThe cloner function

◆ CloneablePtr() [2/5]

template<typename T>
Acts::CloneablePtr< T >::CloneablePtr ( std::unique_ptr< T > ptr)
explicit

Construct from a unique_ptr using copy construction as the cloner.

Parameters
ptrThe unique_ptr to take ownership of
Note
Only available when T is copy-constructible

◆ CloneablePtr() [3/5]

template<typename T>
Acts::CloneablePtr< T >::CloneablePtr ( T * raw,
Cloner cloner )

Construct by taking ownership of a raw pointer with a custom cloner.

Parameters
rawThe raw pointer to take ownership of
clonerThe cloner function

◆ CloneablePtr() [4/5]

template<typename T>
Acts::CloneablePtr< T >::CloneablePtr ( T * raw)
explicit

Construct by taking ownership of a raw pointer using copy construction as the cloner.

Parameters
rawThe raw pointer to take ownership of
Note
Only available when T is copy-constructible

◆ CloneablePtr() [5/5]

template<typename T>
Acts::CloneablePtr< T >::CloneablePtr ( const CloneablePtr< T > & other)

Copy constructor.

Invokes the cloner if the source is non-null.

Parameters
otherThe CloneablePtr to copy from

Member Function Documentation

◆ get()

template<typename T>
T * Acts::CloneablePtr< T >::get ( ) const

Get the raw pointer.

Returns
Pointer to the managed object, or nullptr

◆ operator*()

template<typename T>
T & Acts::CloneablePtr< T >::operator* ( ) const

Dereference operator.

Returns
Reference to the managed object

◆ operator->()

template<typename T>
T * Acts::CloneablePtr< T >::operator-> ( ) const

Arrow operator.

Returns
Pointer to the managed object

◆ operator=() [1/3]

template<typename T>
CloneablePtr & Acts::CloneablePtr< T >::operator= ( CloneablePtr< T > && )
defaultnoexcept

Move assignment.

Returns
Reference to this

◆ operator=() [2/3]

template<typename T>
CloneablePtr & Acts::CloneablePtr< T >::operator= ( const CloneablePtr< T > & other)
noexcept

Copy assignment.

Invokes the cloner if the source is non-null.

Parameters
otherThe CloneablePtr to copy from
Returns
Reference to this

◆ operator=() [3/3]

template<typename T>
template<typename T1>
requires (std::is_copy_constructible_v<T1> && std::is_base_of_v<T, T1>)
CloneablePtr & Acts::CloneablePtr< T >::operator= ( std::unique_ptr< T1 > && ptr)
noexcept

Move assignment from a unique_ptr.

Parameters
ptrThe unique_ptr that's assigned to this object
Returns
Reference to this

◆ release()

template<typename T>
std::unique_ptr< T > Acts::CloneablePtr< T >::release ( )

Release ownership of the managed object.

Returns
Pointer to the formerly managed object

◆ reset()

template<typename T>
void Acts::CloneablePtr< T >::reset ( T * ptr = nullptr)

Reset the managed object.

Parameters
ptrThe new raw pointer to manage (default nullptr)