Quick Links:

bal | bbl | bdl | bsl

Public Types | Public Member Functions | Friends

bsl::weak_ptr< ELEMENT_TYPE > Class Template Reference

#include <bslstl_sharedptr.h>

List of all members.

Public Types

typedef bsl::remove_extent
< ELEMENT_TYPE >::type 
element_type

Public Member Functions

 BSLMF_NESTED_TRAIT_DECLARATION (weak_ptr< ELEMENT_TYPE >, bsl::is_nothrow_move_constructible)
BSLS_KEYWORD_CONSTEXPR weak_ptr () BSLS_KEYWORD_NOEXCEPT
 weak_ptr (BloombergLP::bslmf::MovableRef< weak_ptr > original) BSLS_KEYWORD_NOEXCEPT
template<class COMPATIBLE_TYPE >
 weak_ptr (BloombergLP::bslmf::MovableRef< weak_ptr< COMPATIBLE_TYPE > > other) BSLS_KEYWORD_NOEXCEPT
 weak_ptr (const weak_ptr &original) BSLS_KEYWORD_NOEXCEPT
template<class COMPATIBLE_TYPE >
 weak_ptr (const shared_ptr< COMPATIBLE_TYPE > &other) BSLS_KEYWORD_NOEXCEPT
template<class COMPATIBLE_TYPE >
 weak_ptr (const weak_ptr< COMPATIBLE_TYPE > &other) BSLS_KEYWORD_NOEXCEPT
 ~weak_ptr ()
weak_ptroperator= (BloombergLP::bslmf::MovableRef< weak_ptr > rhs) BSLS_KEYWORD_NOEXCEPT
weak_ptroperator= (const weak_ptr &rhs) BSLS_KEYWORD_NOEXCEPT
template<class COMPATIBLE_TYPE >
enable_if< is_convertible
< COMPATIBLE_TYPE
*, ELEMENT_TYPE * >::value,
weak_ptr & >::type 
operator= (BloombergLP::bslmf::MovableRef< weak_ptr< COMPATIBLE_TYPE > > rhs) BSLS_KEYWORD_NOEXCEPT
template<class COMPATIBLE_TYPE >
enable_if< is_convertible
< COMPATIBLE_TYPE
*, ELEMENT_TYPE * >::value,
weak_ptr & >::type 
operator= (const shared_ptr< COMPATIBLE_TYPE > &rhs) BSLS_KEYWORD_NOEXCEPT
template<class COMPATIBLE_TYPE >
enable_if< is_convertible
< COMPATIBLE_TYPE
*, ELEMENT_TYPE * >::value,
weak_ptr & >::type 
operator= (const weak_ptr< COMPATIBLE_TYPE > &rhs) BSLS_KEYWORD_NOEXCEPT
void reset () BSLS_KEYWORD_NOEXCEPT
void swap (weak_ptr &other) BSLS_KEYWORD_NOEXCEPT
bool expired () const BSLS_KEYWORD_NOEXCEPT
shared_ptr< ELEMENT_TYPE > lock () const BSLS_KEYWORD_NOEXCEPT
template<class ANY_TYPE >
bool owner_before (const shared_ptr< ANY_TYPE > &other) const BSLS_KEYWORD_NOEXCEPT
template<class ANY_TYPE >
bool owner_before (const weak_ptr< ANY_TYPE > &other) const BSLS_KEYWORD_NOEXCEPT
BloombergLP::bslma::SharedPtrRep * rep () const BSLS_KEYWORD_NOEXCEPT
long use_count () const BSLS_KEYWORD_NOEXCEPT
shared_ptr< ELEMENT_TYPE > acquireSharedPtr () const BSLS_KEYWORD_NOEXCEPT
int numReferences () const BSLS_KEYWORD_NOEXCEPT

Friends

class weak_ptr
struct BloombergLP::bslstl::SharedPtr_ImpUtil

Detailed Description

template<class ELEMENT_TYPE>
class bsl::weak_ptr< ELEMENT_TYPE >

This class provides a mechanism to create weak references to reference-counted shared (shared_ptr) objects. A weak reference provides conditional access to a shared object managed by a shared_ptr, but, unlike a shared (or "strong") reference, does not affect the shared object's lifetime.

See Component bslstl_sharedptr


Member Typedef Documentation

template<class ELEMENT_TYPE>
typedef bsl::remove_extent<ELEMENT_TYPE>::type bsl::weak_ptr< ELEMENT_TYPE >::element_type

Constructor & Destructor Documentation

template<class ELEMENT_TYPE>
BSLS_KEYWORD_CONSTEXPR bsl::weak_ptr< ELEMENT_TYPE >::weak_ptr (  ) 

Create a weak pointer in the empty state and referring to no object, i.e., a weak pointer having no representation.

