BDE 4.14.0 Production release
|
#include <bslstl_sharedptr.h>
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 BSLSTL_SHAREDPTR_DECLARE_IF_COMPATIBLE> | |
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 BSLSTL_SHAREDPTR_DECLARE_IF_COMPATIBLE> | |
weak_ptr (const shared_ptr< COMPATIBLE_TYPE > &other) BSLS_KEYWORD_NOEXCEPT | |
template<class COMPATIBLE_TYPE BSLSTL_SHAREDPTR_DECLARE_IF_COMPATIBLE> | |
weak_ptr (const weak_ptr< COMPATIBLE_TYPE > &other) BSLS_KEYWORD_NOEXCEPT | |
~weak_ptr () | |
weak_ptr & | operator= (BloombergLP::bslmf::MovableRef< weak_ptr > rhs) BSLS_KEYWORD_NOEXCEPT |
weak_ptr & | operator= (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 |
template<class ANY_TYPE > | |
bool | owner_equal (const shared_ptr< ANY_TYPE > &other) const BSLS_KEYWORD_NOEXCEPT |
template<class ANY_TYPE > | |
bool | owner_equal (const weak_ptr< ANY_TYPE > &other) const BSLS_KEYWORD_NOEXCEPT |
size_t | owner_hash () 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 |
template<class CONVERTIBLE_TYPE BSLSTL_SHAREDPTR_DEFINE_IF_CONVERTIBLE> | |
weak_ptr (BloombergLP::bslmf::MovableRef< weak_ptr< CONVERTIBLE_TYPE > > original) BSLS_KEYWORD_NOEXCEPT | |
Friends | |
template<class COMPATIBLE_TYPE > | |
class | weak_ptr |
struct | BloombergLP::bslstl::SharedPtr_ImpUtil |
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 bslstl_sharedptr
typedef bsl::remove_extent<ELEMENT_TYPE>::type bsl::weak_ptr< ELEMENT_TYPE >::element_type |
For weak pointers to non-array types, element_type is an alias to the ELEMENT_TYPE
template parameter. Otherwise, it is an alias to the type contained in the array.
|
inline |
Create a weak pointer in the empty state and referring to no object, i.e., a weak pointer having no representation.
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.
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.
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.
bsl::weak_ptr< ELEMENT_TYPE >::weak_ptr | ( | const shared_ptr< COMPATIBLE_TYPE > & | other | ) |
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.
bsl::weak_ptr< ELEMENT_TYPE >::weak_ptr | ( | const weak_ptr< COMPATIBLE_TYPE > & | other | ) |
|
inline |
Destroy this weak pointer object. If this weak pointer manages a (possibly shared) object, release the weak reference to that object.
bsl::weak_ptr< ELEMENT_TYPE >::weak_ptr | ( | BloombergLP::bslmf::MovableRef< weak_ptr< CONVERTIBLE_TYPE > > | original | ) |
|
inline |
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
.
bsl::weak_ptr< ELEMENT_TYPE >::BSLMF_NESTED_TRAIT_DECLARATION | ( | weak_ptr< ELEMENT_TYPE > | , |
bsl::is_nothrow_move_constructible | |||
) |
|
inline |
Return true
if this weak pointer is in the empty state or the object that it originally referenced has been destroyed, and false
otherwise.
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.
|
inline |
[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.
weak_ptr< ELEMENT_TYPE > & 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.
enable_if< is_convertible< COMPATIBLE_TYPE *, ELEMENT_TYPE * >::value, weak_ptr< ELEMENT_TYPE > & >::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.
enable_if< is_convertible< COMPATIBLE_TYPE *, ELEMENT_TYPE * >::value, weak_ptr< ELEMENT_TYPE > & >::type bsl::weak_ptr< ELEMENT_TYPE >::operator= | ( | const shared_ptr< COMPATIBLE_TYPE > & | rhs | ) |
weak_ptr< ELEMENT_TYPE > & 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.
enable_if< is_convertible< COMPATIBLE_TYPE *, ELEMENT_TYPE * >::value, weak_ptr< ELEMENT_TYPE > & >::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.
|
inline |
|
inline |
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.
|
inline |
|
inline |
Return true
if the address of the BloombergLP::bslma::SharedPtrRep
object used by this shared pointer is equal to the address of the BloombergLP::bslma::SharedPtrRep
object used by the specified other
shared pointer, and false
otherwise.
|
inline |
Return an unspecified value such that, for any object x
where owner_equal(x)
is true, owner_hash() == x.owner_hash()
is true. Note that this is based on the hash of the address of the BloombergLP::bslma::SharedPtrRep
object used by this object. Note also that for two empty smart pointers x
and y
, x.owner_hash() == y.owner_hash()
is true.
|
inline |
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.
|
inline |
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.
|
inline |
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.
|
inline |
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).
|
friend |
This friend
declaration provides access to the internal data members while constructing a weak pointer from a weak pointer of a different type.