ememory::SharedPtr< EMEMORY_TYPE > Class Template Reference

#include <SharedPtr.hpp>

Public Member Functions

 SharedPtr (EMEMORY_TYPE2 *_element)
 
 SharedPtr (std::nullptr_t)
 
 SharedPtr ()
 
 SharedPtr (EMEMORY_TYPE *_obj, ememory::Counter *_counter)
 
 SharedPtr (const SharedPtr< EMEMORY_TYPE > &_obj)
 
 SharedPtr (SharedPtr< EMEMORY_TYPE > &&_obj)
 
 ~SharedPtr ()
 
SharedPtroperator= (const SharedPtr< EMEMORY_TYPE > &_obj)
 
SharedPtroperator= (std::nullptr_t)
 
void reset ()
 
int64_t useCount () const
 
bool operator== (std::nullptr_t) const
 
template<class EMEMORY_TYPE2 >
bool operator== (const SharedPtr< EMEMORY_TYPE2 > &_obj) const
 
bool operator!= (std::nullptr_t) const
 
template<class EMEMORY_TYPE2 >
bool operator!= (const SharedPtr< EMEMORY_TYPE2 > &_obj) const
 
const EMEMORY_TYPE * get () const
 
EMEMORY_TYPE * get ()
 
const EMEMORY_TYPE * operator-> () const
 
EMEMORY_TYPE * operator-> ()
 
const EMEMORY_TYPE & operator* () const
 
EMEMORY_TYPE & operator* ()
 
void swap (SharedPtr< EMEMORY_TYPE > &_obj)
 
ememory::CountergetCounter () const
 
deleterCall getDeleter () const
 

Friends

class WeakPtr< EMEMORY_TYPE >
 

Detailed Description

template<typename EMEMORY_TYPE>
class ememory::SharedPtr< EMEMORY_TYPE >

ememory::SharedPtr is a smart pointer that retains shared ownership of an object through a pointer. Several SharedPtr objects may own the same object. The object is destroyed and its memory deallocated when either of the following happens:

  • the last remaining SharedPtr owning the object is destroyed;
  • the last remaining SharedPtr owning the object is assigned another pointer via operator= or reset(). The object is destroyed using delete-expression or a custom deleter that is supplied to shared_ptr during construction.

A SharedPtr can share ownership of an object while storing a pointer to another object. This feature can be used to point to member objects while owning the object they belong to. The stored pointer is the one accessed by get(), the dereference and the comparison operators. The managed pointer is the one passed to the deleter when use count reaches zero.

Note
A big difference whith this wrapper is the constness sharing. When your sharedPtr is shared, the internal pointer is shared too.

Constructor & Destructor Documentation

§ SharedPtr() [1/6]

template<typename EMEMORY_TYPE>
ememory::SharedPtr< EMEMORY_TYPE >::SharedPtr ( EMEMORY_TYPE2 *  _element)

Contructor whith the pointer of data.

Parameters
[in]_elementallocated data (SharedPtr will remove it)

§ SharedPtr() [2/6]

template<typename EMEMORY_TYPE>
ememory::SharedPtr< EMEMORY_TYPE >::SharedPtr ( std::nullptr_t  )

Contructor on nullptr.

§ SharedPtr() [3/6]

template<typename EMEMORY_TYPE>
ememory::SharedPtr< EMEMORY_TYPE >::SharedPtr ( )

Contructor empty.

§ SharedPtr() [4/6]

template<typename EMEMORY_TYPE>
ememory::SharedPtr< EMEMORY_TYPE >::SharedPtr ( EMEMORY_TYPE *  _obj,
ememory::Counter _counter 
)

Contructor (API for casting)

Parameters
[in]_objPointer on the Data
[in]_counterPointer on the counter

§ SharedPtr() [5/6]

template<typename EMEMORY_TYPE>
ememory::SharedPtr< EMEMORY_TYPE >::SharedPtr ( const SharedPtr< EMEMORY_TYPE > &  _obj)

copy Contructor

Parameters
[in]_objSharedPtr to copy

§ SharedPtr() [6/6]

template<typename EMEMORY_TYPE>
ememory::SharedPtr< EMEMORY_TYPE >::SharedPtr ( SharedPtr< EMEMORY_TYPE > &&  _obj)

copy Contructor

Parameters
[in]_objSharedPtr to copy

§ ~SharedPtr()

template<typename EMEMORY_TYPE>
ememory::SharedPtr< EMEMORY_TYPE >::~SharedPtr ( )

Destructor.

Member Function Documentation

§ get() [1/2]