template<class ELEMENT_TYPE>
bsl::weak_ptr< ELEMENT_TYPE >::weak_ptr ( BloombergLP::bslmf::MovableRef< weak_ptr< ELEMENT_TYPE > >  original  ) 

Create a weak pointer that refers to the same object (if any) as the specified original weak pointer, and reset original to an empty state.

template<class ELEMENT_TYPE>
template<class COMPATIBLE_TYPE >
bsl::weak_ptr< ELEMENT_TYPE >::weak_ptr ( BloombergLP::bslmf::MovableRef< weak_ptr< COMPATIBLE_TYPE > >  other  ) 

Create a weak pointer that refers to the same object (if any) as the specified other weak pointer, and reset original to an empty state. Note that this operation does not involve any change to reference counts.

template<class ELEMENT_TYPE>
bsl::weak_ptr< ELEMENT_TYPE >::weak_ptr ( const weak_ptr< ELEMENT_TYPE > &  original  ) 

Create a weak pointer that refers to the same object (if any) as the specified original weak pointer, and increment the number of weak references to the object managed by original (if any). Note that if original is in the empty state, this weak pointer will be initialized to the empty state.

template<class ELEMENT_TYPE>
template<class COMPATIBLE_TYPE >
bsl::weak_ptr< ELEMENT_TYPE >::weak_ptr ( const shared_ptr< COMPATIBLE_TYPE > &  other  ) 

IMPLICIT:

template<class ELEMENT_TYPE>
template<class COMPATIBLE_TYPE >
bsl::weak_ptr< ELEMENT_TYPE >::weak_ptr ( const weak_ptr< COMPATIBLE_TYPE > &  other  ) 

IMPLICIT: Create a weak pointer that refers to the same object (if any) as the specified other (shared or weak) pointer of the (template parameter) COMPATIBLE_TYPE, and increment the number of weak references to the object managed by other (if any). If COMPATIBLE_TYPE * is not implicitly convertible to ELEMENT_TYPE *, then a compiler diagnostic will be emitted. Note that if other is in the empty state, this weak pointer will be initialized to the empty state.

template<class ELEMENT_TYPE>
bsl::weak_ptr< ELEMENT_TYPE >::~weak_ptr (  ) 

Destroy this weak pointer object. If this weak pointer manages a (possibly shared) object, release the weak reference to that object.


Member Function Documentation

template<class ELEMENT_TYPE>
bsl::weak_ptr< ELEMENT_TYPE >::BSLMF_NESTED_TRAIT_DECLARATION ( weak_ptr< ELEMENT_TYPE >  ,
bsl::is_nothrow_move_constructible   
)
template<class ELEMENT_TYPE>
weak_ptr& bsl::weak_ptr< ELEMENT_TYPE >::operator= ( BloombergLP::bslmf::MovableRef< weak_ptr< ELEMENT_TYPE > >  rhs  ) 

Make this weak pointer refer to the same object (if any) as the specified rhs weak pointer. If rhs is not a reference to this weak pointer, decrement the number of weak references to the object this weak pointer managed (if any), and reset rhs to an empty state. Return a reference providing modifiable access to this weak pointer. Note that if rhs is in an empty state, this weak pointer will be set to an empty state.

template<class ELEMENT_TYPE>
weak_ptr& bsl::weak_ptr< ELEMENT_TYPE >::operator= ( const weak_ptr< ELEMENT_TYPE > &  rhs  ) 

Make this weak pointer refer to the same object (if any) as the specified rhs weak pointer. Decrement the number of weak references to the object this weak pointer manages (if any), and increment the number of weak references to the object managed by rhs (if any). Return a reference providing modifiable access to this weak pointer. Note that if rhs is in an empty state, this weak pointer will be set to an empty state.

template<class ELEMENT_TYPE>
template<class COMPATIBLE_TYPE >
enable_if< is_convertible<COMPATIBLE_TYPE *, ELEMENT_TYPE *>::value, weak_ptr&>::type bsl::weak_ptr< ELEMENT_TYPE >::operator= ( BloombergLP::bslmf::MovableRef< weak_ptr< COMPATIBLE_TYPE > >  rhs  ) 

Make this weak pointer refer to the same object (if any) as the specified rhs weak pointer. Decrement the number of weak references to the object this weak pointer managed (if any), and reset rhs to an empty state. Return a reference providing modifiable access to this weak pointer. This function does not exist unless a pointer to (the template parameter) COMPATIBLE_TYPE is convertible to a pointer to (the template parameter) ELEMENT_TYPE. Note that if rhs is in an empty state, this weak pointer will be set to an empty state.

