BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bslma::ManagedPtr< TARGET_TYPE > Class Template Reference

#include <bslma_managedptr.h>

Public Types

typedef ManagedPtrDeleter::Deleter DeleterFunc
 
typedef TARGET_TYPE element_type
 Alias to the TARGET_TYPE template parameter.
 

Public Member Functions

 ManagedPtr ()
 Create an empty managed pointer.
 
template<class MANAGED_TYPE >
 ManagedPtr (MANAGED_TYPE *ptr)
 
 ManagedPtr (ManagedPtr_Ref< TARGET_TYPE > ref) BSLS_KEYWORD_NOEXCEPT
 
 ManagedPtr (ManagedPtr &original) BSLS_KEYWORD_NOEXCEPT
 
 ManagedPtr (bslmf::MovableRef< ManagedPtr > original) BSLS_KEYWORD_NOEXCEPT
 
template<class BDE_OTHER_TYPE >
 ManagedPtr (bslmf::MovableRef< ManagedPtr< BDE_OTHER_TYPE > > original, typename bsl::enable_if< bsl::is_convertible< BDE_OTHER_TYPE *, TARGET_TYPE * >::value, ManagedPtr_TraitConstraint >::type=ManagedPtr_TraitConstraint()) BSLS_KEYWORD_NOEXCEPT
 
template<class ALIASED_TYPE >
 ManagedPtr (ManagedPtr< ALIASED_TYPE > &alias, TARGET_TYPE *ptr)
 
template<class ALIASED_TYPE >
 ManagedPtr (bslmf::MovableRef< ManagedPtr< ALIASED_TYPE > > alias, TARGET_TYPE *ptr)
 
template<class MANAGED_TYPE , class FACTORY_TYPE >
 ManagedPtr (MANAGED_TYPE *ptr, FACTORY_TYPE *factory)
 
 ManagedPtr (bsl::nullptr_t, bsl::nullptr_t=0)
 
template<class FACTORY_TYPE >
 ManagedPtr (bsl::nullptr_t, FACTORY_TYPE *factory)
 
 ManagedPtr (TARGET_TYPE *ptr, void *cookie, DeleterFunc deleter)
 
template<class MANAGED_TYPE >
 ManagedPtr (MANAGED_TYPE *ptr, void *cookie, DeleterFunc deleter)
 
template<class MANAGED_TYPE , class MANAGED_BASE >
 ManagedPtr (MANAGED_TYPE *ptr, void *cookie, void(*deleter)(MANAGED_BASE *, void *))
 
template<class MANAGED_TYPE , class MANAGED_BASE , class COOKIE_TYPE , class COOKIE_BASE >
 ManagedPtr (MANAGED_TYPE *ptr, COOKIE_TYPE *cookie, void(*deleter)(MANAGED_BASE *, COOKIE_BASE *))
 
 ~ManagedPtr ()
 
ManagedPtroperator= (ManagedPtr &rhs) BSLS_KEYWORD_NOEXCEPT
 
ManagedPtroperator= (bslmf::MovableRef< ManagedPtr > rhs) BSLS_KEYWORD_NOEXCEPT
 
template<class BDE_OTHER_TYPE >
bsl::enable_if< bsl::is_convertible< BDE_OTHER_TYPE *, TARGET_TYPE * >::value, ManagedPtr< TARGET_TYPE > >::type & operator= (bslmf::MovableRef< ManagedPtr< BDE_OTHER_TYPE > > rhs) BSLS_KEYWORD_NOEXCEPT
 
ManagedPtroperator= (ManagedPtr_Ref< TARGET_TYPE > ref) BSLS_KEYWORD_NOEXCEPT
 
ManagedPtroperator= (bsl::nullptr_t)
 
template<class REFERENCED_TYPE >
 operator ManagedPtr_Ref< REFERENCED_TYPE > ()
 
void clear ()
 
template<class MANAGED_TYPE >
void load (MANAGED_TYPE *ptr)
 
