rippled
Loading...
Searching...
No Matches
SharedWeakCachePointer.h
1#pragma once
2
3#include <memory>
4#include <variant>
5
6namespace xrpl {
7
16template <class T>
18{
19public:
21
23
24 template <class TT>
27
29
30 template <class TT>
33
36
37 template <class TT>
41
42 template <class TT>
46
48
53 getStrong() const;
54
58 explicit
59 operator bool() const noexcept;
60
64 void
66
70 T*
71 get() const;
72
75 std::size_t
76 use_count() const;
77
79 bool
80 expired() const;
81
85 std::shared_ptr<T>
86 lock() const;
87
89 bool
90 isStrong() const;
91
93 bool
94 isWeak() const;
95
101 bool
103
108 bool
110
111private:
112 std::variant<std::shared_ptr<T>, std::weak_ptr<T>> combo_;
113};
114} // namespace xrpl
A combination of a std::shared_ptr and a std::weak_pointer.
std::size_t use_count() const
If this is a strong pointer, return the strong count.
SharedWeakCachePointer(std::shared_ptr< TT > &&rhs)
T * get() const
If this is a strong pointer, return the raw pointer.
bool expired() const
Return true if there is a non-zero strong count.
bool convertToStrong()
If this is a weak pointer, attempt to convert it to a strong pointer.
SharedWeakCachePointer(SharedWeakCachePointer const &rhs)
SharedWeakCachePointer & operator=(SharedWeakCachePointer const &rhs)
bool convertToWeak()
If this is a strong pointer, attempt to convert it to a weak pointer.
bool isStrong() const
Return true is this represents a strong pointer.
void reset()
Set the pointer to null, decrement the appropriate ref count, and run the appropriate release action.
bool isWeak() const
Return true is this represents a weak pointer.
SharedWeakCachePointer(SharedWeakCachePointer &&rhs)
std::shared_ptr< T > lock() const
If this is a strong pointer, return the strong pointer.
SharedWeakCachePointer & operator=(std::shared_ptr< TT > &&rhs)
SharedWeakCachePointer(std::shared_ptr< TT > const &rhs)
std::shared_ptr< T > const & getStrong() const
Return a strong pointer if this is already a strong pointer (i.e.
std::variant< std::shared_ptr< T >, std::weak_ptr< T > > combo_
SharedWeakCachePointer & operator=(std::shared_ptr< TT > const &rhs)
T is_same_v
STL namespace.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5