[#BloombergLP-bslma-SharedPtrRep]
= xref:BloombergLP.adoc[BloombergLP]::xref:BloombergLP/bslma.adoc[bslma]::SharedPtrRep
:relfileprefix: ../../
:mrdocs:

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

== Synopsis

Declared in `&lt;bslma&lowbar;sharedptrrep&period;h&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
class SharedPtrRep;
----

== Member Functions

[cols="1,4"]
|===
| Name| Description
| xref:BloombergLP/bslma/SharedPtrRep/2constructor.adoc[`SharedPtrRep`]         [.small]#[constructor]#
| Create a `SharedPtrRep` object having one shared reference and no weak references&period;
| xref:BloombergLP/bslma/SharedPtrRep/acquireRef.adoc[`acquireRef`] 
| Atomically acquire a shared reference to the shared object referred to by this representation&period; The behavior is undefined unless `0 &lt; numReferences()`&period;
| xref:BloombergLP/bslma/SharedPtrRep/acquireWeakRef.adoc[`acquireWeakRef`] 
| Atomically acquire a weak reference to the shared object referred to by this representation&period; The behavior is undefined unless `0 &lt; numWeakReferences() &verbar;&verbar; 0 &lt; numReferences()`&period;
| xref:BloombergLP/bslma/SharedPtrRep/disposeObject.adoc[`disposeObject`]  [.small]#[virtual]#
| Dispose of the shared object referred to by this representation&period; This method is automatically invoked by `releaseRef` when the number of shared references reaches zero and should not be explicitly invoked otherwise&period; Note that this virtual `disposeObject` method effectively serves as the shared object&apos;s destructor&period; Also note that derived classes must override this method to perform the appropriate action such as deleting the shared object&period;
| xref:BloombergLP/bslma/SharedPtrRep/disposeRep.adoc[`disposeRep`]  [.small]#[virtual]#
| Dispose of this representation object&period; 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&period; The behavior is undefined unless `disposeObject` has already been called for this representation&period; Note that this virtual `disposeRep` method effectively serves as the representation object&apos;s destructor&period; 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&period;
| xref:BloombergLP/bslma/SharedPtrRep/getDeleter.adoc[`getDeleter`]  [.small]#[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&period; Note that while this methods appears to be a simple accessor, it is declared as non&hyphen; `const` qualified to support representations storing the deleter directly as a data member&period;
| xref:BloombergLP/bslma/SharedPtrRep/hasUniqueOwner.adoc[`hasUniqueOwner`] 
| Return `true` if there is only one shared reference and no weak references to the object referred to by this representation, and `false` otherwise&period;
| xref:BloombergLP/bslma/SharedPtrRep/incrementRefs.adoc[`incrementRefs`] 
| Atomically increment the number of shared references to the shared object referred to by this representation by the optionally specified `incrementAmount`&period; The behavior is undefined unless `0 &lt; incrementAmount` and `0 &lt; numReferences()`&period;
| xref:BloombergLP/bslma/SharedPtrRep/numReferences.adoc[`numReferences`] 
| Return a &quot;snapshot&quot; of the current number of shared references to the shared object referred to by this representation object&period;
| xref:BloombergLP/bslma/SharedPtrRep/numWeakReferences.adoc[`numWeakReferences`] 
| Return a &quot;snapshot&quot; of the current number of weak references to the shared object referred to by this representation object&period;
| xref:BloombergLP/bslma/SharedPtrRep/originalPtr.adoc[`originalPtr`]  [.small]#[virtual]#
| Return the (untyped) address of the modifiable shared object referred to by this representation&period;
| xref:BloombergLP/bslma/SharedPtrRep/releaseRef.adoc[`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&period; The behavior is undefined unless `0 &lt; numReferences()`&period;
| xref:BloombergLP/bslma/SharedPtrRep/releaseWeakRef.adoc[`releaseWeakRef`] 
| 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&period; The behavior is undefined unless `0 &lt; numWeakReferences()`&period;
| xref:BloombergLP/bslma/SharedPtrRep/resetCountsRaw.adoc[`resetCountsRaw`] 
| Reset the number of shared references and the number of weak references stored by this representation to the specified `numSharedReferences` and `numWeakReferences` respectively&period; This function is _not_ thread&hyphen;safe and users must ensure that they serialize access to the `SharedPtrRep` object when calling this function&period; 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`&period;
| xref:BloombergLP/bslma/SharedPtrRep/tryAcquireRef.adoc[`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&period; Return `true` if the acquire succeeds, and `false` otherwise&period; The behavior is undefined unless `0 &lt; numWeakReferences() &verbar;&verbar; 0 &lt; numReferences()`&period;
|===


== Static Member Functions

[cols="1,4"]
|===
| Name| Description
| xref:BloombergLP/bslma/SharedPtrRep/managedPtrDeleter.adoc[`managedPtrDeleter`] 
| Release the shared reference to an object held by the `SharedPtrRep` object that is pointed to be by specified `rep`&period; The behavior is undefined unless `rep` points to an object whose complete type publicly and unambiguously derives from `SharedPtrRep`&period; Note that the first argument is ignored&period; Also note that this function serves as the `ManagedPtr` deleter when converting a `bsl&colon;&colon;shared&lowbar;ptr` to a `bslma&colon;&colon;ManagedPtr`&period;
| xref:BloombergLP/bslma/SharedPtrRep/managedPtrEmptyDeleter.adoc[`managedPtrEmptyDeleter`] 
| This function has no effect&period; The behavior is undefined unless `rep` is null&period; Note that this function serves as the managed ptr deleter when converting an empty or null `bsl&colon;&colon;shared&lowbar;ptr` to a `bslma&colon;&colon;ManagedPtr`&period;
|===


== Protected Member Functions

[cols="1,4"]
|===
| Name| Description
| xref:BloombergLP/bslma/SharedPtrRep/2destructor.adoc[`&#126;SharedPtrRep`] [.small]#[destructor]# [.small]#[virtual]#
| Destroy this representation object&period; Note that this destructor is not intended to be invoked polymorphically, and is marked `virtual` only to silence frequent warnings on popular compilers&period;
|===


== Derived Classes

[cols="1,4"]
|===
| Name| Description
| xref:BloombergLP/bdlcc/SharedObjectPool_Rep.adoc[`SharedObjectPool&lowbar;Rep`] 
| Shared pointer representation object used by `SharedObjectPool`&period;
| xref:BloombergLP/bslstl/SharedPtrAllocateInplaceRep.adoc[`SharedPtrAllocateInplaceRep`] 
| This class provides a concrete implementation of the `SharedPtrRep` protocol for in&hyphen;place instances of the (template parameter) `TYPE`&period; Upon destruction of this object, the destructor of `TYPE` is invoked on the shared object&period;
| xref:BloombergLP/bslstl/SharedPtrAllocateOutofplaceRep.adoc[`SharedPtrAllocateOutofplaceRep`] 
| This class provides a concrete implementation of the `SharedPtrRep` protocol for out&hyphen;of&hyphen;place instances of the parameterized `TYPE`&period; Upon destruction of this object, the parameterized `DELETER` type is invoked on the pointer to the shared object&period;
| xref:BloombergLP/bslstl/SharedPtrArrayAllocateInplaceRep.adoc[`SharedPtrArrayAllocateInplaceRep`] 
| This class provides a concrete implementation of the `SharedPtrRep` protocol for in&hyphen;place instances of the (template parameter) `TYPE`, which must be an array&period; Upon destruction of this object, each element of the array is destructed&period;
| xref:BloombergLP/bslma/SharedPtrInplaceRep.adoc[`SharedPtrInplaceRep`] 
| This class provides a concrete implementation of the `SharedPtrRep` protocol for &quot;in&hyphen;place&quot; instances of the parameterized `TYPE`&period; Upon destruction of this object, the destructor of `TYPE` is invoked&period;
| xref:BloombergLP/bslma/SharedPtrOutofplaceRep.adoc[`SharedPtrOutofplaceRep`] 
| This class provides a concrete implementation of the `SharedPtrRep` protocol for out&hyphen;of&hyphen;place instances of the parameterized `TYPE`&period; Upon destruction of this object, the parameterized `DELETER` type is invoked on the pointer to the shared object&period;
|===


[.small]#Created with https://www.mrdocs.com[MrDocs]#
