xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
libxrpl
protocol
libxrpl/protocol/MPTAmount.cpp
1
#include <xrpl/protocol/MPTAmount.h>
2
3
#include <xrpl/basics/MathUtilities.h>
4
#include <xrpl/basics/contract.h>
5
#include <xrpl/protocol/Feature.h>
6
#include <xrpl/protocol/Rules.h>
7
8
#include <
stdexcept
>
9
10
namespace
xrpl
{
11
12
MPTAmount
&
13
MPTAmount::operator+=
(
MPTAmount
const
& other)
14
{
15
if
(
auto
const
result =
checkedAdd
(
value_
, other.
value
()))
16
{
17
value_
= *result;
18
return
*
this
;
19
}
20
if
(
isFeatureEnabled
(fixCleanup3_5_0,
/*resultIfNoRules*/
true
))
21
Throw<std::overflow_error>
(
"MPTAmount::operator+= overflow"
);
22
value_
+= other.
value
();
23
return
*
this
;
24
}
25
26
MPTAmount
&
27
MPTAmount::operator-=
(
MPTAmount
const
& other)
28
{
29
if
(
auto
const
result =
checkedSub
(
value_
, other.
value
()))
30
{
31
value_
= *result;
32
return
*
this
;
33
}
34
if
(
isFeatureEnabled
(fixCleanup3_5_0,
/*resultIfNoRules*/
true
))
35
Throw<std::overflow_error>
(
"MPTAmount::operator-= overflow"
);
36
value_
-= other.
value
();
37
return
*
this
;
38
}
39
40
MPTAmount
41
MPTAmount::operator-
()
const
42
{
43
return
MPTAmount
{-
value_
};
44
}
45
46
bool
47
MPTAmount::operator==
(
MPTAmount
const
& other)
const
48
{
49
return
value_
== other.
value_
;
50
}
51
52
bool
53
MPTAmount::operator==
(
value_type
other)
const
54
{
55
return
value_
== other;
56
}
57
58
bool
59
MPTAmount::operator<
(
MPTAmount
const
& other)
const
60
{
61
return
value_
< other.
value_
;
62
}
63
64
MPTAmount
65
MPTAmount::minPositiveAmount
()
66
{
67
return
MPTAmount
{1};
68
}
69
70
}
// namespace xrpl
xrpl::MPTAmount
Definition
MPTAmount.h:23
xrpl::MPTAmount::value_type
std::int64_t value_type
Definition
MPTAmount.h:25
xrpl::MPTAmount::operator==
bool operator==(MPTAmount const &other) const
Definition
libxrpl/protocol/MPTAmount.cpp:47
xrpl::MPTAmount::minPositiveAmount
static MPTAmount minPositiveAmount()
Definition
libxrpl/protocol/MPTAmount.cpp:65
xrpl::MPTAmount::operator-=
MPTAmount & operator-=(MPTAmount const &other)
Definition
libxrpl/protocol/MPTAmount.cpp:27
xrpl::MPTAmount::operator-
MPTAmount operator-() const
Definition
libxrpl/protocol/MPTAmount.cpp:41
xrpl::MPTAmount::value
constexpr value_type value() const
Returns the underlying value.
Definition
MPTAmount.h:135
xrpl::MPTAmount::operator<
bool operator<(MPTAmount const &other) const
Definition
libxrpl/protocol/MPTAmount.cpp:59
xrpl::MPTAmount::operator+=
MPTAmount & operator+=(MPTAmount const &other)
Definition
libxrpl/protocol/MPTAmount.cpp:13
xrpl::MPTAmount::value_
value_type value_
Definition
MPTAmount.h:28
xrpl::MPTAmount::MPTAmount
MPTAmount()=default
xrpl
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition
algorithm.h:5
xrpl::checkedSub
constexpr std::optional< std::int64_t > checkedSub(std::int64_t a, std::int64_t b) noexcept
Subtract two signed 64-bit integers, returning std::nullopt when the exact mathematical difference is...
Definition
MathUtilities.h:32
xrpl::checkedAdd
constexpr std::optional< std::int64_t > checkedAdd(std::int64_t a, std::int64_t b) noexcept
Add two signed 64-bit integers, returning std::nullopt when the exact mathematical sum is not represe...
Definition
MathUtilities.h:17
xrpl::isFeatureEnabled
bool isFeatureEnabled(UInt256 const &feature, bool resultIfNoRules)
Check whether a feature is enabled in the current ledger rules.
Definition
Rules.cpp:199
xrpl::Throw
XRPL_NO_SANITIZE_ADDRESS void Throw(Args &&... args)
Definition
contract.h:52
stdexcept
Generated by
1.17.0