xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
libxrpl
protocol
libxrpl/protocol/XRPAmount.cpp
1
#include <xrpl/protocol/XRPAmount.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
XRPAmount
&
13
XRPAmount::operator+=
(
value_type
const
& rhs)
14
{
15
if
(
auto
const
result =
checkedAdd
(
drops_
, rhs))
16
{
17
drops_
= *result;
18
return
*
this
;
19
}
20
if
(
isFeatureEnabled
(fixCleanup3_5_0,
/*resultIfNoRules*/
true
))
21
Throw<std::overflow_error>
(
"XRPAmount::operator+= overflow"
);
22
drops_
+= rhs;
23
return
*
this
;
24
}
25
26
XRPAmount
&
27
XRPAmount::operator-=
(
value_type
const
& rhs)
28
{
29
if
(
auto
const
result =
checkedSub
(
drops_
, rhs))
30
{
31
drops_
= *result;
32
return
*
this
;
33
}
34
if
(
isFeatureEnabled
(fixCleanup3_5_0,
/*resultIfNoRules*/
true
))
35
Throw<std::overflow_error>
(
"XRPAmount::operator-= overflow"
);
36
drops_
-= rhs;
37
return
*
this
;
38
}
39
40
XRPAmount
&
41
XRPAmount::operator*=
(
value_type
const
& rhs)
42
{
43
if
(
auto
const
result =
checkedMul
(
drops_
, rhs))
44
{
45
drops_
= *result;
46
return
*
this
;
47
}
48
if
(
isFeatureEnabled
(fixCleanup3_5_0,
/*resultIfNoRules*/
true
))
49
Throw<std::overflow_error>
(
"XRPAmount::operator*= overflow"
);
50
drops_
*= rhs;
51
return
*
this
;
52
}
53
54
}
// namespace xrpl
xrpl::XRPAmount
Definition
XRPAmount.h:29
xrpl::XRPAmount::operator-=
XRPAmount & operator-=(XRPAmount const &other)
Definition
XRPAmount.h:96
xrpl::XRPAmount::value_type
std::int64_t value_type
Definition
XRPAmount.h:32
xrpl::XRPAmount::drops_
value_type drops_
Definition
XRPAmount.h:35
xrpl::XRPAmount::operator+=
XRPAmount & operator+=(XRPAmount const &other)
Definition
XRPAmount.h:90
xrpl::XRPAmount::operator*=
XRPAmount & operator*=(value_type const &rhs)
Definition
libxrpl/protocol/XRPAmount.cpp:41
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::checkedMul
constexpr std::optional< std::int64_t > checkedMul(std::int64_t a, std::int64_t b) noexcept
Multiply two signed 64-bit integers, returning std::nullopt when the exact mathematical product is no...
Definition
MathUtilities.h:47
xrpl::Throw
XRPL_NO_SANITIZE_ADDRESS void Throw(Args &&... args)
Definition
contract.h:52
stdexcept
Generated by
1.17.0