template<class ELEMENT_TYPE>
template<class COMPATIBLE_TYPE >
enable_if< is_convertible<COMPATIBLE_TYPE *, ELEMENT_TYPE *>::value, weak_ptr&>::type bsl::weak_ptr< ELEMENT_TYPE >::operator= ( const shared_ptr< COMPATIBLE_TYPE > &  rhs  ) 
template<class ELEMENT_TYPE>
template<class COMPATIBLE_TYPE >
enable_if< is_convertible<COMPATIBLE_TYPE *, ELEMENT_TYPE *>::value, weak_ptr&>::type bsl::weak_ptr< ELEMENT_TYPE >::operator= ( const weak_ptr< COMPATIBLE_TYPE > &  rhs  ) 

Make this weak pointer refer to the same object (if any) as the specified rhs (shared or weak) pointer to the (template parameter) COMPATIBLE_TYPE. Decrement the number of weak references to the object to which this weak pointer currently manages (if any), and increment the number of weak references to the object managed by rhs (if any). Return a reference providing modifiable access to this weak pointer. If COMPATIBLE_TYPE * is not implicitly convertible to TYPE *, then a compiler diagnostic will be emitted. Note that if rhs is in the empty state, this weak pointer will be set to the empty state.

template<class ELEMENT_TYPE>
void bsl::weak_ptr< ELEMENT_TYPE >::reset (  ) 

Reset this weak pointer to the empty state. If this weak pointer manages a (possibly shared) object, then decrement the number of weak references to that object.

template<class ELEMENT_TYPE>
void bsl::weak_ptr< ELEMENT_TYPE >::swap ( weak_ptr< ELEMENT_TYPE > &  other  ) 

Efficiently exchange the states of this weak pointer and the specified other weak pointer such that each will refer to the object (if any) and representation (if any) formerly referred to and managed by the other.

template<class ELEMENT_TYPE>
bool bsl::weak_ptr< ELEMENT_TYPE >::expired (  )  const

Return true if this weak pointer is in the empty state or the object that it originally referenced has been destroyed, and false otherwise.

template<class ELEMENT_TYPE>
shared_ptr<ELEMENT_TYPE> bsl::weak_ptr< ELEMENT_TYPE >::lock (  )  const

Return a shared pointer to the object referred to by this weak pointer if false == expired(), and a shared pointer in the empty state otherwise.

template<class ELEMENT_TYPE>
template<class ANY_TYPE >
bool bsl::weak_ptr< ELEMENT_TYPE >::owner_before ( const shared_ptr< ANY_TYPE > &  other  )  const
template<class ELEMENT_TYPE>
template<class ANY_TYPE >
bool bsl::weak_ptr< ELEMENT_TYPE >::owner_before ( const weak_ptr< ANY_TYPE > &  other  )  const

Return true if the address of the BloombergLP::bslma::SharedPtrRep object used by this weak pointer is ordered before the address of the BloombergLP::bslma::SharedPtrRep object used by the specified other shared pointer under the total ordering defined by std::less<BloombergLP::bslma::SharedPtrRep *>, and false otherwise.

template<class ELEMENT_TYPE>
BloombergLP::bslma::SharedPtrRep* bsl::weak_ptr< ELEMENT_TYPE >::rep (  )  const

Return the address providing modifiable access to the BloombergLP::bslma::SharedPtrRep object held by this weak pointer, or 0 if this weak pointer is in the empty state.

template<class ELEMENT_TYPE>
long bsl::weak_ptr< ELEMENT_TYPE >::use_count (  )  const

Return a "snapshot" of the current number of shared pointers that share ownership of the object referred to by this weak pointer, or 0 if this weak pointer is in the empty state. Note that any result other than 0 may be unreliable in a multi-threaded program, where another pointer sharing ownership in a different thread may be copied or destroyed, or another weak pointer may be locked in the case that 1 is returned (that would otherwise indicate unique ownership).

template<class ELEMENT_TYPE>
shared_ptr<ELEMENT_TYPE> bsl::weak_ptr< ELEMENT_TYPE >::acquireSharedPtr (  )  const

Return a shared pointer to the object referred to by this weak pointer and managing the same object as that managed by this weak pointer (if any) if false == expired(), and a shared pointer in the empty state otherwise. Note that the behavior of this method is the same as that of lock.

template<class ELEMENT_TYPE>
int bsl::weak_ptr< ELEMENT_TYPE >::numReferences (  )  const

[!DEPRECATED!] Use use_count instead.

Return a "snapshot" of the current number of shared pointers that share ownership of the object referred to by this weak pointer, or 0 if this weak pointer is in the empty state. Note that the behavior of this method is the same as that of use_count, and the result may be unreliable in multi-threaded code for the same reasons.


Friends And Related Function Documentation

template<class ELEMENT_TYPE>
friend class weak_ptr [friend]
template<class ELEMENT_TYPE>
friend struct BloombergLP::bslstl::SharedPtr_ImpUtil [friend]

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