template<class MANAGED_TYPE , class FACTORY_TYPE >
void load (MANAGED_TYPE *ptr, FACTORY_TYPE *factory)
 
template<class MANAGED_TYPE >
void load (MANAGED_TYPE *ptr, void *cookie, DeleterFunc deleter)
 
void load (bsl::nullptr_t=0, void *cookie=0, DeleterFunc deleter=0)
 
template<class MANAGED_TYPE , class COOKIE_TYPE >
void load (MANAGED_TYPE *ptr, COOKIE_TYPE *cookie, DeleterFunc deleter)
 
template<class MANAGED_TYPE , class MANAGED_BASE >
void load (MANAGED_TYPE *ptr, void *cookie, void(*deleter)(MANAGED_BASE *, void *))
 
template<class MANAGED_TYPE , class MANAGED_BASE , class COOKIE_TYPE , class COOKIE_BASE >
void load (MANAGED_TYPE *ptr, COOKIE_TYPE *cookie, void(*deleter)(MANAGED_BASE *, COOKIE_BASE *))
 
template<class ALIASED_TYPE >
void loadAlias (ManagedPtr< ALIASED_TYPE > &alias, TARGET_TYPE *ptr)
 
ManagedPtr_PairProxy< TARGET_TYPE, ManagedPtrDeleterrelease ()
 
TARGET_TYPE * release (ManagedPtrDeleter *deleter)
 
void reset ()
 
void swap (ManagedPtr &other)
 
 operator BoolType () const
 
bslmf::AddReference< TARGET_TYPE >::Type operator* () const
 
TARGET_TYPE * operator-> () const
 
const ManagedPtrDeleterdeleter () const
 
TARGET_TYPE * get () const
 
TARGET_TYPE * ptr () const
 

Friends

template<class ALIASED_TYPE >
class ManagedPtr
 

Detailed Description

template<class TARGET_TYPE>
class bslma::ManagedPtr< TARGET_TYPE >

This class is a "smart pointer" that refers to a target object accessed via a pointer to the specified parameter type, TARGET_TYPE, and that supports sole ownership of a managed object that is potentially of a different type, and may be an entirely different object from the target object. A managed pointer ensures that the object it manages is destroyed when the managed pointer is destroyed (or re-assigned), using the "deleter" supplied along with the managed object. The target object referenced by a managed pointer may be accessed using either the -> operator, or the dereference operator (operator *). The specified TARGET_TYPE may be const-qualified, but may not be volatile-qualified, nor may it be a reference type.

A managed pointer may be empty, in which case it neither refers to a target object nor owns a managed object. An empty managed pointer is the equivalent of a null pointer: Such a managed pointer is not de-referenceable, and tests as false in boolean expressions.

A managed pointer for which the managed object is not the same object as the target is said to alias the managed object (see the section "Aliasing" in the component-level documentation).

See bslma_managedptr

Member Typedef Documentation

◆ DeleterFunc

template<class TARGET_TYPE >
typedef ManagedPtrDeleter::Deleter bslma::ManagedPtr< TARGET_TYPE >::DeleterFunc

Alias for a function-pointer type for functions used to destroy the object managed by a ManagedPtr object.

◆ element_type

template<class TARGET_TYPE >
typedef TARGET_TYPE bslma::ManagedPtr< TARGET_TYPE >::element_type

Constructor & Destructor Documentation

◆ ManagedPtr() [1/15]

template<class TARGET_TYPE >
bslma::ManagedPtr< TARGET_TYPE >::ManagedPtr ( )
inline

◆ ManagedPtr() [2/15]

template<class TARGET_TYPE >
template<class MANAGED_TYPE >
bslma::ManagedPtr< TARGET_TYPE >::ManagedPtr ( MANAGED_TYPE *  ptr)
inlineexplicit

