2 #ifndef OPENLIBRARY_UTILS_COPY_PTR
3 #define OPENLIBRARY_UTILS_COPY_PTR
9 namespace OpenLibrary_CopyPtr
18 void copier(T* &to_ptr,
const T *from_ptr)
20 if (from_ptr ==
nullptr)
23 to_ptr =
new T(*from_ptr);
39 typedef void (*
Copier)(T* &,
const T *);
46 data_ptr(T *ptr =
nullptr,
Deleter d = &OpenLibrary_CopyPtr::deleter,
Copier c = &OpenLibrary_CopyPtr::copier): m_ptr(ptr), m_deleter(d), m_copier(c)
67 other.m_ptr =
nullptr;
87 data_ptr& operator=(
const data_ptr<T> &other)
100 const T* operator->()
const
110 const T& operator *()
const
142 void copy(
const data_ptr<T> &other)
145 m_deleter = other.m_deleter;
146 m_copier = other.m_copier;
154 void move(
const data_ptr<T> &other)
156 m_deleter = other.m_deleter;
157 m_copier = other.m_copier;
168 getCopier()(m_ptr, ptr);
void(* Deleter)(T *)
deleter for hold object
Definition: data_ptr.hpp:38
Copyable data smart pointer.
Definition: data_ptr.hpp:35
data_ptr(T *ptr=nullptr, Deleter d=&OpenLibrary_CopyPtr::deleter, Copier c=&OpenLibrary_CopyPtr::copier)
Constructor.
Definition: data_ptr.hpp:46
void(* Copier)(T *&, const T *)
interface of copying function
Definition: data_ptr.hpp:39
data_ptr(data_ptr< T > &&other)
Move constructor.
Definition: data_ptr.hpp:64
data_ptr(const data_ptr< T > &other)
Copy constructor.
Definition: data_ptr.hpp:55