19template<
class Cloneable>
23 ClonePtr( std::nullptr_t value =
nullptr):m_ptr(nullptr){}
37 ClonePtr(
const Cloneable& src) : m_ptr( src.clone() ) { }
43 ClonePtr(
const ClonePtr& src) : m_ptr( src.m_ptr.
get() == nullptr ? nullptr : src.m_ptr->clone() ) { }
91 std::swap(first.m_ptr,second.m_ptr);
105 Cloneable*
release() noexcept { m_ptr.release();}
119 Cloneable *
get() {
return m_ptr.get();}
124 const Cloneable*
get()
const {
return m_ptr.get();}
133 const Cloneable*
operator->()
const {
return m_ptr.operator->();}
135 explicit operator bool()
const{
return (
bool)m_ptr;}
139 std::unique_ptr<Cloneable> m_ptr;
148template<
template<
typename>
typename Vector>
151 AnyVector( ) : m_type( typeid( void)){}
155 template<
class value_type>
156 void set(
unsigned size)
158 auto type_idx = std::type_index(
typeid( value_type));
159 if( type_idx != m_type)
161 m_vec.emplace<Vector<value_type>>(size);
166 auto ptr = std::any_cast<Vector<value_type>>(
175 template<
class value_type>
176 void swap ( Vector<value_type>& src)
178 auto type_idx = std::type_index(
typeid( value_type));
179 if( type_idx != m_type)
181 m_vec.emplace< Vector<value_type>>(std::move(src));
186 auto& vec = std::any_cast<Vector<value_type>&>( m_vec);
192 template<
class value_type>
193 const Vector<value_type>& get( )
const
196 return std::any_cast<const Vector<value_type>&>(
199 template<
class value_type>
200 Vector<value_type>& get( )
203 return std::any_cast<Vector<value_type>&>(
209 std::type_index m_type;
This is the namespace for all functions and classes defined and used by the discontinuous Galerkin li...
Manager class that invokes the clone() method on the managed ptr when copied.
Definition memory.h:21
Cloneable * operator->()
Dereference pointer to owned object, i.e. get()
Definition memory.h:131
void reset(const Cloneable &src)
Clone the given object and replace the currently held one.
Definition memory.h:110
Cloneable * get()
Get a pointer to the object on the heap.
Definition memory.h:119
friend void swap(ClonePtr &first, ClonePtr &second)
swap the managed pointers
Definition memory.h:89
ClonePtr(const Cloneable &src)
clone the given value and manage
Definition memory.h:37
void reset(Cloneable *ptr)
Replace the managed object.
Definition memory.h:101
ClonePtr(const ClonePtr &src)
deep copy the given handle using the clone() method of Cloneable
Definition memory.h:43
const Cloneable * get() const
Get a constant pointer to the object on the heap.
Definition memory.h:124
ClonePtr(ClonePtr &&src) noexcept
Steal resources (move construct)
Definition memory.h:59
ClonePtr(Cloneable *ptr)
take ownership of the pointer
Definition memory.h:28
Cloneable & operator*()
Dereference pointer to owned object, i.e. *get()
Definition memory.h:127
const Cloneable * operator->() const
Dereference pointer to owned object, i.e. get()
Definition memory.h:133
ClonePtr(std::nullptr_t value=nullptr)
init an empty ClonePtr
Definition memory.h:23
ClonePtr & operator=(const ClonePtr &src)
deep copy the given handle using the clone() method of Cloneable
Definition memory.h:48
const Cloneable & operator*() const
Dereference pointer to owned object, i.e. *get()
Definition memory.h:129
ClonePtr & operator=(ClonePtr &&src) noexcept
Steal resources (move assignment)
Definition memory.h:67
Cloneable * release() noexcept
Releases ownership of managed object, get() returns nullptr after call.
Definition memory.h:105