19template<
class Cloneable>
39 ClonePtr(
const Cloneable& src) : m_ptr( src.clone() ) { }
45 ClonePtr(
const ClonePtr& src) : m_ptr( src.m_ptr.
get() == nullptr ? nullptr : src.m_ptr->clone() ) { }
93 std::swap(first.m_ptr,second.m_ptr);
107 Cloneable*
release() noexcept { m_ptr.release();}
121 Cloneable *
get() {
return m_ptr.get();}
126 const Cloneable*
get()
const {
return m_ptr.get();}
135 const Cloneable*
operator->()
const {
return m_ptr.operator->();}
137 explicit operator bool()
const{
return (
bool)m_ptr;}
141 std::unique_ptr<Cloneable> m_ptr;
150template<
template<
typename>
typename Vector>
153 AnyVector( ) : m_type( typeid( void)){}
157 template<
class value_type>
158 void set(
unsigned size)
160 auto type_idx = std::type_index(
typeid(
value_type));
161 if( type_idx != m_type)
163 m_vec.emplace<Vector<value_type>>(size);
168 auto ptr = std::any_cast<Vector<value_type>>(
177 template<
class value_type>
178 void swap ( Vector<value_type>& src)
180 auto type_idx = std::type_index(
typeid(
value_type));
181 if( type_idx != m_type)
183 m_vec.emplace< Vector<value_type>>(std::move(src));
188 auto& vec = std::any_cast<Vector<value_type>&>( m_vec);
194 template<
class value_type>
195 const Vector<value_type>& get( )
const
198 return std::any_cast<const Vector<value_type>&>(
201 template<
class value_type>
202 Vector<value_type>& get( )
205 return std::any_cast<Vector<value_type>&>(
211 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:133
void reset(const Cloneable &src)
Clone the given object and replace the currently held one.
Definition memory.h:112
Cloneable * get()
Get a pointer to the object on the heap.
Definition memory.h:121
friend void swap(ClonePtr &first, ClonePtr &second)
swap the managed pointers
Definition memory.h:91
ClonePtr(const Cloneable &src)
clone the given value and manage
Definition memory.h:39
ClonePtr()
init an empty ClonePtr
Definition memory.h:23
void reset(Cloneable *ptr)
Replace the managed object.
Definition memory.h:103
ClonePtr(const ClonePtr &src)
deep copy the given handle using the clone() method of Cloneable
Definition memory.h:45
const Cloneable * get() const
Get a constant pointer to the object on the heap.
Definition memory.h:126
ClonePtr(ClonePtr &&src) noexcept
Steal resources (move construct)
Definition memory.h:61
ClonePtr(Cloneable *ptr)
take ownership of the pointer
Definition memory.h:30
Cloneable & operator*()
Dereference pointer to owned object, i.e. *get()
Definition memory.h:129
const Cloneable * operator->() const
Dereference pointer to owned object, i.e. get()
Definition memory.h:135
ClonePtr(std::nullptr_t)
init an empty ClonePtr
Definition memory.h:25
ClonePtr & operator=(const ClonePtr &src)
deep copy the given handle using the clone() method of Cloneable
Definition memory.h:50
const Cloneable & operator*() const
Dereference pointer to owned object, i.e. *get()
Definition memory.h:131
ClonePtr & operator=(ClonePtr &&src) noexcept
Steal resources (move assignment)
Definition memory.h:69
Cloneable * release() noexcept
Releases ownership of managed object, get() returns nullptr after call.
Definition memory.h:107