OpenLibrary
Public Types | Public Member Functions | List of all members
ol::data_ptr< T > Class Template Reference

Copyable data smart pointer. More...

#include <data_ptr.hpp>

Public Types

typedef void(* Deleter) (T *)
 deleter for hold object
 
typedef void(* Copier) (T *&, const T *)
 interface of copying function
 

Public Member Functions

 data_ptr (T *ptr=nullptr, Deleter d=&OpenLibrary_CopyPtr::deleter, Copier c=&OpenLibrary_CopyPtr::copier)
 Constructor. More...
 
 data_ptr (const data_ptr< T > &other)
 Copy constructor. More...
 
 data_ptr (data_ptr< T > &&other)
 Move constructor. More...
 
data_ptroperator= (T *ptr)
 
data_ptroperator= (const data_ptr< T > &other)
 
T * operator-> ()
 
const T * operator-> () const
 
T & operator* ()
 
const T & operator* () const
 
T * get ()
 
const T * get () const
 

Detailed Description

template<class T>
class ol::data_ptr< T >

Copyable data smart pointer.

When data_ptr is copied, it makes a copy of hold object. So it behaves similarly std::shared_ptr, but instead of pointing to the same data a copy of data occurs. data_ptr can be used for storing class' private data which on class copy should also be copied. operator= of data_ptr and copy constructor of data_ptr are calling copy constructor of encapsulated type.

Constructor & Destructor Documentation

template<class T>
ol::data_ptr< T >::data_ptr ( T *  ptr = nullptr,
Deleter  d = &OpenLibrary_CopyPtr::deleter,
Copier  c = &OpenLibrary_CopyPtr::copier 
)
inline

Constructor.

Constructs data_ptr object and stores pointer to object of type T inside. data_ptr takes ownership over passed pointer.

  • d object deleter. A function which takes pointer to T as parameter. Responsibility of deleter is to delete owned pointer when data_ptr is destroyed.
  • c object copier. A function of type data_ptr::Copier. It is called on data_ptr copy. Its responsibility is to create new instance of T and initialize it with data from copied data_ptr.
template<class T>
ol::data_ptr< T >::data_ptr ( const data_ptr< T > &  other)
inline

Copy constructor.

Makes copy of data_ptr. Object kept in data_ptr will be copied too.

template<class T>
ol::data_ptr< T >::data_ptr ( data_ptr< T > &&  other)
inline

Move constructor.

Moves data from one data_ptr to another. No copies are made. Source data_ptr becomes empty.


The documentation for this class was generated from the following file: