Honeycomb  0.1
Component-Model Framework
Classes | Public Types | Public Member Functions | Friends | Related Functions | List of all members
honey::SharedPtr< T > Class Template Reference

Combined intrusive/non-intrusive smart pointer. Can reference and share any object automatically. More...

#include <SharedPtr.h>

Inheritance diagram for honey::SharedPtr< T >:
Inheritance graph
[legend]
Collaboration diagram for honey::SharedPtr< T >:
Collaboration graph
[legend]

Public Types

typedef T Elem
 
typedef Ref_< Elem >::type Ref
 

Public Member Functions

 SharedPtr ()
 
 SharedPtr (nullptr_t)
 
template<class U , typename std::enable_if< mt::True< U >::value &&isIntrusive, int >::type = 0>
 SharedPtr (U *ptr)
 Reference an object, allowing for implicit construction. For intrusive pointers only. More...
 
template<class U , class Fin = finalize<U>, class Alloc = typename DefaultAllocator<U>::type, typename mt::disable_if< mt::True< U >::value &&isIntrusive, int >::type = 0>
 SharedPtr (U *ptr, Fin &&f=Fin(), Alloc &&a=Alloc())
 Reference an object with finalizer and internal control block allocator. For non-intrusive pointers only. More...
 
 SharedPtr (const SharedPtr &ptr)
 Reference the object pointed to by another shared pointer. More...
 
template<class U >
 SharedPtr (const SharedPtr< U > &ptr)
 
 SharedPtr (SharedPtr &&ptr)
 Transfer ownership out of shared pointer, leaving it null. More...
 
template<class U >
 SharedPtr (SharedPtr< U > &&ptr)
 
template<class U >
 SharedPtr (const WeakPtr< U > &ptr)
 Lock a weak pointer to get access to its object. Shared ptr will be null if the object has already been destroyed. More...
 
template<class U , class Fin >
 SharedPtr (UniquePtr< U, Fin > &&ptr)
 Transfer ownership out of unique pointer, leaving it null. More...
 
 ~SharedPtr ()
 
SharedPtroperator= (const SharedPtr &rhs)
 
template<class U >
SharedPtroperator= (const SharedPtr< U > &rhs)
 
SharedPtroperator= (SharedPtr &&rhs)
 
template<class U >
SharedPtroperator= (SharedPtr< U > &&rhs)
 
template<class U , class Fin , typename std::enable_if< mt::True< U >::value &&isIntrusive, int >::type = 0>
SharedPtroperator= (UniquePtr< U, Fin > &&rhs)
 
template<class U , class Fin , typename mt::disable_if< mt::True< U >::value &&isIntrusive, int >::type = 0>
SharedPtroperator= (UniquePtr< U, Fin > &&rhs)
 
template<class U >
bool operator== (const SharedPtr< U > &rhs) const
 
template<class U >
bool operator!= (const SharedPtr< U > &rhs) const
 
template<class U >
bool operator< (const SharedPtr< U > &rhs) const
 
template<class U >
bool operator> (const SharedPtr< U > &rhs) const
 
template<class U >
bool operator<= (const SharedPtr< U > &rhs) const
 
template<class U >
bool operator>= (const SharedPtr< U > &rhs) const
 
bool operator== (nullptr_t) const
 
bool operator!= (nullptr_t) const
 
T * operator-> () const
 
Ref operator* () const
 
 operator T * () const
 
T * get () const
 Get the raw pointer to the object. More...
 
template<class U , typename std::enable_if< mt::True< U >::value &&isIntrusive, int >::type = 0>
void set (U *ptr)
 Dereference the current object and reference a new object. For intrusive pointers only. More...
 
template<class U , class Fin = finalize<U>, class Alloc = typename DefaultAllocator<U>::type, typename mt::disable_if< mt::True< U >::value &&isIntrusive, int >::type = 0>
void set (U *ptr, Fin &&f=Fin(), Alloc &&a=Alloc())
 Dereference the current object and reference a new object, with finalizer and internal control block allocator. For non-intrusive pointers only. More...
 
void set (nullptr_t)
 
int refCount () const
 Get number of shared references to the object. More...
 
bool unique () const
 Check whether this is the only shared reference to the object. More...
 

Friends

template<class >
class SharedPtr
 
template<class >
class WeakPtr
 
template<class , class >
struct priv::SharedControl_obj
 
template<class T_ , class U >
SharedPtr< T_ > static_pointer_cast (const SharedPtr< U > &)
 
