1#ifndef XRPL_PROTOCOL_XRPAMOUNT_H_INCLUDED
2#define XRPL_PROTOCOL_XRPAMOUNT_H_INCLUDED
4#include <xrpl/basics/Number.h>
5#include <xrpl/basics/contract.h>
6#include <xrpl/beast/utility/Zero.h>
7#include <xrpl/json/json_value.h>
8#include <xrpl/protocol/Units.h>
10#include <boost/multiprecision/cpp_int.hpp>
11#include <boost/operators.hpp>
20class XRPAmount :
private boost::totally_ordered<XRPAmount>,
21 private boost::additive<XRPAmount>,
22 private boost::equality_comparable<XRPAmount, std::int64_t>,
23 private boost::additive<XRPAmount, std::int64_t>
139 operator bool() const noexcept
166 template <
class Dest>
177 return static_cast<Dest
>(
drops_);
180 template <
class Dest>
184 return dropsAs<Dest>().value_or(defaultValue);
187 template <
class Dest>
191 return dropsAs<Dest>().value_or(defaultValue.
drops());
203 "Expected XRPAmount to be a signed integral type");
249template <
class Char,
class Traits>
253 return os << q.
drops();
269 using namespace boost::multiprecision;
272 Throw<std::runtime_error>(
"division by zero");
274 int128_t
const amt128(amt.
drops());
275 auto const neg = amt.
drops() < 0;
276 auto const m = amt128 * num;
286 Throw<std::overflow_error>(
"XRP mulRatio overflow");
constexpr XRPAmount(beast::Zero)
XRPAmount & operator=(value_type drops)
Dest dropsAs(Dest defaultValue) const
constexpr value_type value() const
Returns the underlying value.
bool operator==(XRPAmount const &other) const
std::optional< Dest > dropsAs() const
constexpr int signum() const noexcept
Return the sign of the amount.
friend std::istream & operator>>(std::istream &s, XRPAmount &val)
XRPAmount & operator-=(XRPAmount const &other)
XRPAmount operator-() const
constexpr XRPAmount operator*(value_type const &rhs) const
XRPAmount & operator+=(value_type const &rhs)
constexpr value_type drops() const
Returns the number of drops.
XRPAmount & operator*=(value_type const &rhs)
constexpr XRPAmount & operator=(XRPAmount const &other)=default
XRPAmount & operator-=(value_type const &rhs)
static XRPAmount minPositiveAmount()
Dest dropsAs(XRPAmount defaultValue) const
constexpr XRPAmount(value_type drops)
XRPAmount & operator+=(XRPAmount const &other)
bool operator<(XRPAmount const &other) const
constexpr double decimalXRP() const
constexpr XRPAmount & operator=(beast::Zero)
Json::Value jsonClipped() const
bool operator==(value_type other) const
XRPAmount(Number const &x)
friend constexpr XRPAmount operator*(value_type lhs, XRPAmount const &rhs)
constexpr XRPAmount(XRPAmount const &other)=default
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
std::ostream & operator<<(std::ostream &out, base_uint< Bits, Tag > const &u)
IOUAmount mulRatio(IOUAmount const &amt, std::uint32_t num, std::uint32_t den, bool roundUp)
std::string to_string(base_uint< Bits, Tag > const &a)
constexpr XRPAmount DROPS_PER_XRP
Number of drops per 1 XRP.
Zero allows classes to offer efficient comparisons to zero.