Create a managed pointer having a target object referenced by the specified ptr, owning the managed object *ptr, and having a deleter that will call delete ptr to destroy the managed object when invoked (e.g., when this managed pointer object is destroyed), unless 0 == ptr, in which case create an empty managed pointer. The deleter will invoke the destructor of MANAGED_TYPE rather than the destructor of TARGET_TYPE. This constructor will not compile unless MANAGED_TYPE * is convertible to TARGET_TYPE *. Note that this behavior allows ManagedPtr to be defined for void pointers, and to call the correct destructor for the managed object, even if the destructor for TARGET_TYPE is not declared as virtual. The behavior is undefined unless the managed object (if any) can be destroyed by delete, or if the lifetime of the managed object is already managed by another object.

◆ ManagedPtr() [3/15]

template<class TARGET_TYPE >
bslma::ManagedPtr< TARGET_TYPE >::ManagedPtr ( ManagedPtr_Ref< TARGET_TYPE >  ref)
inline

Create a managed pointer having the same target object as the managed pointer referenced by the specified ref, transfer ownership of the managed object owned by the managed pointer referenced by ref, and reset the managed pointer referenced by ref to empty. This constructor is used to create a managed pointer from a managed pointer rvalue, or from a managed pointer to a "compatible" type, where "compatible" means a built-in conversion from COMPATIBLE_TYPE * to TARGET_TYPE * is defined, e.g., derived * to base *, T * to const T *, or T * to void *.

◆ ManagedPtr() [4/15]

template<class TARGET_TYPE >
bslma::ManagedPtr< TARGET_TYPE >::ManagedPtr ( ManagedPtr< TARGET_TYPE > &  original)
inline

◆ ManagedPtr() [5/15]

template<class TARGET_TYPE >
bslma::ManagedPtr< TARGET_TYPE >::ManagedPtr ( bslmf::MovableRef< ManagedPtr< TARGET_TYPE > >  original)
inline

Create a managed pointer having the same target object as the specified original, transfer ownership of the object managed by original (if any) to this managed pointer, and reset original to empty.

◆ ManagedPtr() [6/15]

template<class TARGET_TYPE >
template<class BDE_OTHER_TYPE >
bslma::ManagedPtr< TARGET_TYPE >::ManagedPtr ( bslmf::MovableRef< ManagedPtr< BDE_OTHER_TYPE > >  original,
typename bsl::enable_if< bsl::is_convertible< BDE_OTHER_TYPE *, TARGET_TYPE * >::value, ManagedPtr_TraitConstraint >::type  = ManagedPtr_TraitConstraint() 
)
inline

Create a managed pointer having the same target object as the specified original, transfer ownership of the object managed by original (if any) to this managed pointer, and reset original to empty. TARGET_TYPE must be an accessible and unambiguous base of BDE_OTHER_TYPE

◆ ManagedPtr() [7/15]

template<class TARGET_TYPE >
template<class ALIASED_TYPE >
bslma::ManagedPtr< TARGET_TYPE >::ManagedPtr ( ManagedPtr< ALIASED_TYPE > &  alias,
TARGET_TYPE *  ptr 
)
inline

Create a managed pointer that takes ownership of the object managed by the specified alias, but which uses the specified ptr to refer to its target object, unless 0 == ptr, in which case create an empty managed pointer. Reset alias to empty if ownership of its managed object is transferred. The behavior is undefined if alias is empty, but 0 != ptr. Note that destroying or re-assigning a managed pointer created with this constructor will destroy the object originally managed by alias (unless release is called first); the destructor for *ptr is not called directly.

◆ ManagedPtr() [8/15]

template<class TARGET_TYPE >
template<class ALIASED_TYPE >
bslma::ManagedPtr< TARGET_TYPE >::ManagedPtr ( bslmf::MovableRef< ManagedPtr< ALIASED_TYPE > >  alias,
TARGET_TYPE *  ptr 
)
inline

◆ ManagedPtr() [9/15]

template<class TARGET_TYPE >
template<class MANAGED_TYPE , class FACTORY_TYPE >
bslma::ManagedPtr< TARGET_TYPE >::ManagedPtr ( MANAGED_TYPE *  ptr,
FACTORY_TYPE *  factory 
)
inline

