Samchon Framework for CPP  1.0.0
samchon::SmartPointer< _Ty > Class Template Reference

Global shared pointer
. More...

#include <SmartPointer.hpp>

Public Member Functions

 SmartPointer ()
 Default Constructor. More...
 
 SmartPointer (const _Ty *ptr)
 Constrct from pointer. More...
 
 SmartPointer (const SmartPointer &smartPointer)
 Copy Constructor. More...
 
 SmartPointer (SmartPointer &&smartPointer)
 Move constructor. More...
 
 ~SmartPointer ()
 Destroy SmartPointer. More...
 
void reset (const _Ty *ptr)
 Reset pointer. More...
 
auto get () const -> _Ty *
 Get pointer. More...
 
auto operator-> () const -> _Ty *
 Dereference object membr. More...
 
auto operator* () const -> _Ty &
 Dereference object. More...
 

Private Attributes

_Ty * ptr
 A pointer managed by SmartPointer. More...
 

Static Private Attributes

static std::map< _Ty *, size_t > useCountMap
 Map of use count of each pointer. More...
 
static std::mutex mtx
 Mutex assigned to useCountMap. More...
 

Detailed Description

template<typename _Ty>
class samchon::SmartPointer< _Ty >

Global shared pointer
.

SmartPointer is a global shared pointer based on map, map referencing.

Manages the storage of a pointer, providing a limited garbage-collection facility, possibly sharing that management with other objects.

Referenced comments of std::allocator.

Template Parameters
Thetype of managed object
Author
Jeongho Nam http://samchon.org

Definition at line 22 of file SmartPointer.hpp.

Constructor & Destructor Documentation

template<typename _Ty>
samchon::SmartPointer< _Ty >::SmartPointer ( )
inline

Default Constructor.

The object is empty (owns no pointer, use count of zero)

Definition at line 49 of file SmartPointer.hpp.

template<typename _Ty>
samchon::SmartPointer< _Ty >::SmartPointer ( const _Ty *  ptr)
inlineexplicit

Constrct from pointer.

The object owns ptr, setting the use count to add 1

Parameters
ptrThe pointer to own

Definition at line 60 of file SmartPointer.hpp.

template<typename _Ty>
samchon::SmartPointer< _Ty >::SmartPointer ( const SmartPointer< _Ty > &  smartPointer)
inline

Copy Constructor.

The object shares ownership of smartPointer's asset and increases the use count

Parameters
smartPointerThe object to copy

Definition at line 73 of file SmartPointer.hpp.

template<typename _Ty>
samchon::SmartPointer< _Ty >::SmartPointer ( SmartPointer< _Ty > &&  smartPointer)
inline

Move constructor.

The object acquires the content managed by smartPointer
The ceding object becomes empty and there's no change on use count

Parameters
smartPointerThe object to move

Definition at line 84 of file SmartPointer.hpp.

template<typename _Ty>
samchon::SmartPointer< _Ty >::~SmartPointer ( )
inline

Destroy SmartPointer.

Destroys the object. But, before, it may produce the following side effects depending on the use_count of member

  • If use_count is greater than 1: The use count is decreased by 1.
  • If use_count is 1 (i.e., the object is the unique owner of the managed pointer): the object pointed by its owned pointer is deleted.
  • If use_count is zero (i.e., the object is empty), this destructor has no side effects.

Definition at line 105 of file SmartPointer.hpp.

Member Function Documentation

template<typename _Ty>
void samchon::SmartPointer< _Ty >::reset ( const _Ty *  ptr)
inline

Reset pointer.

Reset pointer to manage and shrink use count of previous pointer.

Additionally, a call to this function has the same side effects as if SmartPointer's destructor was called before its value changed (including the deletion of the managed object if this SmartPointer was unique).

Parameters
Pointerwhose ownership is taken over by the object. Unlike std::shared_ptr, ptr being managed by another SmartPointer does not cause any problem

Definition at line 128 of file SmartPointer.hpp.

Referenced by samchon::SmartPointer< samchon::protocol::service::User >::SmartPointer().

Here is the caller graph for this function:

template<typename _Ty>
auto samchon::SmartPointer< _Ty >::get ( ) const -> _Ty*
inline

Get pointer.

Returns the stored pointer.

The stored pointer points to the object the shared_ptr object dereferences to, which is generally the same as its owned pointer.

Returns
The stored pointer

Definition at line 154 of file SmartPointer.hpp.

Referenced by samchon::protocol::service::Server::addClient().

Here is the caller graph for this function:

template<typename _Ty>
auto samchon::SmartPointer< _Ty >::operator-> ( ) const -> _Ty*
inline

Dereference object membr.

Returns a pointer to the object pointed by the stored pointer in order to access one of its members. This member function shall not be called if the stored pointer is a null pointer.

It returns the same value as get().

Returns
A pointer to be managed by SmartPointer

Definition at line 170 of file SmartPointer.hpp.

template<typename _Ty>
auto samchon::SmartPointer< _Ty >::operator* ( ) const -> _Ty&
inline

Dereference object.

Returns a reference to the object pointerd by pointer. It is equivalent to: *get()

Returns
A reference to the object pointed

Definition at line 184 of file SmartPointer.hpp.

Member Data Documentation

template<typename _Ty>
std::map< _Ty *, size_t > samchon::SmartPointer< _Ty >::useCountMap
staticprivate

Map of use count of each pointer.

Definition at line 28 of file SmartPointer.hpp.

template<typename _Ty>
std::mutex samchon::SmartPointer< _Ty >::mtx
staticprivate

Mutex assigned to useCountMap.

Definition at line 33 of file SmartPointer.hpp.

template<typename _Ty>
_Ty* samchon::SmartPointer< _Ty >::ptr
private

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