Quick Links: |
#include <bslma_sharedptroutofplacerep.h>
Public Member Functions | |
virtual void | disposeObject () |
virtual void | disposeRep () |
virtual void * | getDeleter (const std::type_info &type) |
virtual void * | originalPtr () const |
TYPE * | ptr () const |
void | acquireRef () |
void | acquireWeakRef () |
void | incrementRefs (int incrementAmount=1) |
void | releaseRef () |
void | releaseWeakRef () |
void | resetCountsRaw (int numSharedReferences, int numWeakReferences) |
bool | tryAcquireRef () |
bool | hasUniqueOwner () const |
int | numReferences () const |
int | numWeakReferences () const |
Static Public Member Functions | |
static SharedPtrOutofplaceRep < TYPE, DELETER > * | makeOutofplaceRep (TYPE *ptr, const DELETER &deleter, Allocator *basicAllocator=0) |
static void | managedPtrDeleter (void *, void *rep) |
static void | managedPtrEmptyDeleter (void *, void *rep) |
This class provides a concrete implementation of the SharedPtrRep
protocol for out-of-place instances of the parameterized TYPE
. Upon destruction of this object, the parameterized DELETER
type is invoked on the pointer to the shared object.
See Component bslma_sharedptroutofplacerep
static SharedPtrOutofplaceRep<TYPE, DELETER>* bslma::SharedPtrOutofplaceRep< TYPE, DELETER >::makeOutofplaceRep | ( | TYPE * | ptr, | |
const DELETER & | deleter, | |||
Allocator * | basicAllocator = 0 | |||
) | [static] |
Return the address of a newly created SharedPtrOutofplaceRep
object that manages the lifetime of the specified ptr
, using the specified deleter
to destroy ptr
. Optionally, specify a basicAllocator
used to supply memory. If basicAllocator
is 0, the currently installed default allocator is used. Note that the parameterized DELETER
type will be used to deallocate the memory pointed to by ptr
.
virtual void bslma::SharedPtrOutofplaceRep< TYPE, DELETER >::disposeObject | ( | ) | [virtual] |
Destroy the object being referred to by this representation. This method is automatically invoked by releaseRef
when the number of shared references reaches zero and should not be explicitly invoked otherwise.
Implements bslma::SharedPtrRep.
virtual void bslma::SharedPtrOutofplaceRep< TYPE, DELETER >::disposeRep | ( | ) | [virtual] |
Destroy this representation object and deallocate the associated memory. This method is automatically invoked by releaseRef
and releaseWeakRef
when the number of weak references and the number of shared references both reach zero and should not be explicitly invoked otherwise. The behavior is undefined unless disposeObject
has already been called for this representation. Note that this disposeRep
method effectively serves as the representation object's destructor.
Implements bslma::SharedPtrRep.
virtual void* bslma::SharedPtrOutofplaceRep< TYPE, DELETER >::getDeleter | ( | const std::type_info & | type | ) | [virtual] |
Return a pointer to the deleter stored by the derived representation (if any) if the deleter has the same type as that described by the specified type
, and a null pointer otherwise.
Implements bslma::SharedPtrRep.
virtual void* bslma::SharedPtrOutofplaceRep< TYPE, DELETER >::originalPtr | ( | ) | const [virtual] |
Return the (untyped) address of the modifiable shared object to which this object refers.
Implements bslma::SharedPtrRep.
TYPE* bslma::SharedPtrOutofplaceRep< TYPE, DELETER >::ptr | ( | ) | const |
Return the address of the modifiable shared object to which this object refers.
static void bslma::SharedPtrRep::managedPtrDeleter | ( | void * | , | |
void * | rep | |||
) | [static, inherited] |
Release the shared reference to an object held by the SharedPtrRep
object that is pointed to be by specified rep
. The behavior is undefined unless rep
points to an object whose complete type publicly and unambiguously derives from SharedPtrRep
. Note that the first argument is ignored. Also note that this function serves as the ManagedPtr
deleter when converting a bsl::shared_ptr
to a bslma::ManagedPtr
.
static void bslma::SharedPtrRep::managedPtrEmptyDeleter | ( | void * | , | |
void * | rep | |||
) | [static, inherited] |
This function has no effect. The behavior is undefined unless rep
is null. Note that this function serves as the managed ptr deleter when converting an empty or null bsl::shared_ptr
to a bslma::ManagedPtr
.
void bslma::SharedPtrRep::acquireRef | ( | ) | [inherited] |
Atomically acquire a shared reference to the shared object referred to by this representation. The behavior is undefined unless 0 < numReferences()
.
void bslma::SharedPtrRep::acquireWeakRef | ( | ) | [inherited] |
Atomically acquire a weak reference to the shared object referred to by this representation. The behavior is undefined unless 0 < numWeakReferences() || 0 < numReferences()
.
void bslma::SharedPtrRep::incrementRefs | ( | int | incrementAmount = 1 |
) | [inherited] |
Atomically increment the number of shared references to the shared object referred to by this representation by the optionally specified incrementAmount
. The behavior is undefined unless 0 < incrementAmount
and 0 < numReferences()
.
DEPRECATED: Use acquireRef
instead.
void bslma::SharedPtrRep::releaseRef | ( | ) | [inherited] |
Atomically release a shared reference to the shared object referred to by this representation, disposing of the shared object if all the shared references to that object are released, and disposing of this representation if all (shared and weak) references to that object are released. The behavior is undefined unless 0 < numReferences()
.
void bslma::SharedPtrRep::releaseWeakRef | ( | ) | [inherited] |
Atomically release a weak reference to the shared object referred to by this representation, disposing of this representation if all (shared and weak) references to the shared object are released. The behavior is undefined unless 0 < numWeakReferences()
.
void bslma::SharedPtrRep::resetCountsRaw | ( | int | numSharedReferences, | |
int | numWeakReferences | |||
) | [inherited] |
Reset the number of shared references and the number of weak references stored by this representation to the specified numSharedReferences
and numWeakReferences
respectively. This function is not thread-safe and users must ensure that they serialize access to the SharedPtrRep
object when calling this function. Note that this function updates the counts, but does not dispose of the representation or the object irrespective of the values of numSharedReferences
and numWeakReferences
.
bool bslma::SharedPtrRep::tryAcquireRef | ( | ) | [inherited] |
Atomically acquire a shared reference to the shared object referred to by this representation, if the number of shared references is greater than 0, and do nothing otherwise. Return true
if the acquire succeeds, and false
otherwise. The behavior is undefined unless 0 < numWeakReferences() || 0 < numReferences()
.
bool bslma::SharedPtrRep::hasUniqueOwner | ( | ) | const [inherited] |
Return true
if there is only one shared reference and no weak references to the object referred to by this representation, and false
otherwise.
int bslma::SharedPtrRep::numReferences | ( | ) | const [inherited] |
Return a "snapshot" of the current number of shared references to the shared object referred to by this representation object.
int bslma::SharedPtrRep::numWeakReferences | ( | ) | const [inherited] |
Return a "snapshot" of the current number of weak references to the shared object referred to by this representation object.