rippled
Loading...
Searching...
No Matches
SharedWeakCachePointer.h
1#ifndef XRPL_BASICS_SHAREDWEAKCACHEPOINTER_H_INCLUDED
2#define XRPL_BASICS_SHAREDWEAKCACHEPOINTER_H_INCLUDED
3
4#include <memory>
5#include <variant>
6
7namespace ripple {
8
17template <class T>
19{
20public:
22
24
25 template <class TT>
28
30
31 template <class TT>
34
37
38 template <class TT>
42
43 template <class TT>
47
49
54 getStrong() const;
55
59 explicit
60 operator bool() const noexcept;
61
65 void
67
71 T*
72 get() const;
73
76 std::size_t
77 use_count() const;
78
80 bool
81 expired() const;
82
86 std::shared_ptr<T>
87 lock() const;
88
90 bool
91 isStrong() const;
92
94 bool
95 isWeak() const;
96
102 bool
104
109 bool
111
112private:
113 std::variant<std::shared_ptr<T>, std::weak_ptr<T>> combo_;
114};
115} // namespace ripple
116#endif
A combination of a std::shared_ptr and a std::weak_pointer.
std::shared_ptr< T > const & getStrong() const
Return a strong pointer if this is already a strong pointer (i.e.
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 convertToWeak()
If this is a strong pointer, attempt to convert it to a weak pointer.
void reset()
Set the pointer to null, decrement the appropriate ref count, and run the appropriate release action.
bool convertToStrong()
If this is a weak pointer, attempt to convert it to a strong pointer.
SharedWeakCachePointer & operator=(SharedWeakCachePointer const &rhs)
std::size_t use_count() const
If this is a strong pointer, return the strong count.
std::variant< std::shared_ptr< T >, std::weak_ptr< T > > combo_
SharedWeakCachePointer(SharedWeakCachePointer const &rhs)
SharedWeakCachePointer(std::shared_ptr< TT > &&rhs)
bool isStrong() const
Return true is this represents a strong pointer.
SharedWeakCachePointer & operator=(std::shared_ptr< TT > const &rhs)
T * get() const
If this is a strong pointer, return the raw pointer.
SharedWeakCachePointer & operator=(std::shared_ptr< TT > &&rhs)
SharedWeakCachePointer(std::shared_ptr< TT > const &rhs)
bool isWeak() const
Return true is this represents a weak pointer.
SharedWeakCachePointer(SharedWeakCachePointer &&rhs)
T is_same_v
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
STL namespace.