BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bslma::SharedPtrRep Class Referenceabstract

#include <bslma_sharedptrrep.h>

Inheritance diagram for bslma::SharedPtrRep:
bdlcc::SharedObjectPool_Rep< TYPE, RESETTER > bslma::SharedPtrInplaceRep< TYPE > bslma::SharedPtrOutofplaceRep< TYPE, DELETER >

Public Member Functions

 SharedPtrRep ()
 
virtual void disposeObject ()=0
 
virtual void disposeRep ()=0
 
virtual void * getDeleter (const std::type_info &type)=0
 
virtual void * originalPtr () const =0
 
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 void managedPtrDeleter (void *, void *rep)
 
static void managedPtrEmptyDeleter (void *, void *rep)
 

Protected Member Functions

virtual ~SharedPtrRep ()
 

Detailed Description

This class provides a partially implemented shared pointer representation ("letter") protocol. The class provides two counters for storing the number of shared and weak references, and functions to increment and decrement these counters. In addition, this class provides protocol methods that allow concrete implementations to specify what action should be taken when these counts reach zero. The function disposeRep is responsible for destroying this object, it is called when the reference count to this object reaches zero. Thus, the destructor of this object is declared as protected and should never be invoked.

See bslma_sharedptrrep

Constructor & Destructor Documentation

◆ ~SharedPtrRep()

bslma::SharedPtrRep::~SharedPtrRep ( )
inlineprotectedvirtual

Destroy this representation object. Note that this destructor is not intended to be invoked polymorphically, and is marked virtual only to silence frequent warnings on popular compilers.

◆ SharedPtrRep()

bslma::SharedPtrRep::SharedPtrRep ( )
inline

Create a SharedPtrRep object having one shared reference and no weak references.

Member Function Documentation

◆ acquireRef()

void bslma::SharedPtrRep::acquireRef ( )
inline

Atomically acquire a shared reference to the shared object referred to by this representation. The behavior is undefined unless 0 < numReferences().

◆ acquireWeakRef()

void bslma::SharedPtrRep::acquireWeakRef ( )

Atomically acquire a weak reference to the shared object referred to by this representation. The behavior is undefined unless 0 < numWeakReferences() || 0 < numReferences().

◆ disposeObject()

virtual void bslma::SharedPtrRep::disposeObject ( )
pure virtual

Dispose of the shared object 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. Note that this virtual disposeObject method effectively serves as the shared object's destructor. Also note that derived classes must override this method to perform the appropriate action such as deleting the shared object.

Implemented in bdlcc::SharedObjectPool_Rep< TYPE, RESETTER >, bslma::SharedPtrInplaceRep< TYPE >, and bslma::SharedPtrOutofplaceRep< TYPE, DELETER >.

◆ disposeRep()

virtual void bslma::SharedPtrRep::disposeRep ( )
pure virtual

Dispose of this representation object. 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 virtual disposeRep method effectively serves as the representation object's destructor. Also note that derived classes must override this method to perform appropriate action such as deleting this representation, or returning it to an object pool.

Implemented in bdlcc::SharedObjectPool_Rep< TYPE, RESETTER >, bslma::SharedPtrInplaceRep< TYPE >, and bslma::SharedPtrOutofplaceRep< TYPE, DELETER >.

◆ getDeleter()

virtual void * bslma::SharedPtrRep::getDeleter ( const std::type_info &  type)
pure 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. Note that while this methods appears to be a simple accessor, it is declared as non- const qualified to support representations storing the deleter directly as a data member.

Implemented in bdlcc::SharedObjectPool_Rep< TYPE, RESETTER >, bslma::SharedPtrInplaceRep< TYPE >, and bslma::SharedPtrOutofplaceRep< TYPE, DELETER >.

◆ hasUniqueOwner()

bool bslma::SharedPtrRep::hasUniqueOwner ( ) const
inline

Return true if there is only one shared reference and no weak references to the object referred to by this representation, and false otherwise.

◆ incrementRefs()

void bslma::SharedPtrRep::incrementRefs ( int  incrementAmount = 1)
inline

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.

◆ managedPtrDeleter()

void bslma::SharedPtrRep::managedPtrDeleter ( void *  ,
void *  rep 
)
inlinestatic

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.

◆ managedPtrEmptyDeleter()

void bslma::SharedPtrRep::managedPtrEmptyDeleter ( void *  ,
void *  rep 
)
inlinestatic

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.

◆ numReferences()

int bslma::SharedPtrRep::numReferences ( ) const
inline

Return a "snapshot" of the current number of shared references to the shared object referred to by this representation object.

◆ numWeakReferences()

int bslma::SharedPtrRep::numWeakReferences ( ) const
inline

Return a "snapshot" of the current number of weak references to the shared object referred to by this representation object.

◆ originalPtr()

virtual void * bslma::SharedPtrRep::originalPtr ( ) const
pure virtual

Return the (untyped) address of the modifiable shared object referred to by this representation.

Implemented in bdlcc::SharedObjectPool_Rep< TYPE, RESETTER >, bslma::SharedPtrInplaceRep< TYPE >, and bslma::SharedPtrOutofplaceRep< TYPE, DELETER >.

◆ releaseRef()

void bslma::SharedPtrRep::releaseRef ( )

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().

◆ releaseWeakRef()

void bslma::SharedPtrRep::releaseWeakRef ( )
inline

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().

◆ resetCountsRaw()

void bslma::SharedPtrRep::resetCountsRaw ( int  numSharedReferences,
int  numWeakReferences 
)

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.

◆ tryAcquireRef()

bool bslma::SharedPtrRep::tryAcquireRef ( )

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().


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