xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
include
xrpl
basics
SharedWeakCachePointer.h
1
#pragma once
2
3
#include <
concepts
>
4
#include <
cstddef
>
5
#include <
memory
>
6
#include <
variant
>
7
8
namespace
xrpl
{
9
18
19
template
<
class
T>
20
class
SharedWeakCachePointer
21
{
22
public
:
23
SharedWeakCachePointer
() =
default
;
24
25
SharedWeakCachePointer
(
SharedWeakCachePointer
const
& rhs);
26
27
template
<
class
TT>
28
requires
std::convertible_to<TT*, T*>
29
SharedWeakCachePointer
(
std::shared_ptr<TT>
const
& rhs);
30
31
SharedWeakCachePointer
(
SharedWeakCachePointer
&& rhs);
32
33
template
<
class
TT>
34
requires
std::convertible_to<TT*, T*>
35
SharedWeakCachePointer
(
std::shared_ptr<TT>
&& rhs);
36
37
SharedWeakCachePointer
&
38
operator=
(
SharedWeakCachePointer
const
& rhs);
39
40
template
<
class
TT>
41
requires
std::convertible_to<TT*, T*>
42
SharedWeakCachePointer
&
43
operator=
(
std::shared_ptr<TT>
const
& rhs);
44
45
template
<
class
TT>
46
requires
std::convertible_to<TT*, T*>
47
SharedWeakCachePointer
&
48
operator=
(
std::shared_ptr<TT>
&& rhs);
49
50
~SharedWeakCachePointer
();
51
56
[[nodiscard]]
std::shared_ptr<T>
const
&
57
getStrong
()
const
;
58
63
explicit
64
operator
bool() const noexcept;
65
70
void
71
reset
();
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
118
convertToStrong
();
119
125
bool
126
convertToWeak
();
127
128
private:
129
std
::variant<
std
::shared_ptr<T>,
std
::weak_ptr<T>>
combo_
;
130
};
131
}
// namespace xrpl
xrpl::SharedWeakCachePointer::SharedWeakCachePointer
SharedWeakCachePointer(std::shared_ptr< TT > &&rhs)
xrpl::SharedWeakCachePointer::get
T * get() const
If this is a strong pointer, return the raw pointer.
xrpl::SharedWeakCachePointer::expired
bool expired() const
Return true if there is a non-zero strong count.
xrpl::SharedWeakCachePointer::convertToStrong
bool convertToStrong()
If this is a weak pointer, attempt to convert it to a strong pointer.
xrpl::SharedWeakCachePointer::SharedWeakCachePointer
SharedWeakCachePointer(SharedWeakCachePointer const &rhs)
xrpl::SharedWeakCachePointer::operator=
SharedWeakCachePointer & operator=(SharedWeakCachePointer const &rhs)
xrpl::SharedWeakCachePointer::convertToWeak
bool convertToWeak()
If this is a strong pointer, attempt to convert it to a weak pointer.
xrpl::SharedWeakCachePointer::isStrong
bool isStrong() const
Return true is this represents a strong pointer.
xrpl::SharedWeakCachePointer::reset
void reset()
Set the pointer to null, decrement the appropriate ref count, and run the appropriate release action.
xrpl::SharedWeakCachePointer::useCount
std::size_t useCount() const
If this is a strong pointer, return the strong count.
xrpl::SharedWeakCachePointer::isWeak
bool isWeak() const
Return true is this represents a weak pointer.
xrpl::SharedWeakCachePointer::SharedWeakCachePointer
SharedWeakCachePointer(SharedWeakCachePointer &&rhs)
xrpl::SharedWeakCachePointer::lock
std::shared_ptr< T > lock() const
If this is a strong pointer, return the strong pointer.
xrpl::SharedWeakCachePointer::operator=
SharedWeakCachePointer & operator=(std::shared_ptr< TT > &&rhs)
xrpl::SharedWeakCachePointer::SharedWeakCachePointer
SharedWeakCachePointer(std::shared_ptr< TT > const &rhs)
xrpl::SharedWeakCachePointer::getStrong
std::shared_ptr< T > const & getStrong() const
Return a strong pointer if this is already a strong pointer (i.e.
xrpl::SharedWeakCachePointer::combo_
std::variant< std::shared_ptr< T >, std::weak_ptr< T > > combo_
Definition
SharedWeakCachePointer.h:129
xrpl::SharedWeakCachePointer::operator=
SharedWeakCachePointer & operator=(std::shared_ptr< TT > const &rhs)
xrpl::SharedWeakCachePointer::~SharedWeakCachePointer
~SharedWeakCachePointer()
xrpl::SharedWeakCachePointer::SharedWeakCachePointer
SharedWeakCachePointer()=default
concepts
cstddef
memory
std
STL namespace.
xrpl
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition
algorithm.h:5
std::shared_ptr
variant
Generated by
1.17.0