Create a managed pointer having a target object referenced by the specified ptr, owning the managed object *ptr, and having a deleter that will call factory->deleteObject(ptr) to destroy the managed object when invoked (e.g., when this managed pointer object is destroyed), unless 0 == ptr, in which case create an empty managed pointer. The deleter will invoke the destructor of MANAGED_TYPE rather than the destructor of TARGET_TYPE. This constructor will not compile unless MANAGED_TYPE * is convertible to TARGET_TYPE *. The behavior is undefined unless the managed object (if any) can be destroyed by the specified factory, or if 0 == factory && 0 != ptr, or if the lifetime of the managed object is already managed by another object. Note that bslma::Allocator, and any class publicly and unambiguously derived from bslma::Allocator, meets the requirements for FACTORY_TYPE.

◆ ManagedPtr() [10/15]

template<class TARGET_TYPE >
bslma::ManagedPtr< TARGET_TYPE >::ManagedPtr ( bsl::nullptr_t  ,
bsl::nullptr_t  = 0 
)
inlineexplicit

Create an empty managed pointer. Note that this constructor is necessary to match null-pointer literal arguments, in order to break ambiguities and provide valid type deduction with the other constructor templates in this class.

◆ ManagedPtr() [11/15]

template<class TARGET_TYPE >
template<class FACTORY_TYPE >
bslma::ManagedPtr< TARGET_TYPE >::ManagedPtr ( bsl::nullptr_t  ,
FACTORY_TYPE *  factory 
)
inline

Create an empty managed pointer. Note that the specified factory is ignored, as an empty managed pointer does not call its deleter.

◆ ManagedPtr() [12/15]

template<class TARGET_TYPE >
bslma::ManagedPtr< TARGET_TYPE >::ManagedPtr ( TARGET_TYPE *  ptr,
void *  cookie,
DeleterFunc  deleter 
)
inline

Create a managed pointer having a target object referenced by the specified ptr, owning the managed object *ptr, and having a deleter that will invoke the specified deleter with the address of the currently managed object, and with the specified cookie (that the deleter can use for its own purposes), unless 0 == ptr, in which case create an empty managed pointer. The behavior is undefined if ptr is already managed by another object, or if 0 == deleter && 0 != ptr. Note that this constructor is required only because the deprecated overloads cause an ambiguity in its absence; it should be removed when the deprecated overloads are removed.

◆ ManagedPtr() [13/15]

template<class TARGET_TYPE >
template<class MANAGED_TYPE >
bslma::ManagedPtr< TARGET_TYPE >::ManagedPtr ( MANAGED_TYPE *  ptr,
void *  cookie,
DeleterFunc  deleter 
)
inline

Create a managed pointer having a target object referenced by the specified ptr, owning the managed object *ptr, and having a deleter that will invoke the specified deleter with the address of the currently managed object, and with the specified cookie (that the deleter can use for its own purposes), unless 0 == ptr, in which case create an empty managed pointer. This constructor will not compile unless MANAGED_TYPE * is convertible to TARGET_TYPE *. The deleter will invoke the destructor of MANAGED_TYPE rather than the destructor of TARGET_TYPE. The behavior is undefined if ptr is already managed by another object, or if 0 == deleter && 0 != ptr.

◆ ManagedPtr() [14/15]

template<class TARGET_TYPE >
template<class MANAGED_TYPE , class MANAGED_BASE >
bslma::ManagedPtr< TARGET_TYPE >::ManagedPtr ( MANAGED_TYPE *  ptr,
void *  cookie,
void(*)(MANAGED_BASE *, void *)  deleter 
)
inline

[DEPRECATED]: Instead, use:

template <class MANAGED_TYPE>
ManagedPtr(MANAGED_TYPE *ptr, void *cookie, DeleterFunc deleter);
TARGET_TYPE * ptr() const
Definition bslma_managedptr.h:2553
const ManagedPtrDeleter & deleter() const
Definition bslma_managedptr.h:2537
friend class ManagedPtr
Definition bslma_managedptr.h:1288
ManagedPtrDeleter::Deleter DeleterFunc
Definition bslma_managedptr.h:1189

