|
| 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 () |
|
ManagedPtr & | operator= (ManagedPtr &rhs) BSLS_KEYWORD_NOEXCEPT |
|
ManagedPtr & | operator= (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 |
|
ManagedPtr & | operator= (ManagedPtr_Ref< TARGET_TYPE > ref) BSLS_KEYWORD_NOEXCEPT |
|
ManagedPtr & | operator= (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, ManagedPtrDeleter > | release () |
|
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 ManagedPtrDeleter & | deleter () const |
|
TARGET_TYPE * | get () const |
|
TARGET_TYPE * | ptr () const |
|
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
template<class TARGET_TYPE >
template<class MANAGED_TYPE >
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.
template<class TARGET_TYPE >
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 *
.
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
.
template<class TARGET_TYPE >
template<class MANAGED_TYPE >
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
.
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>
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).
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>
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).
template<class TARGET_TYPE >
template<class MANAGED_TYPE >
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.
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>
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.
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
.
template<class TARGET_TYPE >
template<class MANAGED_TYPE >
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.
template<class TARGET_TYPE >
template<class ALIASED_TYPE >
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.
template<class TARGET_TYPE >
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 *
.