Gazebo Utils

API Reference

1.5.1
ImplPtr< T, Deleter, Operations > Class Template Reference

The ImplPtr class provides a convenient away to achieve the Rule of Zero while keeping all the benefits of PIMPL. This saves us from writing an enormous amount of boilerplate code for each class. More...

#include <ImplPtr.hh>

Public Member Functions

 ImplPtr (const ImplPtr &_other)
 Copy constructor. More...
 
 ImplPtr (ImplPtr &&)=default
 
template<class U , class D , class Ops >
 ImplPtr (U *_ptr, D &&_deleter, Ops &&_ops)
 Constructor. More...
 
 ~ImplPtr ()=default
 Destructor. More...
 
T * Get ()
 Non-const member access function. This const-unqualified operator ensures that logical const-correctness is followed by the consumer class. More...
 
const T * Get () const
 Const member access function. This const-qualified operator ensures that logical const-correctness is followed by the consumer class. More...
 
T & operator* ()
 Non-const dereference operator. This const-unqualified operator ensures that logical const-correctness is followed by the consumer class. More...
 
const T & operator* () const
 Const dereference operator. This const-qualified operator ensures that logical const-correctness is followed by the consumer class. More...
 
T * operator-> ()
 Non-const member access operator. This const-unqualified operator ensures that logical const-correctness is followed by the consumer class. More...
 
const T * operator-> () const
 Const member access operator. This const-qualified operator ensures that logical const-correctness is followed by the consumer class. More...
 
ImplPtroperator= (const ImplPtr &_other)
 Copy assignment operator. More...
 
ImplPtroperator= (ImplPtr &&)=default
 

Detailed Description

template<class T, class Deleter = void (*)(T*), class Operations = detail::CopyMoveDeleteOperations<T>>
class ignition::utils::ImplPtr< T, Deleter, Operations >

The ImplPtr class provides a convenient away to achieve the Rule of Zero while keeping all the benefits of PIMPL. This saves us from writing an enormous amount of boilerplate code for each class.

To follow PIMPL design principles, create an object of this type as the one and only member variable of your class, e.g.:

class MyClass
{
public: /* ... public member functions ... */
private: class Implementation;
private: ImplPtr<Implementation> dataPtr;
};

When constructing the dataPtr object, pass it MakeImpl<Implementation>(/* ... args ... *‍/) in the initialization list of your class.

See also
MakeImpl<T>()

This class was inspired by the following blog post: http://oliora.github.io/2015/12/29/pimpl-and-rule-of-zero.html

For interface classes that should not be copiable, see the UniqueImplPtr class further down in this header.

Note
Switching between ImplPtr and UniqueImplPtr is NOT ABI-safe. This is essentially the same as changing whether or not the class provides a copy-constructor and a copy-assignment operator, which is bound to result in runtime linking issues at a minimum (but more importantly, it changes the binary footprint of the class). If it is not obvious whether a class should be copiable, then the safest choice is to use a UniqueImplPtr and then manually add the copy constructor/operator later if it is deemed acceptable. The next time an ABI update is permitted, those manually written functions can be removed and the UniqueImplPtr can be replaced with an ImplPtr.

Constructor & Destructor Documentation

◆ ImplPtr() [1/3]

ImplPtr ( U *  _ptr,
D &&  _deleter,
Ops &&  _ops 
)

Constructor.

Template Parameters
UA type that is compatible with T, i.e. either T or a class that is derived from T.
DThe deleter type
OpsThe copy operation container type
Parameters
[in]_ptrThe raw pointer to the implementation
[in]_deleterThe deleter object
[in]_opsThe copy operation object

◆ ImplPtr() [2/3]

ImplPtr ( const ImplPtr< T, Deleter, Operations > &  _other)

Copy constructor.

Parameters
[in]_otherAnother ImplPtr of the same type

◆ ImplPtr() [3/3]

ImplPtr ( ImplPtr< T, Deleter, Operations > &&  )
default

◆ ~ImplPtr()

~ImplPtr ( )
default

Destructor.

Member Function Documentation

◆ Get() [1/2]

T* Get ( )

Non-const member access function. This const-unqualified operator ensures that logical const-correctness is followed by the consumer class.

Returns
Mutable access to the contained object's members.

◆ Get() [2/2]

const T* Get ( ) const

Const member access function. This const-qualified operator ensures that logical const-correctness is followed by the consumer class.

Returns
Immutable access to the contained object's members.

◆ operator*() [1/2]

T& operator* ( )

Non-const dereference operator. This const-unqualified operator ensures that logical const-correctness is followed by the consumer class.

Returns
A mutable reference to the contained object.

◆ operator*() [2/2]

const T& operator* ( ) const

Const dereference operator. This const-qualified operator ensures that logical const-correctness is followed by the consumer class.

Returns
A const-reference to the contained object.

◆ operator->() [1/2]

T* operator-> ( )

Non-const member access operator. This const-unqualified operator ensures that logical const-correctness is followed by the consumer class.

Returns
Mutable access to the contained object's members.

◆ operator->() [2/2]

const T* operator-> ( ) const

Const member access operator. This const-qualified operator ensures that logical const-correctness is followed by the consumer class.

Returns
Immutable access to the contained object's members.

◆ operator=() [1/2]

ImplPtr& operator= ( const ImplPtr< T, Deleter, Operations > &  _other)

Copy assignment operator.

Parameters
[in]_otherAnother ImplPtr of the same type
Returns
A reference to this ImplPtr

◆ operator=() [2/2]

ImplPtr& operator= ( ImplPtr< T, Deleter, Operations > &&  )
default

The documentation for this class was generated from the following file: