jle_cpp_tk  0.0 2015-04-03 sh1:"d699093732dd5f321606d0ff7a6b63b229f1922c"
A small, safe, selft contained, soft-realtime C++ toolkit
jle::shared_ptr< _Tp, _Lp > Class Template Reference

A safe std smart pointer WRAPPER. More...

#include <shared_ptr.hpp>

Public Member Functions

constexpr shared_ptr ()
 Construct an empty shared_ptr. More...
 
 shared_ptr (const shared_ptr &)=default
 
template<typename _Tp1 >
 shared_ptr (_Tp1 *__p)
 Construct a shared_ptr that owns the pointer __p. More...
 
template<typename _Tp1 , typename _Deleter >
 shared_ptr (_Tp1 *__p, _Deleter __d)
 Construct a shared_ptr that owns the pointer __p and the deleter __d. More...
 
template<typename _Deleter >
 shared_ptr (nullptr_t __p, _Deleter __d)
 Construct a shared_ptr that owns a null pointer and the deleter __d. More...
 
template<typename _Tp1 , typename _Deleter , typename _Alloc >
 shared_ptr (_Tp1 *__p, _Deleter __d, _Alloc __a)
 Construct a shared_ptr that owns the pointer __p and the deleter __d. More...
 
template<typename _Deleter , typename _Alloc >
 shared_ptr (nullptr_t __p, _Deleter __d, _Alloc __a)
 Construct a shared_ptr that owns a null pointer and the deleter __d. More...
 
template<typename _Tp1 , typename = typename std::enable_if<std::is_convertible<_Tp1*, _Tp*>::value>::type>
 shared_ptr (const shared_ptr< _Tp1 > &__r)
 If __r is empty, constructs an empty shared_ptr; otherwise construct a shared_ptr that shares ownership with __r. More...
 
 shared_ptr (shared_ptr &&__r)
 Move-constructs a shared_ptr instance from __r. More...
 
 shared_ptr (std::shared_ptr< _Tp > &&__ptr)
 Move-constructs a shared_ptr instance from __r. More...
 
template<typename _Tp1 , typename = typename std::enable_if<std::is_convertible<_Tp1*, _Tp*>::value>::type>
 shared_ptr (shared_ptr< _Tp1 > &&__r)
 Move-constructs a shared_ptr instance from __r. More...
 
template<typename _Tp1 >
 shared_ptr (const weak_ptr< _Tp1 > &__r)
 Constructs a shared_ptr that shares ownership with __r and stores a copy of the pointer stored in __r. More...
 
template<typename _Tp1 , typename _Del >
 shared_ptr (std::unique_ptr< _Tp1, _Del > &&__r)
 
constexpr shared_ptr (nullptr_t __p)
 Construct an empty shared_ptr. More...
 
 shared_ptr (const std::shared_ptr< _Tp > &_ptr)
 
shared_ptroperator= (const shared_ptr &)=default
 
template<typename _Tp1 >
shared_ptroperator= (const shared_ptr< _Tp1 > &__r)
 
shared_ptroperator= (shared_ptr &&__r)
 
template<class _Tp1 >
shared_ptroperator= (shared_ptr< _Tp1 > &&__r)
 
template<typename _Tp1 , typename _Del >
shared_ptroperator= (std::unique_ptr< _Tp1, _Del > &&__r)
 
void reset ()
 
template<typename _Tp1 >
void reset (_Tp1 *__p)
 
template<typename _Tp1 , typename _Deleter >
void reset (_Tp1 *__p, _Deleter __d)
 
template<typename _Tp1 , typename _Deleter , typename _Alloc >
void reset (_Tp1 *__p, _Deleter __d, _Alloc __a)
 
std::add_lvalue_reference< _Tp >::type operator* () const
 
_Tp * operator-> () const
 
bool expired (void) const
 
_Tp * get () const
 
 operator bool () const
 
bool unique () const
 
long use_count () const
 
void swap (std::__shared_ptr< _Tp, _Lp > &__other)
 
template<typename _Tp1 >
bool owner_before (std::__shared_ptr< _Tp1, _Lp > const &__rhs) const
 
template<typename _Tp1 >
bool owner_before (std::__weak_ptr< _Tp1, _Lp > const &__rhs) const
 

Friends

class jle::weak_ptr< _Tp >
 

Detailed Description

template<typename _Tp, std::_Lock_policy _Lp = std::__default_lock_policy>
class jle::shared_ptr< _Tp, _Lp >

A safe std smart pointer WRAPPER.

It's almost equal to std::shared_ptr but... has the method exprired and if you try to access to noninitializated pointer, an exception will be throw

No external dependencies

Example:

Examples:
/core/ex_shared_ptr.cpp, /core/ex_test.cpp, /core/ex_weak_ptr.cpp, and /net/ex_http_server.cpp.

Constructor & Destructor Documentation

template<typename _Tp, std::_Lock_policy _Lp = std::__default_lock_policy>
constexpr jle::shared_ptr< _Tp, _Lp >::shared_ptr ( )
inline

Construct an empty shared_ptr.

Postcondition
use_count()==0 && get()==0
template<typename _Tp, std::_Lock_policy _Lp = std::__default_lock_policy>
template<typename _Tp1 >
jle::shared_ptr< _Tp, _Lp >::shared_ptr ( _Tp1 *  __p)
inlineexplicit

Construct a shared_ptr that owns the pointer __p.

Parameters
__pA pointer that is convertible to element_type*.
Postcondition
use_count() == 1 && get() == __p
Exceptions
std::bad_alloc,inwhich case delete __p is called.
template<typename _Tp, std::_Lock_policy _Lp = std::__default_lock_policy>
template<typename _Tp1 , typename _Deleter >
jle::shared_ptr< _Tp, _Lp >::shared_ptr ( _Tp1 *  __p,
_Deleter  __d 
)
inline

Construct a shared_ptr that owns the pointer __p and the deleter __d.

Parameters
__pA pointer.
__dA deleter.
Postcondition
use_count() == 1 && get() == __p
Exceptions
std::bad_alloc,inwhich case __d(__p) is called.

Requirements: _Deleter's copy constructor and destructor must not throw

__shared_ptr will release __p by calling __d(__p)

template<typename _Tp, std::_Lock_policy _Lp = std::__default_lock_policy>
template<typename _Deleter >
jle::shared_ptr< _Tp, _Lp >::shared_ptr ( nullptr_t  __p,
_Deleter  __d 
)
inline

Construct a shared_ptr that owns a null pointer and the deleter __d.

Parameters
__pA null pointer constant.
__dA deleter.
Postcondition
use_count() == 1 && get() == __p
Exceptions
std::bad_alloc,inwhich case __d(__p) is called.

Requirements: _Deleter's copy constructor and destructor must not throw

The last owner will call __d(__p)

template<typename _Tp, std::_Lock_policy _Lp = std::__default_lock_policy>
template<typename _Tp1 , typename _Deleter , typename _Alloc >
jle::shared_ptr< _Tp, _Lp >::shared_ptr ( _Tp1 *  __p,
_Deleter  __d,
_Alloc  __a 
)
inline

Construct a shared_ptr that owns the pointer __p and the deleter __d.

Parameters
__pA pointer.
__dA deleter.
__aAn allocator.
Postcondition
use_count() == 1 && get() == __p
Exceptions
std::bad_alloc,inwhich case __d(__p) is called.

Requirements: _Deleter's copy constructor and destructor must not throw _Alloc's copy constructor and destructor must not throw.

__shared_ptr will release __p by calling __d(__p)

template<typename _Tp, std::_Lock_policy _Lp = std::__default_lock_policy>
template<typename _Deleter , typename _Alloc >
jle::shared_ptr< _Tp, _Lp >::shared_ptr ( nullptr_t  __p,
_Deleter  __d,
_Alloc  __a 
)
inline

Construct a shared_ptr that owns a null pointer and the deleter __d.

Parameters
__pA null pointer constant.
__dA deleter.
__aAn allocator.
Postcondition
use_count() == 1 && get() == __p
Exceptions
std::bad_alloc,inwhich case __d(__p) is called.

Requirements: _Deleter's copy constructor and destructor must not throw _Alloc's copy constructor and destructor must not throw.

The last owner will call __d(__p)

template<typename _Tp, std::_Lock_policy _Lp = std::__default_lock_policy>
template<typename _Tp1 , typename = typename std::enable_if<std::is_convertible<_Tp1*, _Tp*>::value>::type>
jle::shared_ptr< _Tp, _Lp >::shared_ptr ( const shared_ptr< _Tp1 > &  __r)
inline

If __r is empty, constructs an empty shared_ptr; otherwise construct a shared_ptr that shares ownership with __r.

Parameters
__rA shared_ptr.
Postcondition
get() == __r.get() && use_count() == __r.use_count()
template<typename _Tp, std::_Lock_policy _Lp = std::__default_lock_policy>
jle::shared_ptr< _Tp, _Lp >::shared_ptr ( shared_ptr< _Tp, _Lp > &&  __r)
inline

Move-constructs a shared_ptr instance from __r.

Parameters
__rA shared_ptr rvalue.
Postcondition
*this contains the old value of __r, __r is empty.
template<typename _Tp, std::_Lock_policy _Lp = std::__default_lock_policy>
jle::shared_ptr< _Tp, _Lp >::shared_ptr ( std::shared_ptr< _Tp > &&  __ptr)
inlineexplicit

Move-constructs a shared_ptr instance from __r.

Parameters
__rA shared_ptr rvalue.
Postcondition
*this contains the old value of __r, __r is empty.
template<typename _Tp, std::_Lock_policy _Lp = std::__default_lock_policy>
template<typename _Tp1 , typename = typename std::enable_if<std::is_convertible<_Tp1*, _Tp*>::value>::type>
jle::shared_ptr< _Tp, _Lp >::shared_ptr ( shared_ptr< _Tp1 > &&  __r)
inline

Move-constructs a shared_ptr instance from __r.

Parameters
__rA shared_ptr rvalue.
Postcondition
*this contains the old value of __r, __r is empty.
template<typename _Tp, std::_Lock_policy _Lp = std::__default_lock_policy>
template<typename _Tp1 >
jle::shared_ptr< _Tp, _Lp >::shared_ptr ( const weak_ptr< _Tp1 > &  __r)
inlineexplicit

Constructs a shared_ptr that shares ownership with __r and stores a copy of the pointer stored in __r.

Parameters
__rA weak_ptr.
Postcondition
use_count() == __r.use_count()
Exceptions
bad_weak_ptrwhen __r.expired(), in which case the constructor has no effect.
template<typename _Tp, std::_Lock_policy _Lp = std::__default_lock_policy>
constexpr jle::shared_ptr< _Tp, _Lp >::shared_ptr ( nullptr_t  __p)
inline

Construct an empty shared_ptr.

Parameters
__pA null pointer constant.
Postcondition
use_count() == 0 && get() == nullptr

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