17template<
class Cloneable>
21 ClonePtr( std::nullptr_t value =
nullptr):m_ptr(nullptr){}
35 ClonePtr(
const Cloneable& src) : m_ptr( src.clone() ) { }
41 ClonePtr(
const ClonePtr& src) : m_ptr( src.m_ptr.
get() == nullptr ? nullptr : src.m_ptr->clone() ) { }
89 std::swap(first.m_ptr,second.m_ptr);
103 Cloneable*
release() noexcept { m_ptr.release();}
117 Cloneable *
get() {
return m_ptr.get();}
122 const Cloneable*
get()
const {
return m_ptr.get();}
131 const Cloneable*
operator->()
const {
return m_ptr.operator->();}
133 explicit operator bool()
const{
return (
bool)m_ptr;}
137 std::unique_ptr<Cloneable> m_ptr;
162 ptr =
new T(*src.ptr);
178 swap( first.ptr, second.ptr);
187 T&
data( )
const {
return *ptr;}
This is the namespace for all functions and classes defined and used by the discontinuous Galerkin li...
a manager class that invokes the copy constructor on the managed ptr when copied (deep copy)
Definition: memory.h:152
Buffer(const T &t)
new T(t)
Definition: memory.h:158
~Buffer()
delete managed object
Definition: memory.h:172
T & data() const
Get write access to the data on the heap.
Definition: memory.h:187
friend void swap(Buffer &first, Buffer &second)
Definition: memory.h:175
Buffer(const Buffer &src)
Definition: memory.h:161
Buffer()
new T
Definition: memory.h:154
Buffer & operator=(Buffer src)
Definition: memory.h:167
Buffer(Buffer &&t)
Definition: memory.h:164
Manager class that invokes the clone() method on the managed ptr when copied.
Definition: memory.h:19
Cloneable * operator->()
Dereference pointer to owned object, i.e. get()
Definition: memory.h:129
void reset(const Cloneable &src)
Clone the given object and replace the currently held one.
Definition: memory.h:108
Cloneable * get()
Get a pointer to the object on the heap.
Definition: memory.h:117
friend void swap(ClonePtr &first, ClonePtr &second)
swap the managed pointers
Definition: memory.h:87
ClonePtr(const Cloneable &src)
clone the given value and manage
Definition: memory.h:35
void reset(Cloneable *ptr)
Replace the managed object.
Definition: memory.h:99
ClonePtr(const ClonePtr &src)
deep copy the given handle using the clone() method of Cloneable
Definition: memory.h:41
const Cloneable * get() const
Get a constant pointer to the object on the heap.
Definition: memory.h:122
ClonePtr(ClonePtr &&src) noexcept
Steal resources (move construct)
Definition: memory.h:57
ClonePtr(Cloneable *ptr)
take ownership of the pointer
Definition: memory.h:26
Cloneable & operator*()
Dereference pointer to owned object, i.e. *get()
Definition: memory.h:125
const Cloneable * operator->() const
Dereference pointer to owned object, i.e. get()
Definition: memory.h:131
ClonePtr(std::nullptr_t value=nullptr)
init an empty ClonePtr
Definition: memory.h:21
ClonePtr & operator=(const ClonePtr &src)
deep copy the given handle using the clone() method of Cloneable
Definition: memory.h:46
const Cloneable & operator*() const
Dereference pointer to owned object, i.e. *get()
Definition: memory.h:127
ClonePtr & operator=(ClonePtr &&src) noexcept
Steal resources (move assignment)
Definition: memory.h:65
Cloneable * release() noexcept
Releases ownership of managed object, get() returns nullptr after call.
Definition: memory.h:103