xrpld
Loading...
Searching...
No Matches
xrpl::SharedWeakCachePointer< T > Class Template Reference

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

#include <SharedWeakCachePointer.h>

Collaboration diagram for xrpl::SharedWeakCachePointer< T >:

Public Member Functions

 SharedWeakCachePointer ()=default
 SharedWeakCachePointer (SharedWeakCachePointer const &rhs)
template<class TT>
 SharedWeakCachePointer (std::shared_ptr< TT > const &rhs)
 SharedWeakCachePointer (SharedWeakCachePointer &&rhs)
template<class TT>
 SharedWeakCachePointer (std::shared_ptr< TT > &&rhs)
SharedWeakCachePointeroperator= (SharedWeakCachePointer const &rhs)
template<class TT>
SharedWeakCachePointeroperator= (std::shared_ptr< TT > const &rhs)
template<class TT>
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 useCount () 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 xrpl::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 17 of file SharedWeakCachePointer.h.

Constructor & Destructor Documentation

◆ SharedWeakCachePointer() [1/5]

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

◆ SharedWeakCachePointer() [2/5]

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

◆ SharedWeakCachePointer() [3/5]

template<class T>
template<class TT>
xrpl::SharedWeakCachePointer< T >::SharedWeakCachePointer ( std::shared_ptr< TT > const & rhs)

◆ SharedWeakCachePointer() [4/5]

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

◆ SharedWeakCachePointer() [5/5]

template<class T>
template<class TT>
xrpl::SharedWeakCachePointer< T >::SharedWeakCachePointer ( std::shared_ptr< TT > && rhs)

◆ ~SharedWeakCachePointer()

Member Function Documentation

◆ operator=() [1/3]

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

◆ operator=() [2/3]

template<class T>
template<class TT>
SharedWeakCachePointer & xrpl::SharedWeakCachePointer< T >::operator= ( std::shared_ptr< TT > const & rhs)

◆ operator=() [3/3]

template<class T>
template<class TT>
SharedWeakCachePointer & xrpl::SharedWeakCachePointer< T >::operator= ( std::shared_ptr< TT > && rhs)

◆ getStrong()

template<class T>
std::shared_ptr< T > const & xrpl::SharedWeakCachePointer< T >::getStrong ( ) const
nodiscard

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>
xrpl::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 xrpl::SharedWeakCachePointer< T >::reset ( )

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

◆ get()

template<class T>
T * xrpl::SharedWeakCachePointer< T >::get ( ) const
nodiscard

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

Otherwise return null.

◆ useCount()

template<class T>
std::size_t xrpl::SharedWeakCachePointer< T >::useCount ( ) const
nodiscard

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

Otherwise return 0

◆ expired()

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

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

◆ lock()

template<class T>
std::shared_ptr< T > xrpl::SharedWeakCachePointer< T >::lock ( ) const
nodiscard

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

Otherwise attempt to lock the weak pointer.

◆ isStrong()

template<class T>
bool xrpl::SharedWeakCachePointer< T >::isStrong ( ) const
nodiscard

Return true is this represents a strong pointer.

◆ isWeak()

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

Return true is this represents a weak pointer.

◆ convertToStrong()

template<class T>
bool xrpl::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 xrpl::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> > xrpl::SharedWeakCachePointer< T >::combo_
private

Definition at line 112 of file SharedWeakCachePointer.h.