#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 () | |
SharedPtr & | operator= (const SharedPtr< EMEMORY_TYPE > &_obj) |
SharedPtr & | operator= (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::Counter * | getCounter () 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]
ememory::SharedPtr< EMEMORY_TYPE >::SharedPtr | ( | EMEMORY_TYPE2 * | _element | ) |
Contructor whith the pointer of data.
- Parameters
-
[in] _element allocated data (SharedPtr will remove it)
§ SharedPtr() [2/6]
ememory::SharedPtr< EMEMORY_TYPE >::SharedPtr | ( | std::nullptr_t | ) |
Contructor on nullptr.
§ SharedPtr() [3/6]
ememory::SharedPtr< EMEMORY_TYPE >::SharedPtr | ( | ) |
Contructor empty.
§ SharedPtr() [4/6]
ememory::SharedPtr< EMEMORY_TYPE >::SharedPtr | ( | EMEMORY_TYPE * | _obj, |
ememory::Counter * | _counter | ||
) |
Contructor (API for casting)
- Parameters
-
[in] _obj Pointer on the Data [in] _counter Pointer on the counter
§ SharedPtr() [5/6]
ememory::SharedPtr< EMEMORY_TYPE >::SharedPtr | ( | const SharedPtr< EMEMORY_TYPE > & | _obj | ) |
copy Contructor
- Parameters
-
[in] _obj SharedPtr to copy
§ SharedPtr() [6/6]
ememory::SharedPtr< EMEMORY_TYPE >::SharedPtr | ( | SharedPtr< EMEMORY_TYPE > && | _obj | ) |
copy Contructor
- Parameters
-
[in] _obj SharedPtr to copy
§ ~SharedPtr()
ememory::SharedPtr< EMEMORY_TYPE >::~SharedPtr | ( | ) |
Destructor.
Member Function Documentation
§ get() [1/2]
const EMEMORY_TYPE* ememory::SharedPtr< EMEMORY_TYPE >::get | ( | ) | const |
Get a const pointer on the data.
- Returns
- Data const pointer
§ get() [2/2]
EMEMORY_TYPE* ememory::SharedPtr< EMEMORY_TYPE >::get | ( | ) |
Get a pointer on the data.
- Returns
- Data pointer
§ getCounter()
|
inline |
Get Counter pointer.
- Returns
- Pointer on the counter
§ getDeleter()
|
inline |
Get deleter function of the data pointer.
- Returns
- deleter function
§ operator!=() [1/2]
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]
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] _obj Object to compare
- Returns
- true The Object have NOT the same pointer reference, false otherwise
§ operator*() [1/2]
const EMEMORY_TYPE& ememory::SharedPtr< EMEMORY_TYPE >::operator* | ( | ) | const |
Get a const reference on the data.
- Returns
- Data const reference
§ operator*() [2/2]
EMEMORY_TYPE& ememory::SharedPtr< EMEMORY_TYPE >::operator* | ( | ) |
Get a reference on the data.
- Returns
- Data reference
§ operator->() [1/2]
const EMEMORY_TYPE* ememory::SharedPtr< EMEMORY_TYPE >::operator-> | ( | ) | const |
Const dereferences the stored pointer.
- Returns
- Const pointer on the Data
§ operator->() [2/2]
EMEMORY_TYPE* ememory::SharedPtr< EMEMORY_TYPE >::operator-> | ( | ) |
Dereferences the stored pointer.
- Returns
- Pointer on the Data
§ operator=() [1/2]
SharedPtr& ememory::SharedPtr< EMEMORY_TYPE >::operator= | ( | const SharedPtr< EMEMORY_TYPE > & | _obj | ) |
§ operator=() [2/2]
SharedPtr& ememory::SharedPtr< EMEMORY_TYPE >::operator= | ( | std::nullptr_t | ) |
Asignement operator (asign nullptr)
- Returns
- Reference on this
§ operator==() [1/2]
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]
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] _obj Object to compare
- Returns
- true The Object have the same pointer reference, false otherwise
§ reset()
void ememory::SharedPtr< EMEMORY_TYPE >::reset | ( | ) |
Reset the SharedPtr ==> Remove data if needed.
§ swap()
void ememory::SharedPtr< EMEMORY_TYPE >::swap | ( | SharedPtr< EMEMORY_TYPE > & | _obj | ) |
Swap 2 Object inside the SharedPtr.
- Parameters
-
[in] _obj Object to swap with
§ useCount()
int64_t ememory::SharedPtr< EMEMORY_TYPE >::useCount | ( | ) | const |
The documentation for this class was generated from the following file:
- framework/atria-soft/ememory/ememory/SharedPtr.hpp