template<class T_ , class U >
SharedPtr< T_ > dynamic_pointer_cast (const SharedPtr< U > &)
 
template<class T_ , class U >
SharedPtr< T_ > const_pointer_cast (const SharedPtr< U > &)
 
bool operator== (nullptr_t, const SharedPtr &rhs)
 
bool operator!= (nullptr_t, const SharedPtr &rhs)
 

Related Functions

(Note that these are not member functions.)

template<class T , class Alloc , class... Args, typename mt::disable_if< mt::is_base_of< priv::SharedObj_tag, T >::value, int >::type = 0>
SharedPtr< T > alloc_shared (Alloc &&a, Args &&...args)
 Create a shared ptr to an object of type T constructed with args. The object and the internal control block are allocated together in a single allocation. More...
 
template<class T , class Alloc , class... Args, typename std::enable_if< mt::is_base_of< priv::SharedObj_tag, T >::value, int >::type = 0>
SharedPtr< T > alloc_shared (Alloc &&a, Args &&...args)
 Specializaton for intrusive pointers, simply allocates T and constructs with args. More...
 
template<class T , class... Args, class Alloc = typename DefaultAllocator<T>::type>
SharedPtr< T > make_shared (Args &&...args)
 alloc_shared() using T::Allocator if available, otherwise std::allocator More...
 
template<class T , class U >
SharedPtr< T > static_pointer_cast (const SharedPtr< U > &rhs)
 
template<class T , class U >
SharedPtr< T > dynamic_pointer_cast (const SharedPtr< U > &rhs)
 
template<class T , class U >
SharedPtr< T > const_pointer_cast (const SharedPtr< U > &rhs)
 

Detailed Description

template<class T>
class honey::SharedPtr< T >

Combined intrusive/non-intrusive smart pointer. Can reference and share any object automatically.

Non-intrusive pointers use the finalizer and internal control block allocator supplied as arguments.
Intrusive pointers finalize with SharedObj::finalize() and don't require an internal control block allocator.

See also
SharedObj, WeakPtr

Member Typedef Documentation

template<class T>
typedef T honey::SharedPtr< T >::Elem
template<class T>
typedef Ref_<Elem>::type honey::SharedPtr< T >::Ref

Constructor & Destructor Documentation

template<class T>
honey::SharedPtr< T >::SharedPtr ( )
inline
template<class T>
honey::SharedPtr< T >::SharedPtr ( nullptr_t  )
inline
template<class T>
template<class U , typename std::enable_if< mt::True< U >::value &&isIntrusive, int >::type = 0>
honey::SharedPtr< T >::SharedPtr ( U *  ptr)
inline

Reference an object, allowing for implicit construction. For intrusive pointers only.

template<class T>
template<class U , class Fin = finalize<U>, class Alloc = typename DefaultAllocator<U>::type, typename mt::disable_if< mt::True< U >::value &&isIntrusive, int >::type = 0>
honey::SharedPtr< T >::SharedPtr ( U *  ptr,
Fin &&  f = Fin(),
Alloc &&  a = Alloc() 
)
inlineexplicit

Reference an object with finalizer and internal control block allocator. For non-intrusive pointers only.

Finalizer is run when reference count reaches 0 (deletes object by default).

template<class T>
honey::SharedPtr< T >::SharedPtr ( const SharedPtr< T > &  ptr)
inline

Reference the object pointed to by another shared pointer.

template<class T>
template<class U >
honey::SharedPtr< T >::SharedPtr ( const SharedPtr< U > &  ptr)
inline
template<class T>
honey::SharedPtr< T >::SharedPtr ( SharedPtr< T > &&  ptr)
inline

Transfer ownership out of shared pointer, leaving it null.

template<class T>
template<class U >
honey::SharedPtr< T >::SharedPtr ( SharedPtr< U > &&  ptr)
inline
template<class T>
template<class U >
honey::SharedPtr< T >::SharedPtr ( const WeakPtr< U > &  ptr)
inlineexplicit

Lock a weak pointer to get access to its object. Shared ptr will be null if the object has already been destroyed.

template<class T>
template<class U , class Fin >
honey::SharedPtr< T >::SharedPtr ( UniquePtr< U, Fin > &&  ptr)
inline

Transfer ownership out of unique pointer, leaving it null.

template<class T>
honey::SharedPtr< T >::~SharedPtr ( )
inline

Member Function Documentation

template<class T>
T* honey::SharedPtr< T >::get ( ) const
inline

Get the raw pointer to the object.

