31 m_smartptr.reset(dynamic_cast<typename T::element_type*>(ptr->clone()));
39 dynamic_cast<typename T::element_type*>(o.
m_smartptr->clone()));
43 if (
this == &o)
return *
this;
45 dynamic_cast<typename T::element_type*>(o.
m_smartptr->clone()));
51 dynamic_cast<typename T::element_type*>(o_ptr->clone()));
63 if (
this == &o)
return *
this;
69 typename T::element_type*
get()
74 throw std::runtime_error(
"dereferencing nullptr poly_ptr");
76 const typename T::element_type*
get()
const 81 throw std::runtime_error(
"dereferencing nullptr poly_ptr");
85 const typename T::element_type*
operator->()
const {
return get(); }
86 typename T::element_type&
operator*(
void) {
return *
get(); }
87 const typename T::element_type&
operator*()
const {
return *
get(); }
88 operator bool()
const {
return m_smartptr ? true :
false; }
Wrapper to a std::shared_ptr<>, adding deep-copy semantics to copy ctor and copy operator, suitable for polymorphic classes with a clone() method.
deepcopy_poly_ptr(deepcopy_poly_ptr &&o)
move ctor
deepcopy_poly_ptr< T > & operator=(const deepcopy_poly_ptr< T > &o)
const T::element_type & operator*() const
deepcopy_poly_ptr(const T &ptr)
Ctor from a smart pointer; makes deep copy.
T::element_type & operator*(void)
deepcopy_poly_ptr< T > & operator=(deepcopy_poly_ptr< T > &&o)
move operator
deepcopy_poly_ptr(const deepcopy_poly_ptr< T > &o)
copy ctor: makes a copy of the object via clone()
T::element_type * operator->()
bool operator!(void) const
const T::element_type * operator->() const
deepcopy_poly_ptr< T > & operator=(const T &o_ptr)
~deepcopy_poly_ptr()=default
deepcopy_poly_ptr()=default
Default ctor; init to nullptr.
const T & get_ptr() const