Create a managed pointer having a target object referenced by the specified ptr, owning the managed object *ptr, and having a deleter that will invoke the specified deleter with the address of the currently managed object, and with the specified cookie (that the deleter can use for its own purposes), unless 0 == ptr, in which case create an empty managed pointer. This constructor will not compile unless MANAGED_TYPE * is convertible to TARGET_TYPE *, and MANAGED_TYPE * is convertible to MANAGED_BASE *. The deleter will invoke the destructor of MANAGED_TYPE rather than the destructor of TARGET_TYPE. The behavior is undefined if ptr is already managed by another object, or if 0 == deleter && 0 != ptr. Note that this constructor is needed only to avoid ambiguous type deductions when passing a null pointer literal as the cookie when the user passes a deleter taking a type other than void * for its object type. Also note that this function is deprecated as it relies on undefined compiler behavior for its implementation (that luckily performs as required on every platform supported by BDE).

◆ ManagedPtr() [15/15]

template<class TARGET_TYPE >
template<class MANAGED_TYPE , class MANAGED_BASE , class COOKIE_TYPE , class COOKIE_BASE >
bslma::ManagedPtr< TARGET_TYPE >::ManagedPtr ( MANAGED_TYPE *  ptr,
COOKIE_TYPE *  cookie,
void(*)(MANAGED_BASE *, COOKIE_BASE *)  deleter 
)
inline

[DEPRECATED]: Instead, use:

template <class MANAGED_TYPE>
ManagedPtr(MANAGED_TYPE *ptr, void *cookie, DeleterFunc deleter);

Create a managed pointer having a target object referenced by the specified ptr, owning the managed object *ptr, and having a deleter that will invoke the specified deleter with the address of the currently managed object, and with the specified cookie (that the deleter can use for its own purposes), unless 0 == ptr, in which case create an empty managed pointer. This constructor will not compile unless MANAGED_TYPE * is convertible to TARGET_TYPE *, and MANAGED_TYPE * is convertible to MANAGED_BASE *. The deleter will invoke the destructor of MANAGED_TYPE rather than the destructor of TARGET_TYPE. The behavior is undefined if ptr is already managed by another object, or if 0 == deleter && 0 != ptr. Note that this function is deprecated as it relies on undefined compiler behavior for its implementation (that luckily performs as required on every platform supported by BDE).

◆ ~ManagedPtr()

template<class TARGET_TYPE >
bslma::ManagedPtr< TARGET_TYPE >::~ManagedPtr ( )
inline

Destroy this managed pointer object. Destroy the object managed by this managed pointer by invoking the user-supplied deleter, unless this managed pointer is empty, in which case the deleter will not be called.

Member Function Documentation

◆ clear()

template<class TARGET_TYPE >
void bslma::ManagedPtr< TARGET_TYPE >::clear ( )
inline

[DEPRECATED] Use reset instead.

Destroy the current managed object (if any) and reset this managed pointer to empty.

◆ deleter()

template<class TARGET_TYPE >
const ManagedPtrDeleter & bslma::ManagedPtr< TARGET_TYPE >::deleter ( ) const
inline

Return a reference to the non-modifiable deleter information associated with this managed pointer. The behavior is undefined if this managed pointer is empty.

◆ get()

template<class TARGET_TYPE >
TARGET_TYPE * bslma::ManagedPtr< TARGET_TYPE >::get ( ) const
inline

Return the address of the target object, or 0 if this managed pointer is empty.

◆ load() [1/7]

template<class TARGET_TYPE >
void bslma::ManagedPtr< TARGET_TYPE >::load ( bsl::nullptr_t  = 0,
void *  cookie = 0,
DeleterFunc  deleter = 0 
)
inline

Destroy the current managed object (if any) and reset this managed pointer to empty. Note that the optionally specified cookie and deleter will be ignored, as empty managed pointers do not invoke a deleter.

◆ load() [2/7]

