xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
include
xrpl
tx
paths
detail
EitherAmount.h
1
#pragma once
2
3
#include <xrpl/basics/contract.h>
4
#include <xrpl/protocol/Concepts.h>
5
#include <xrpl/protocol/IOUAmount.h>
6
#include <xrpl/protocol/MPTAmount.h>
// IWYU pragma: keep
7
#include <xrpl/protocol/XRPAmount.h>
8
9
#include <
ostream
>
// IWYU pragma: keep
10
#include <
stdexcept
>
11
#include <
variant
>
12
13
namespace
xrpl
{
14
15
struct
EitherAmount
16
{
17
std::variant<XRPAmount, IOUAmount, MPTAmount>
amount
;
18
19
explicit
EitherAmount
() =
default
;
20
21
template
<StepAmount T>
22
explicit
EitherAmount
(T
const
& a) :
amount
(a)
23
{
24
}
25
26
template
<StepAmount T>
27
[[nodiscard]]
bool
28
holds
()
const
29
{
30
return
std::holds_alternative<T>
(
amount
);
31
}
32
33
template
<StepAmount T>
34
[[nodiscard]] T
const
&
35
get
()
const
36
{
37
if
(!
holds<T>
())
38
Throw<std::logic_error>
(
"EitherAmount doesn't hold requested amount"
);
39
return
std::get<T>(
amount
);
40
}
41
42
#ifndef NDEBUG
43
friend
std::ostream
&
44
operator<<
(
std::ostream
& stream,
EitherAmount
const
& amt)
45
{
46
std::visit
([&]<
StepAmount
T>(T
const
& a) { stream <<
to_string
(a); }, amt.
amount
);
47
return
stream;
48
}
49
#endif
50
};
51
52
template
<StepAmount T>
53
T
const
&
54
get
(
EitherAmount
const
& amt)
55
{
56
return
amt.
get
<T>();
57
}
58
59
}
// namespace xrpl
std::ostream
xrpl::StepAmount
Definition
Concepts.h:18
std::holds_alternative
T holds_alternative(T... args)
xrpl
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition
algorithm.h:5
xrpl::get
T get(Section const §ion, std::string const &name, T const &defaultValue=T{})
Retrieve a key/value pair from a section.
Definition
BasicConfig.h:360
xrpl::to_string
std::string to_string(BaseUInt< Bits, Tag > const &a)
Definition
base_uint.h:657
xrpl::Throw
XRPL_NO_SANITIZE_ADDRESS void Throw(Args &&... args)
Definition
contract.h:52
ostream
stdexcept
xrpl::EitherAmount
Definition
EitherAmount.h:16
xrpl::EitherAmount::amount
std::variant< XRPAmount, IOUAmount, MPTAmount > amount
Definition
EitherAmount.h:17
xrpl::EitherAmount::EitherAmount
EitherAmount(T const &a)
Definition
EitherAmount.h:22
xrpl::EitherAmount::holds
bool holds() const
Definition
EitherAmount.h:28
xrpl::EitherAmount::get
T const & get() const
Definition
EitherAmount.h:35
xrpl::EitherAmount::EitherAmount
EitherAmount()=default
xrpl::EitherAmount::operator<<
friend std::ostream & operator<<(std::ostream &stream, EitherAmount const &amt)
Definition
EitherAmount.h:44
variant
std::visit
T visit(T... args)
Generated by
1.17.0