20 #ifndef RIPPLE_BASICS_XRPAMOUNT_H_INCLUDED
21 #define RIPPLE_BASICS_XRPAMOUNT_H_INCLUDED
23 #include <ripple/basics/contract.h>
24 #include <ripple/basics/safe_cast.h>
25 #include <ripple/beast/utility/Zero.h>
26 #include <ripple/json/json_value.h>
28 #include <boost/multiprecision/cpp_int.hpp>
29 #include <boost/operators.hpp>
46 class XRPAmount :
private boost::totally_ordered<XRPAmount>,
47 private boost::additive<XRPAmount>,
48 private boost::equality_comparable<XRPAmount, std::int64_t>,
49 private boost::additive<XRPAmount, std::int64_t>
158 explicit constexpr
operator bool() const noexcept
180 template <
class Dest>
191 return static_cast<Dest
>(
drops_);
194 template <
class Dest>
198 return dropsAs<Dest>().value_or(defaultValue);
201 template <
class Dest>
205 return dropsAs<Dest>().value_or(defaultValue.
drops());
212 std::is_signed_v<value_type> && std::is_integral_v<value_type>,
213 "Expected XRPAmount to be a signed integral type");
259 template <
class Char,
class Traits>
263 return os << q.
drops();
279 using namespace boost::multiprecision;
282 Throw<std::runtime_error>(
"division by zero");
284 int128_t
const amt128(amt.
drops());
285 auto const neg = amt.
drops() < 0;
286 auto const m = amt128 * num;
296 Throw<std::overflow_error>(
"XRP mulRatio overflow");
302 #endif // RIPPLE_BASICS_XRPAMOUNT_H_INCLUDED
IOUAmount mulRatio(IOUAmount const &amt, std::uint32_t num, std::uint32_t den, bool roundUp)
XRPAmount & operator-=(value_type const &rhs)
constexpr XRPAmount(value_type drops)
bool operator==(value_type other) const
constexpr XRPAmount & operator=(XRPAmount const &other)=default
XRPAmount & operator+=(value_type const &rhs)
friend std::istream & operator>>(std::istream &s, XRPAmount &val)
constexpr value_type value() const
Returns the underlying value.
constexpr value_type drops() const
Returns the number of drops.
bool operator==(XRPAmount const &other) const
std::ostream & operator<<(std::ostream &os, TOffer< TIn, TOut > const &offer)
feeunit::dropTag unit_type
constexpr XRPAmount operator*(value_type const &rhs) const
XRPAmount & operator*=(value_type const &rhs)
constexpr double decimalXRP() const
bool operator<(XRPAmount const &other) const
Zero allows classes to offer efficient comparisons to zero.
std::optional< Dest > dropsAs() const
Dest dropsAs(XRPAmount defaultValue) const
constexpr XRPAmount DROPS_PER_XRP
Number of drops per 1 XRP.
XRPAmount operator-() const
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
XRPAmount & operator-=(XRPAmount const &other)
constexpr friend XRPAmount operator*(value_type lhs, XRPAmount const &rhs)
XRPAmount & operator+=(XRPAmount const &other)
static XRPAmount minPositiveAmount()
std::string to_string(Manifest const &m)
Format the specified manifest to a string for debugging purposes.
XRPAmount & operator=(value_type drops)
constexpr XRPAmount & operator=(beast::Zero)
constexpr XRPAmount(beast::Zero)
Dest dropsAs(Dest defaultValue) const
Json::Value jsonClipped() const
constexpr int signum() const noexcept
Return the sign of the amount.