template<class TARGET_TYPE >
template<class MANAGED_TYPE >
void bslma::ManagedPtr< TARGET_TYPE >::load ( MANAGED_TYPE *  ptr)
inline

Destroy the currently managed object, if any. Then, set the target object of this managed pointer to be that referenced by the specified ptr, take ownership of *ptr as the currently managed object, and set a deleter that uses the currently installed default allocator to destroy the managed object when invoked (e.g., when this managed pointer object is destroyed), unless 0 == ptr, in which case reset this managed pointer to empty. The deleter will invoke the destructor of MANAGED_TYPE rather than the destructor of TARGET_TYPE. This function will not compile unless MANAGED_TYPE * is convertible to TARGET_TYPE *. The behavior is undefined unless the managed object (if any) can be destroyed by the currently installed default allocator, or if the lifetime of the managed object is already managed by another object.

◆ load() [3/7]

template<class TARGET_TYPE >
template<class MANAGED_TYPE , class COOKIE_TYPE >
void bslma::ManagedPtr< TARGET_TYPE >::load ( MANAGED_TYPE *  ptr,
COOKIE_TYPE *  cookie,
DeleterFunc  deleter 
)
inline

◆ load() [4/7]

template<class TARGET_TYPE >
template<class MANAGED_TYPE , class MANAGED_BASE , class COOKIE_TYPE , class COOKIE_BASE >
void bslma::ManagedPtr< TARGET_TYPE >::load ( MANAGED_TYPE *  ptr,
COOKIE_TYPE *  cookie,
void(*)(MANAGED_BASE *, COOKIE_BASE *)  deleter 
)
inline

[DEPRECATED]: Instead, use:

template <class MANAGED_TYPE>
void load(MANAGED_TYPE *ptr, void *cookie, DeleterFunc deleter);

Destroy the currently managed object, if any. Then, set the target object of this managed pointer to be that referenced by the specified ptr, take ownership of *ptr as the currently managed object, and set a deleter that will invoke the specified deleter with the address of the currently managed object, and with the specified cookie (that the deleter can use for its own purposes), unless 0 == ptr, in which case reset this managed pointer to empty. The behavior is undefined if ptr is already managed by another object, or if 0 == deleter && 0 != ptr. Note that this function is deprecated as it relies on undefined compiler behavior for its implementation, but luckily perform as required for all currently supported platforms; on platforms where the non-deprecated overload is not available (e.g., GCC 3.4) code should be written as if it were available, as an appropriate (deprecated) overload will be selected with the correct (non-deprecated) behavior.

◆ load() [5/7]

template<class TARGET_TYPE >
template<class MANAGED_TYPE , class FACTORY_TYPE >
void bslma::ManagedPtr< TARGET_TYPE >::load ( MANAGED_TYPE *  ptr,
FACTORY_TYPE *  factory 
)
inline

Destroy the currently managed object, if any. Then, set the target object of this managed pointer to be that referenced by the specified ptr, take ownership of *ptr as the currently managed object, and set a deleter that calls factory->deleteObject(ptr) to destroy the managed object when invoked (e.g., when this managed pointer object is destroyed), unless 0 == ptr, in which case reset this managed pointer to empty. The deleter will invoke the destructor of MANAGED_TYPE rather than the destructor of TARGET_TYPE. This function will not compile unless MANAGED_TYPE * is convertible to TARGET_TYPE *. The behavior is undefined unless the managed object (if any) can be destroyed by the specified factory, or if 0 == factory && 0 != ptr, or if the the lifetime of the managed object is already managed by another object. Note that bslma::Allocator, and any class publicly and unambiguously derived from bslma::Allocator, meets the requirements for FACTORY_TYPE.

◆ load() [6/7]

template<class TARGET_TYPE >
template<class MANAGED_TYPE >
void bslma::ManagedPtr< TARGET_TYPE >::load ( MANAGED_TYPE *  ptr,
void *  cookie,
DeleterFunc  deleter 
)
inline

