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

A combination of a std::shared_ptr and a std::weak_pointer. More...

#include <SharedWeakCachePointer.h>

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

Public Member Functions

 SharedWeakCachePointer ()=default
 
 SharedWeakCachePointer (SharedWeakCachePointer const &rhs)
 
template<class TT >
requires std::convertible_to<TT*, T*>
 SharedWeakCachePointer (std::shared_ptr< TT > const &rhs)
 
 SharedWeakCachePointer (SharedWeakCachePointer &&rhs)
 
template<class TT >
requires std::convertible_to<TT*, T*>
 SharedWeakCachePointer (std::shared_ptr< TT > &&rhs)
 
SharedWeakCachePointeroperator= (SharedWeakCachePointer const &rhs)
 
template<class TT >
requires std::convertible_to<TT*, T*>
SharedWeakCachePointeroperator= (std::shared_ptr< TT > const &rhs)
 
template<class TT >
requires std::convertible_to<TT*, T*>
SharedWeakCachePointeroperator= (std::shared_ptr< TT > &&rhs)
 
 ~SharedWeakCachePointer ()
 
std::shared_ptr< T > const & 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.
 
std::shared_ptr< 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 Attributes

std::variant< std::shared_ptr< T >, std::weak_ptr< T > > combo_
 

Detailed Description

template<class T>
class ripple::SharedWeakCachePointer< T >

A combination of a std::shared_ptr and a std::weak_pointer.

This class is a wrapper to a std::variant<std::shared_ptr,std::weak_ptr> This class is useful for storing intrusive pointers in tagged caches using less memory than storing both pointers directly.

Definition at line 37 of file SharedWeakCachePointer.h.

Constructor & Destructor Documentation

◆ SharedWeakCachePointer() [1/5]

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

◆ SharedWeakCachePointer() [2/5]

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

◆ SharedWeakCachePointer() [3/5]

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

◆ SharedWeakCachePointer() [4/5]

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

◆ SharedWeakCachePointer() [5/5]

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

◆ ~SharedWeakCachePointer()

Member Function Documentation

◆ operator=() [1/3]

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

◆ operator=() [2/3]

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

◆ operator=() [3/3]

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

◆ getStrong()

template<class T >
std::shared_ptr< T > const & ripple::SharedWeakCachePointer< 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::SharedWeakCachePointer< 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::SharedWeakCachePointer< T >::reset ( )

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

◆ get()

template<class T >
T * ripple::SharedWeakCachePointer< 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::SharedWeakCachePointer< T >::use_count ( ) const

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

Otherwise return 0

◆ expired()

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

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

◆ lock()

template<class T >
std::shared_ptr< T > ripple::SharedWeakCachePointer< 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::SharedWeakCachePointer< T >::isStrong ( ) const

Return true is this represents a strong pointer.

◆ isWeak()

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

Return true is this represents a weak pointer.

◆ convertToStrong()

template<class T >
bool ripple::SharedWeakCachePointer< 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::SharedWeakCachePointer< 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.

Member Data Documentation

◆ combo_

template<class T >
std::variant<std::shared_ptr<T>, std::weak_ptr<T> > ripple::SharedWeakCachePointer< T >::combo_
private

Definition at line 132 of file SharedWeakCachePointer.h.