xrpld
Loading...
Searching...
No Matches
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
10namespace xrpl {
11
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
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
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
XRPAmount & operator-=(XRPAmount const &other)
Definition XRPAmount.h:96
std::int64_t value_type
Definition XRPAmount.h:32
value_type drops_
Definition XRPAmount.h:35
XRPAmount & operator+=(XRPAmount const &other)
Definition XRPAmount.h:90
XRPAmount & operator*=(value_type const &rhs)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
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...
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...
bool isFeatureEnabled(UInt256 const &feature, bool resultIfNoRules)
Check whether a feature is enabled in the current ledger rules.
Definition Rules.cpp:199
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...
XRPL_NO_SANITIZE_ADDRESS void Throw(Args &&... args)
Definition contract.h:52