xrpld
Loading...
Searching...
No Matches
SharedWeakCachePointer.h
1#pragma once
2
3#include <concepts>
4#include <cstddef>
5#include <memory>
6#include <variant>
7
8namespace xrpl {
9
18
19template <class T>
21{
22public:
24
26
27 template <class TT>
28 requires std::convertible_to<TT*, T*>
30
32
33 template <class TT>
34 requires std::convertible_to<TT*, T*>
36
39
40 template <class TT>
41 requires std::convertible_to<TT*, T*>
44
45 template <class TT>
46 requires std::convertible_to<TT*, T*>
49
51
56 [[nodiscard]] std::shared_ptr<T> const&
57 getStrong() const;
58
63 explicit
64 operator bool() const noexcept;
65
70 void
72
77 [[nodiscard]] T*
78 get() const;
79
83 [[nodiscard]] std::size_t
84 useCount() const;
85
89 [[nodiscard]] bool
90 expired() const;
91
96 [[nodiscard]] std::shared_ptr<T>
97 lock() const;
98
102 [[nodiscard]] bool
103 isStrong() const;
104
108 [[nodiscard]] bool
109 isWeak() const;
110
117 bool
119
125 bool
127
128private:
129 std::variant<std::shared_ptr<T>, std::weak_ptr<T>> combo_;
130};
131} // namespace xrpl
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.
SharedWeakCachePointer & operator=(std::shared_ptr< TT > &&rhs)
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.
std::size_t useCount() const
If this is a strong pointer, return the strong count.
SharedWeakCachePointer(std::shared_ptr< TT > &&rhs)
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.
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(std::shared_ptr< TT > const &rhs)
SharedWeakCachePointer & operator=(std::shared_ptr< TT > const &rhs)
STL namespace.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5