template<typename EMEMORY_TYPE>
const EMEMORY_TYPE* ememory::SharedPtr< EMEMORY_TYPE >::get ( ) const

Get a const pointer on the data.

Returns
Data const pointer

§ get() [2/2]

template<typename EMEMORY_TYPE>
EMEMORY_TYPE* ememory::SharedPtr< EMEMORY_TYPE >::get ( )

Get a pointer on the data.

Returns
Data pointer

§ getCounter()

template<typename EMEMORY_TYPE>
ememory::Counter* ememory::SharedPtr< EMEMORY_TYPE >::getCounter ( ) const
inline

Get Counter pointer.

Returns
Pointer on the counter

§ getDeleter()

template<typename EMEMORY_TYPE>
deleterCall ememory::SharedPtr< EMEMORY_TYPE >::getDeleter ( ) const
inline

Get deleter function of the data pointer.

Returns
deleter function

§ operator!=() [1/2]

template<typename EMEMORY_TYPE>
bool ememory::SharedPtr< EMEMORY_TYPE >::operator!= ( std::nullptr_t  ) const

Check if the SharedPtr have NOT an internal data (nullptr)

Returns
true The pointer is asigned, false otherwise

§ operator!=() [2/2]

template<typename EMEMORY_TYPE>
template<class EMEMORY_TYPE2 >
bool ememory::SharedPtr< EMEMORY_TYPE >::operator!= ( const SharedPtr< EMEMORY_TYPE2 > &  _obj) const

Check if two SharedPtr are NOT the same data (maybe not the same cast)

Parameters
[in]_objObject to compare
Returns
true The Object have NOT the same pointer reference, false otherwise

§ operator*() [1/2]

template<typename EMEMORY_TYPE>
const EMEMORY_TYPE& ememory::SharedPtr< EMEMORY_TYPE >::operator* ( ) const

Get a const reference on the data.

Returns
Data const reference

§ operator*() [2/2]

template<typename EMEMORY_TYPE>
EMEMORY_TYPE& ememory::SharedPtr< EMEMORY_TYPE >::operator* ( )

Get a reference on the data.

Returns
Data reference

§ operator->() [1/2]

template<typename EMEMORY_TYPE>
const EMEMORY_TYPE* ememory::SharedPtr< EMEMORY_TYPE >::operator-> ( ) const

Const dereferences the stored pointer.

Returns
Const pointer on the Data

§ operator->() [2/2]

template<typename EMEMORY_TYPE>
EMEMORY_TYPE* ememory::SharedPtr< EMEMORY_TYPE >::operator-> ( )

Dereferences the stored pointer.

Returns
Pointer on the Data

§ operator=() [1/2]

template<typename EMEMORY_TYPE>
SharedPtr& ememory::SharedPtr< EMEMORY_TYPE >::operator= ( const SharedPtr< EMEMORY_TYPE > &  _obj)

Asignement operator.

Parameters
[in]_objSharedPtr to copy
Returns
Reference on this

§ operator=() [2/2]

template<typename EMEMORY_TYPE>
SharedPtr& ememory::SharedPtr< EMEMORY_TYPE >::operator= ( std::nullptr_t  )

Asignement operator (asign nullptr)

Returns
Reference on this

§ operator==() [1/2]

template<typename EMEMORY_TYPE>
bool ememory::SharedPtr< EMEMORY_TYPE >::operator== ( std::nullptr_t  ) const

Check if the SharedPtr have an internal data (not nullptr)

Returns
true The pointer is not asigned, false otherwise

§ operator==() [2/2]

template<typename EMEMORY_TYPE>
template<class EMEMORY_TYPE2 >
bool ememory::SharedPtr< EMEMORY_TYPE >::operator== ( const SharedPtr< EMEMORY_TYPE2 > &  _obj) const

Check if two SharedPtr are the same data (maybe not the same cast)

Parameters
[in]_objObject to compare
Returns
true The Object have the same pointer reference, false otherwise

§ reset()

template<typename EMEMORY_TYPE>
void ememory::SharedPtr< EMEMORY_TYPE >::reset ( )

Reset the SharedPtr ==> Remove data if needed.

§ swap()

template<typename EMEMORY_TYPE>
void ememory::SharedPtr< EMEMORY_TYPE >::swap ( SharedPtr< EMEMORY_TYPE > &  _obj)

Swap 2 Object inside the SharedPtr.

Parameters
[in]_objObject to swap with

§ useCount()

template<typename EMEMORY_TYPE>
int64_t ememory::SharedPtr< EMEMORY_TYPE >::useCount ( ) const

Get the number of conencted SharedPtr.

Returns
Number of SharedPtr on this data

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