Destroy the currently managed object, if any. Then, set the target object of this managed pointer to be that referenced by the specified ptr, take ownership of *ptr as the currently managed object, and set a deleter that will invoke the specified deleter with the address of the currently managed object, and with the specified cookie (that the deleter can use for its own purposes), unless 0 == ptr, in which case reset this managed pointer to empty. The behavior is undefined if ptr is already managed by another object, or if 0 == deleter && 0 != ptr. Note that GCC 3.4 and earlier versions have a bug in template type deduction/overload resolution that causes ambiguities if this signature is available. This function will be restored on that platform once the deprecated signatures are finally removed.

◆ load() [7/7]

template<class TARGET_TYPE >
template<class MANAGED_TYPE , class MANAGED_BASE >
void bslma::ManagedPtr< TARGET_TYPE >::load ( MANAGED_TYPE *  ptr,
void *  cookie,
void(*)(MANAGED_BASE *, void *)  deleter 
)
inline

◆ loadAlias()

template<class TARGET_TYPE >
template<class ALIASED_TYPE >
void bslma::ManagedPtr< TARGET_TYPE >::loadAlias ( ManagedPtr< ALIASED_TYPE > &  alias,
TARGET_TYPE *  ptr 
)

If the specified alias manages the same object as this managed pointer, set the target object of this managed pointer to be that referenced by the specified ptr; otherwise, destroy the currently managed object (if any), and if alias is empty, reset this managed pointer to empty; otherwise, transfer ownership (and the deleter) of the object managed by alias, and set the target object of this managed pointer to be that referenced by ptr. The behavior is undefined if 0 == ptr and alias is not empty, or if 0 != ptr and alias is empty, or if ptr is already managed by a managed pointer other than alias. Note that this establishes a managed pointer where ptr aliases alias. The managed object for alias will ultimately be destroyed, and the destructor for ptr is not called directly.

◆ operator BoolType()

template<class TARGET_TYPE >
bslma::ManagedPtr< TARGET_TYPE >::operator BoolType ( ) const
inline

Return a value of "unspecified bool" type that evaluates to false if this managed pointer is empty, and true otherwise. Note that this conversion operator allows a managed pointer to be used within a conditional context, such as within an if or while statement, but does not allow managed pointers to be compared (e.g., via < or >). Also note that a superior solution is available in C++11 using the explicit operator bool() syntax, that removes the need for a special boolean-like type and private equality-comparison operators.

◆ operator ManagedPtr_Ref< REFERENCED_TYPE >()

template<class TARGET_TYPE >
template<class REFERENCED_TYPE >
bslma::ManagedPtr< TARGET_TYPE >::operator ManagedPtr_Ref< REFERENCED_TYPE > ( )
inline

Return a managed pointer reference, referring to this object. Note that this conversion operator is used implicitly to allow the construction of managed pointers from rvalues because temporaries cannot be passed by references offering modifiable access.

◆ operator*()

template<class TARGET_TYPE >
bslmf::AddReference< TARGET_TYPE >::Type bslma::ManagedPtr< TARGET_TYPE >::operator* ( ) const
inline

Return a reference to the target object. The behavior is undefined if this managed pointer is empty, or if TARGET_TYPE is void or const void.

◆ operator->()

template<class TARGET_TYPE >
TARGET_TYPE * bslma::ManagedPtr< TARGET_TYPE >::operator-> ( ) const
inline

Return the address of the target object, or 0 if this managed pointer is empty.

◆ operator=() [1/5]

template<class TARGET_TYPE >
ManagedPtr< TARGET_TYPE > & bslma::ManagedPtr< TARGET_TYPE >::operator= ( bsl::nullptr_t  )
inline

Destroy the current managed object (if any) and reset this managed pointer to empty.

◆ operator=() [2/5]

template<class TARGET_TYPE >
ManagedPtr< TARGET_TYPE > & bslma::ManagedPtr< TARGET_TYPE >::operator= ( bslmf::MovableRef< ManagedPtr< TARGET_TYPE > >  rhs)
inline

