Discontinuous Galerkin Library
#include "dg/algorithm.h"
|
Manager class that invokes the clone()
method on the managed ptr when copied.
More...
Public Member Functions | |
ClonePtr (std::nullptr_t value=nullptr) | |
init an empty ClonePtr More... | |
ClonePtr (Cloneable *ptr) | |
take ownership of the pointer More... | |
ClonePtr (const Cloneable &src) | |
clone the given value and manage More... | |
ClonePtr (const ClonePtr &src) | |
deep copy the given handle using the clone() method of Cloneable More... | |
ClonePtr & | operator= (const ClonePtr &src) |
deep copy the given handle using the clone() method of Cloneable More... | |
ClonePtr (ClonePtr &&src) noexcept | |
Steal resources (move construct) More... | |
ClonePtr & | operator= (ClonePtr &&src) noexcept |
Steal resources (move assignment) More... | |
void | reset (Cloneable *ptr) |
Replace the managed object. More... | |
Cloneable * | release () noexcept |
Releases ownership of managed object, get() returns nullptr after call. More... | |
void | reset (const Cloneable &src) |
Clone the given object and replace the currently held one. More... | |
Cloneable * | get () |
Get a pointer to the object on the heap. More... | |
const Cloneable * | get () const |
Get a constant pointer to the object on the heap. More... | |
Cloneable & | operator* () |
Dereference pointer to owned object, i.e. *get () More... | |
const Cloneable & | operator* () const |
Dereference pointer to owned object, i.e. *get () More... | |
Cloneable * | operator-> () |
Dereference pointer to owned object, i.e. get() More... | |
const Cloneable * | operator-> () const |
Dereference pointer to owned object, i.e. get() More... | |
operator bool () const | |
true if *this owns an object, false else More... | |
Friends | |
void | swap (ClonePtr &first, ClonePtr &second) |
swap the managed pointers More... | |
Manager class that invokes the clone()
method on the managed ptr when copied.
When copied invokes a deep copy using the clone()
method. This class is most useful when a class needs to hold a polymorphic, Cloneable oject as a variable.
Cloneable | a type that may be uncopyable/unassignable but provides the clone() method with signature
|
|
inline |
init an empty ClonePtr
|
inline |
take ownership of the pointer
ptr | a pointer to object to manage |
|
inline |
clone the given value and manage
src
is cloned, src
is allowed to go out of scope after ClonePtr
was initialized. src | an object to clone |
|
inline |
deep copy the given handle using the clone()
method of Cloneable
src | an oject to copy, clones the contained object if not empty |
|
inlinenoexcept |
Steal resources (move construct)
src | an object to steal pointer from |
|
inline |
Get a pointer to the object on the heap.
nullptr
if no object owned
|
inline |
Get a constant pointer to the object on the heap.
nullptr
if no object owned
|
inlineexplicit |
true
if *this
owns an object, false
else
|
inline |
Dereference pointer to owned object, i.e. *get
()
|
inline |
Dereference pointer to owned object, i.e. *get
()
|
inline |
Dereference pointer to owned object, i.e. get()
|
inline |
Dereference pointer to owned object, i.e. get()
|
inlinenoexcept |
Steal resources (move assignment)
src | an object to steal pointer from |
|
inline |
deep copy the given handle using the clone()
method of Cloneable
src | an oject to copy and swap |
|
inlinenoexcept |
Releases ownership of managed object, get()
returns nullptr
after call.
|
inline |
Replace the managed object.
Take the ownership of the given pointer and delete the currently held one if non-empty
ptr | a pointer to a new object to manage |
|
inline |
Clone the given object and replace the currently held one.
src | a Cloneable object |
|
friend |
swap the managed pointers
This follows the discussion in https://stackoverflow.com/questions/5695548/public-friend-swap-member-function
first | first instance |
second | second instance |