rippled
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
ripple::SharedIntrusive< T > Class Template Reference

A shared intrusive pointer class that supports weak pointers. More...

#include <IntrusivePointer.h>

Public Member Functions

 SharedIntrusive ()=default
 
template<CAdoptTag TAdoptTag>
 SharedIntrusive (T *p, TAdoptTag) noexcept
 
 SharedIntrusive (SharedIntrusive const &rhs)
 
template<class TT >
requires std::convertible_to<TT*, T*>
 SharedIntrusive (SharedIntrusive< TT > const &rhs)
 
 SharedIntrusive (SharedIntrusive &&rhs)
 
template<class TT >
requires std::convertible_to<TT*, T*>
 SharedIntrusive (SharedIntrusive< TT > &&rhs)
 
SharedIntrusiveoperator= (SharedIntrusive const &rhs)
 
bool operator!= (std::nullptr_t) const
 
bool operator== (std::nullptr_t) const
 
template<class TT >
requires std::convertible_to<TT*, T*>
SharedIntrusiveoperator= (SharedIntrusive< TT > const &rhs)
 
SharedIntrusiveoperator= (SharedIntrusive &&rhs)
 
template<class TT >
requires std::convertible_to<TT*, T*>
SharedIntrusiveoperator= (SharedIntrusive< TT > &&rhs)
 
template<CAdoptTag TAdoptTag = SharedIntrusiveAdoptIncrementStrongTag>
void adopt (T *p)
 Adopt the raw pointer.
 
 ~SharedIntrusive ()
 
template<class TT >
 SharedIntrusive (StaticCastTagSharedIntrusive, SharedIntrusive< TT > const &rhs)
 Create a new SharedIntrusive by statically casting the pointer controlled by the rhs param.
 
template<class TT >
 SharedIntrusive (StaticCastTagSharedIntrusive, SharedIntrusive< TT > &&rhs)
 Create a new SharedIntrusive by statically casting the pointer controlled by the rhs param.
 
template<class TT >
 SharedIntrusive (DynamicCastTagSharedIntrusive, SharedIntrusive< TT > const &rhs)
 Create a new SharedIntrusive by dynamically casting the pointer controlled by the rhs param.
 
template<class TT >
 SharedIntrusive (DynamicCastTagSharedIntrusive, SharedIntrusive< TT > &&rhs)
 Create a new SharedIntrusive by dynamically casting the pointer controlled by the rhs param.
 
T & operator* () const noexcept
 
T * operator-> () const noexcept
 
 operator bool () const noexcept
 
void reset ()
 Set the pointer to null, decrement the strong count, and run the appropriate release action.
 
T * get () const
 Get the raw pointer.
 
std::size_t use_count () const
 Return the strong count.
 

Private Member Functions

T * unsafeGetRawPtr () const
 Return the raw pointer held by this object.
 
void unsafeReleaseAndStore (T *next)
 Exchange the current raw pointer held by this object with the given pointer.
 
void unsafeSetRawPtr (T *p)
 Set the raw pointer directly.
 
T * unsafeExchange (T *p)
 Exchange the raw pointer directly.
 

Private Attributes

T * ptr_ {nullptr}
 pointer to the type with an intrusive count
 

Friends

template<class TT >
class SharedIntrusive
 
template<class TT >
class SharedWeakUnion
 
template<class TT >
class WeakIntrusive
 
template<class TT , class... Args>
SharedIntrusive< TT > make_SharedIntrusive (Args &&... args)
 Create a shared intrusive pointer.
 

Detailed Description

template<class T>
class ripple::SharedIntrusive< T >

A shared intrusive pointer class that supports weak pointers.

This is meant to be used for SHAMapInnerNodes, but may be useful for other cases. Since the reference counts are stored on the pointee, the pointee is not destroyed until both the strong and weak pointer counts go to zero. When the strong pointer count goes to zero, the "partialDestructor" is called. This can be used to destroy as much of the object as possible while still retaining the reference counts. For example, for SHAMapInnerNodes the children may be reset in that function. Note that std::shared_poiner WILL run the destructor when the strong count reaches zero, but may not free the memory used by the object until the weak count reaches zero. In rippled, we typically allocate shared pointers with the make_shared function. When that is used, the memory is not reclaimed until the weak count reaches zero.

Definition at line 87 of file IntrusivePointer.h.

Constructor & Destructor Documentation

◆ SharedIntrusive() [1/10]

template<class T >
ripple::SharedIntrusive< T >::SharedIntrusive ( )
default

◆ SharedIntrusive() [2/10]

template<class T >
template<CAdoptTag TAdoptTag>
ripple::SharedIntrusive< T >::SharedIntrusive ( T *  p,
TAdoptTag   
)
noexcept

◆ SharedIntrusive() [3/10]

template<class T >
ripple::SharedIntrusive< T >::SharedIntrusive ( SharedIntrusive< T > const &  rhs)

◆ SharedIntrusive() [4/10]

template<class T >
template<class TT >
requires std::convertible_to<TT*, T*>
ripple::SharedIntrusive< T >::SharedIntrusive ( SharedIntrusive< TT > const &  rhs)

◆ SharedIntrusive() [5/10]

template<class T >
ripple::SharedIntrusive< T >::SharedIntrusive ( SharedIntrusive< T > &&  rhs)

◆ SharedIntrusive() [6/10]

template<class T >
template<class TT >
requires std::convertible_to<TT*, T*>
ripple::SharedIntrusive< T >::SharedIntrusive ( SharedIntrusive< TT > &&  rhs)

◆ ~SharedIntrusive()

template<class T >
ripple::SharedIntrusive< T >::~SharedIntrusive ( )

