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

A combination of a strong and a weak intrusive pointer stored in the space of a single pointer. More...

#include <IntrusivePointer.h>

Collaboration diagram for ripple::SharedWeakUnion< T >:
Collaboration graph
[legend]

Public Member Functions

 SharedWeakUnion ()=default
 
 SharedWeakUnion (SharedWeakUnion const &rhs)
 
template<class TT >
requires std::convertible_to<TT*, T*>
 SharedWeakUnion (SharedIntrusive< TT > const &rhs)
 
 SharedWeakUnion (SharedWeakUnion &&rhs)
 
template<class TT >
requires std::convertible_to<TT*, T*>
 SharedWeakUnion (SharedIntrusive< TT > &&rhs)
 
SharedWeakUnionoperator= (SharedWeakUnion const &rhs)
 
template<class TT >
requires std::convertible_to<TT*, T*>
SharedWeakUnionoperator= (SharedIntrusive< TT > const &rhs)
 
template<class TT >
requires std::convertible_to<TT*, T*>
SharedWeakUnionoperator= (SharedIntrusive< TT > &&rhs)
 
 ~SharedWeakUnion ()
 
SharedIntrusive< T > getStrong () const
 Return a strong pointer if this is already a strong pointer (i.e.
 
 operator bool () const noexcept
 Return true if this is a strong pointer and the strong pointer is seated.
 
void reset ()
 Set the pointer to null, decrement the appropriate ref count, and run the appropriate release action.
 
T * get () const
 If this is a strong pointer, return the raw pointer.
 
std::size_t use_count () const
 If this is a strong pointer, return the strong count.
 
bool expired () const
 Return true if there is a non-zero strong count.
 
SharedIntrusive< T > lock () const
 If this is a strong pointer, return the strong pointer.
 
bool isStrong () const
 Return true is this represents a strong pointer.
 
bool isWeak () const
 Return true is this represents a weak pointer.
 
bool convertToStrong ()
 If this is a weak pointer, attempt to convert it to a strong pointer.
 
bool convertToWeak ()
 If this is a strong pointer, attempt to convert it to a weak pointer.
 

Private Types

enum class  RefStrength { strong , weak }
 

Private Member Functions

T * unsafeGetRawPtr () const
 Return the raw pointer held by this object.
 
void unsafeSetRawPtr (T *p, RefStrength rs)
 Set the raw pointer and tag bit directly.
 
void unsafeSetRawPtr (std::nullptr_t)
 Set the raw pointer and tag bit to all zeros (strong null pointer).
 
void unsafeReleaseNoStore ()
 Decrement the appropriate ref count, and run the appropriate release action.
 

Private Attributes

std::uintptr_t tp_ {0}
 

Static Private Attributes

static constexpr std::uintptr_t tagMask = 1
 
static constexpr std::uintptr_t ptrMask = ~tagMask
 

Detailed Description

template<class T>
class ripple::SharedWeakUnion< T >

A combination of a strong and a weak intrusive pointer stored in the space of a single pointer.

This class is similar to a std::variant<SharedIntrusive,WeakIntrusive> with some optimizations. In particular, it uses a low-order bit to determine if the raw pointer represents a strong pointer or a weak pointer. It can also be quickly switched between its strong pointer and weak pointer representations. This class is useful for storing intrusive pointers in tagged caches.

Definition at line 321 of file IntrusivePointer.h.

Member Enumeration Documentation

◆ RefStrength

template<class T >
enum class ripple::SharedWeakUnion::RefStrength
strongprivate
Enumerator
strong 
weak 

Definition at line 440 of file IntrusivePointer.h.

Constructor & Destructor Documentation

◆ SharedWeakUnion() [1/5]

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

◆ SharedWeakUnion() [2/5]

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

◆ SharedWeakUnion() [3/5]

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

◆ SharedWeakUnion() [4/5]

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

◆ SharedWeakUnion() [5/5]

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

◆ ~SharedWeakUnion()

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

Member Function Documentation

◆ operator=() [1/3]

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

◆ operator=() [2/3]

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

◆ operator=() [3/3]

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

◆ getStrong()

template<class T >
SharedIntrusive< T > ripple::SharedWeakUnion< T >::getStrong ( ) const

Return a strong pointer if this is already a strong pointer (i.e.

don't lock the weak pointer. Use the lock method if that's what's needed)

◆ operator bool()

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

Return true if this is a strong pointer and the strong pointer is seated.

◆ reset()

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

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

◆ get()

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

If this is a strong pointer, return the raw pointer.

Otherwise return null.

◆ use_count()

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

If this is a strong pointer, return the strong count.

Otherwise return 0

◆ expired()

template<class T >
bool ripple::SharedWeakUnion< T >::expired ( ) const

Return true if there is a non-zero strong count.

◆ lock()

template<class T >
SharedIntrusive< T > ripple::SharedWeakUnion< T >::lock ( ) const

If this is a strong pointer, return the strong pointer.

Otherwise attempt to lock the weak pointer.

◆ isStrong()

template<class T >
bool ripple::SharedWeakUnion< T >::isStrong ( ) const

Return true is this represents a strong pointer.

◆ isWeak()

template<class T >
bool ripple::SharedWeakUnion< T >::isWeak ( ) const

Return true is this represents a weak pointer.

◆ convertToStrong()

template<class T >
bool ripple::SharedWeakUnion< T >::convertToStrong ( )

If this is a weak pointer, attempt to convert it to a strong pointer.

Returns
true if successfully converted to a strong pointer (or was already a strong pointer). Otherwise false.

◆ convertToWeak()

template<class T >
bool ripple::SharedWeakUnion< T >::convertToWeak ( )

If this is a strong pointer, attempt to convert it to a weak pointer.

Returns
false if the pointer is null. Otherwise return true.

◆ unsafeGetRawPtr()

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

Return the raw pointer held by this object.

◆ unsafeSetRawPtr() [1/2]

template<class T >
void ripple::SharedWeakUnion< T >::unsafeSetRawPtr ( T *  p,
RefStrength  rs 
)
private

Set the raw pointer and tag bit directly.

◆ unsafeSetRawPtr() [2/2]

template<class T >
void ripple::SharedWeakUnion< T >::unsafeSetRawPtr ( std::nullptr_t  )
private

Set the raw pointer and tag bit to all zeros (strong null pointer).

◆ unsafeReleaseNoStore()

template<class T >
void ripple::SharedWeakUnion< T >::unsafeReleaseNoStore ( )
private

Decrement the appropriate ref count, and run the appropriate release action.

Note: this does not set the raw pointer to null.

Member Data Documentation

◆ tp_

template<class T >
std::uintptr_t ripple::SharedWeakUnion< T >::tp_ {0}
private

Definition at line 430 of file IntrusivePointer.h.

◆ tagMask

template<class T >
constexpr std::uintptr_t ripple::SharedWeakUnion< T >::tagMask = 1
staticconstexprprivate

Definition at line 431 of file IntrusivePointer.h.

◆ ptrMask

template<class T >
constexpr std::uintptr_t ripple::SharedWeakUnion< T >::ptrMask = ~tagMask
staticconstexprprivate

Definition at line 432 of file IntrusivePointer.h.