template<class T>
honey::SharedPtr< T >::operator T * ( ) const
inline
template<class T>
template<class U >
bool honey::SharedPtr< T >::operator!= ( const SharedPtr< U > &  rhs) const
inline
template<class T>
bool honey::SharedPtr< T >::operator!= ( nullptr_t  ) const
inline
template<class T>
Ref honey::SharedPtr< T >::operator* ( ) const
inline
template<class T>
T* honey::SharedPtr< T >::operator-> ( ) const
inline
template<class T>
template<class U >
bool honey::SharedPtr< T >::operator< ( const SharedPtr< U > &  rhs) const
inline
template<class T>
template<class U >
bool honey::SharedPtr< T >::operator<= ( const SharedPtr< U > &  rhs) const
inline
template<class T>
SharedPtr& honey::SharedPtr< T >::operator= ( const SharedPtr< T > &  rhs)
inline
template<class T>
template<class U >
SharedPtr& honey::SharedPtr< T >::operator= ( const SharedPtr< U > &  rhs)
inline
template<class T>
SharedPtr& honey::SharedPtr< T >::operator= ( SharedPtr< T > &&  rhs)
inline
template<class T>
template<class U >
SharedPtr& honey::SharedPtr< T >::operator= ( SharedPtr< U > &&  rhs)
inline
template<class T>
template<class U , class Fin , typename std::enable_if< mt::True< U >::value &&isIntrusive, int >::type = 0>
SharedPtr& honey::SharedPtr< T >::operator= ( UniquePtr< U, Fin > &&  rhs)
inline
template<class T>
template<class U , class Fin , typename mt::disable_if< mt::True< U >::value &&isIntrusive, int >::type = 0>
SharedPtr& honey::SharedPtr< T >::operator= ( UniquePtr< U, Fin > &&  rhs)
inline
template<class T>
template<class U >
bool honey::SharedPtr< T >::operator== ( const SharedPtr< U > &  rhs) const
inline
template<class T>
bool honey::SharedPtr< T >::operator== ( nullptr_t  ) const
inline
template<class T>
template<class U >
bool honey::SharedPtr< T >::operator> ( const SharedPtr< U > &  rhs) const
inline
template<class T>
template<class U >
bool honey::SharedPtr< T >::operator>= ( const SharedPtr< U > &  rhs) const
inline
template<class T>
int honey::SharedPtr< T >::refCount ( ) const
inline

Get number of shared references to the object.

template<class T>
template<class U , typename std::enable_if< mt::True< U >::value &&isIntrusive, int >::type = 0>
void honey::SharedPtr< T >::set ( U *  ptr)
inline

Dereference the current object and reference a new object. For intrusive pointers only.

template<class T>
template<class U , class Fin = finalize<U>, class Alloc = typename DefaultAllocator<U>::type, typename mt::disable_if< mt::True< U >::value &&isIntrusive, int >::type = 0>
void honey::SharedPtr< T >::set ( U *  ptr,
Fin &&  f = Fin(),
Alloc &&  a = Alloc() 
)
inline

Dereference the current object and reference a new object, with finalizer and internal control block allocator. For non-intrusive pointers only.

template<class T>
void honey::SharedPtr< T >::set ( nullptr_t  )
inline
template<class T>
bool honey::SharedPtr< T >::unique ( ) const
inline

Check whether this is the only shared reference to the object.

Friends And Related Function Documentation

template<class T , class Alloc , class... Args, typename std::enable_if< mt::is_base_of< priv::SharedObj_tag, T >::value, int >::type = 0>
SharedPtr< T > alloc_shared ( Alloc &&  a,
Args &&...  args 
)
related

Specializaton for intrusive pointers, simply allocates T and constructs with args.

template<class T>
template<class T_ , class U >
SharedPtr<T_> const_pointer_cast ( const SharedPtr< U > &  )
friend
template<class T>
template<class T_ , class U >
SharedPtr<T_> dynamic_pointer_cast ( const SharedPtr< U > &  )
friend
template<class T>
bool operator!= ( nullptr_t  ,
const SharedPtr< T > &  rhs 
)
friend
template<class T>
bool operator== ( nullptr_t  ,
const SharedPtr< T > &  rhs 
)
friend
template<class T>
template<class , class >
friend struct priv::SharedControl_obj
friend
template<class T>
template<class >
friend class SharedPtr
friend
template<class T>
template<class T_ , class U >
SharedPtr<T_> static_pointer_cast ( const SharedPtr< U > &  )
friend
template<class T>
template<class >
friend class WeakPtr
friend

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