◆ SharedIntrusive() [7/10]

template<class T >
template<class TT >
ripple::SharedIntrusive< T >::SharedIntrusive ( StaticCastTagSharedIntrusive< T >  ,
SharedIntrusive< TT > const &  rhs 
)

Create a new SharedIntrusive by statically casting the pointer controlled by the rhs param.

◆ SharedIntrusive() [8/10]

template<class T >
template<class TT >
ripple::SharedIntrusive< T >::SharedIntrusive ( StaticCastTagSharedIntrusive< T >  ,
SharedIntrusive< TT > &&  rhs 
)

Create a new SharedIntrusive by statically casting the pointer controlled by the rhs param.

◆ SharedIntrusive() [9/10]

template<class T >
template<class TT >
ripple::SharedIntrusive< T >::SharedIntrusive ( DynamicCastTagSharedIntrusive< T >  ,
SharedIntrusive< TT > const &  rhs 
)

Create a new SharedIntrusive by dynamically casting the pointer controlled by the rhs param.

◆ SharedIntrusive() [10/10]

template<class T >
template<class TT >
ripple::SharedIntrusive< T >::SharedIntrusive ( DynamicCastTagSharedIntrusive< T >  ,
SharedIntrusive< TT > &&  rhs 
)

Create a new SharedIntrusive by dynamically casting the pointer controlled by the rhs param.

Member Function Documentation

◆ operator=() [1/4]

template<class T >
SharedIntrusive & ripple::SharedIntrusive< T >::operator= ( SharedIntrusive< T > const &  rhs)

◆ operator!=()

template<class T >
bool ripple::SharedIntrusive< T >::operator!= ( std::nullptr_t  ) const

◆ operator==()

template<class T >
bool ripple::SharedIntrusive< T >::operator== ( std::nullptr_t  ) const

◆ operator=() [2/4]

template<class T >
template<class TT >
requires std::convertible_to<TT*, T*>
SharedIntrusive & ripple::SharedIntrusive< T >::operator= ( SharedIntrusive< TT > const &  rhs)

◆ operator=() [3/4]

template<class T >
SharedIntrusive & ripple::SharedIntrusive< T >::operator= ( SharedIntrusive< T > &&  rhs)

◆ operator=() [4/4]

template<class T >
template<class TT >
requires std::convertible_to<TT*, T*>
SharedIntrusive & ripple::SharedIntrusive< T >::operator= ( SharedIntrusive< TT > &&  rhs)

◆ adopt()

template<class T >
template<CAdoptTag TAdoptTag = SharedIntrusiveAdoptIncrementStrongTag>
void ripple::SharedIntrusive< T >::adopt ( T *  p)

Adopt the raw pointer.

The strong reference may or may not be incremented, depending on the TAdoptTag

◆ operator*()

template<class T >
T & ripple::SharedIntrusive< T >::operator* ( ) const
noexcept

◆ operator->()

template<class T >
T * ripple::SharedIntrusive< T >::operator-> ( ) const
noexcept

◆ operator bool()

template<class T >
ripple::SharedIntrusive< T >::operator bool ( ) const
explicitnoexcept

◆ reset()

template<class T >
void ripple::SharedIntrusive< T >::reset ( )

Set the pointer to null, decrement the strong count, and run the appropriate release action.

◆ get()

template<class T >
T * ripple::SharedIntrusive< T >::get ( ) const

Get the raw pointer.

◆ use_count()

template<class T >
std::size_t ripple::SharedIntrusive< T >::use_count ( ) const

Return the strong count.

◆ unsafeGetRawPtr()

template<class T >
T * ripple::SharedIntrusive< T >::unsafeGetRawPtr ( ) const
private

Return the raw pointer held by this object.

◆ unsafeReleaseAndStore()

template<class T >
void ripple::SharedIntrusive< T >::unsafeReleaseAndStore ( T *  next)
private

Exchange the current raw pointer held by this object with the given pointer.

Decrement the strong count of the raw pointer previously held by this object and run the appropriate release action.

◆ unsafeSetRawPtr()

template<class T >
void ripple::SharedIntrusive< T >::unsafeSetRawPtr ( T *  p)
private

Set the raw pointer directly.

This is wrapped in a function so the class can support both atomic and non-atomic pointers in a future patch.

◆ unsafeExchange()

template<class T >
T * ripple::SharedIntrusive< T >::unsafeExchange ( T *  p)
private

Exchange the raw pointer directly.

This sets the raw pointer to the given value and returns the previous value. This is wrapped in a function so the class can support both atomic and non-atomic pointers in a future patch.

Friends And Related Symbol Documentation

◆ SharedIntrusive

template<class T >
template<class TT >
friend class SharedIntrusive
friend

Definition at line 196 of file IntrusivePointer.h.

◆ SharedWeakUnion

template<class T >
template<class TT >
friend class SharedWeakUnion
friend

Definition at line 199 of file IntrusivePointer.h.

◆ WeakIntrusive

template<class T >
template<class TT >
friend class WeakIntrusive
friend

Definition at line 202 of file IntrusivePointer.h.

◆ make_SharedIntrusive

template<class T >
template<class TT , class... Args>
SharedIntrusive< TT > make_SharedIntrusive ( Args &&...  args)
friend

Create a shared intrusive pointer.

Note: unlike std::shared_ptr, where there is an advantage of allocating the pointer and control block together, there is no benefit for intrusive pointers.

Definition at line 467 of file IntrusivePointer.h.

Member Data Documentation

◆ ptr_

template<class T >
T* ripple::SharedIntrusive< T >::ptr_ {nullptr}
private

pointer to the type with an intrusive count

Definition at line 231 of file IntrusivePointer.h.