If this object and the specified rhs manage the same object, return a reference to this managed pointer; otherwise, destroy the managed object owned by this managed pointer, transfer ownership of the managed object owned by rhs to this managed pointer, set this managed pointer to point to the target object referenced by rhs, reset rhs to empty, and return a reference to this managed pointer.

◆ operator=() [3/5]

template<class TARGET_TYPE >
template<class BDE_OTHER_TYPE >
bsl::enable_if< bsl::is_convertible< BDE_OTHER_TYPE *, TARGET_TYPE * >::value, ManagedPtr< TARGET_TYPE > >::type & bslma::ManagedPtr< TARGET_TYPE >::operator= ( bslmf::MovableRef< ManagedPtr< BDE_OTHER_TYPE > >  rhs)
inline

If this object and the specified rhs manage the same object, return a reference to this managed pointer; otherwise, destroy the managed object owned by this managed pointer, transfer ownership of the managed object owned by rhs to this managed pointer, set this managed pointer to point to the target object referenced by rhs, reset rhs to empty, and return a reference to this managed pointer. TARGET_TYPE must be an accessible and unambiguous base of BDE_OTHER_TYPE

◆ operator=() [4/5]

template<class TARGET_TYPE >
ManagedPtr< TARGET_TYPE > & bslma::ManagedPtr< TARGET_TYPE >::operator= ( ManagedPtr< TARGET_TYPE > &  rhs)
inline

◆ operator=() [5/5]

template<class TARGET_TYPE >
ManagedPtr< TARGET_TYPE > & bslma::ManagedPtr< TARGET_TYPE >::operator= ( ManagedPtr_Ref< TARGET_TYPE >  ref)
inline

If this object and the managed pointer reference by the specified ref manage the same object, return a reference to this managed pointer; otherwise, destroy the managed object owned by this managed pointer, transfer ownership of the managed object owned by the managed pointer referenced by ref, and set this managed pointer to point to the target object currently referenced the managed pointer referenced by ref; then reset the managed pointer referenced by ref to empty, and return a reference to this managed pointer. This operator is (implicitly) used to assign from a managed pointer rvalue, or from a managed pointer to a "compatible" type, where "compatible" means a built-in conversion from MANAGED_TYPE * to TARGET_TYPE * is defined, e.g., derived * to base *, T * to const T *, or T * to void *.

◆ ptr()

template<class TARGET_TYPE >
TARGET_TYPE * bslma::ManagedPtr< TARGET_TYPE >::ptr ( ) const
inline

[DEPRECATED]: Use get instead.

Return the address of the target object, or 0 if this managed pointer is empty.

◆ release() [1/2]

template<class TARGET_TYPE >
ManagedPtr_PairProxy< TARGET_TYPE, ManagedPtrDeleter > bslma::ManagedPtr< TARGET_TYPE >::release ( )

Return a raw pointer to the current target object (if any) and the deleter for the currently managed object, and reset this managed pointer to empty. It is undefined behavior to run the returned deleter unless the returned pointer to target object is not null.

◆ release() [2/2]

template<class TARGET_TYPE >
TARGET_TYPE * bslma::ManagedPtr< TARGET_TYPE >::release ( ManagedPtrDeleter deleter)

Load the specified deleter for the currently managed object and reset this managed pointer to empty. Return a raw pointer to the target object (if any) managed by this pointer. It is undefined behavior to run the returned deleter unless the returned pointer to target object is not null.

◆ reset()

template<class TARGET_TYPE >
void bslma::ManagedPtr< TARGET_TYPE >::reset ( )
inline

Destroy the current managed object (if any) and reset this managed pointer to empty.

◆ swap()

template<class TARGET_TYPE >
void bslma::ManagedPtr< TARGET_TYPE >::swap ( ManagedPtr< TARGET_TYPE > &  other)
inline

Exchange the value and ownership of this managed pointer with the specified other managed pointer.

Friends And Related Symbol Documentation

◆ ManagedPtr

template<class TARGET_TYPE >
template<class ALIASED_TYPE >
friend class ManagedPtr
friend

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