xrpld
Loading...
Searching...
No Matches
xrpl::STAmount Class Referencefinal

#include <STAmount.h>

Inheritance diagram for xrpl::STAmount:
Collaboration diagram for xrpl::STAmount:

Classes

struct  Unchecked

Public Types

using mantissa_type = std::uint64_t
using exponent_type = int
using rep = std::pair<mantissa_type, exponent_type>
using value_type = STAmount

Public Member Functions

 STAmount (SerialIter &sit, SField const &name)
template<AssetType A>
 STAmount (SField const &name, A const &asset, mantissa_type mantissa, exponent_type exponent, bool negative, Unchecked)
template<AssetType A>
 STAmount (A const &asset, mantissa_type mantissa, exponent_type exponent, bool negative, Unchecked)
template<AssetType A>
 STAmount (SField const &name, A const &asset, mantissa_type mantissa=0, exponent_type exponent=0, bool negative=false)
 STAmount (SField const &name, std::int64_t mantissa)
 STAmount (SField const &name, std::uint64_t mantissa=0, bool negative=false)
 STAmount (std::uint64_t mantissa=0, bool negative=false)
 STAmount (SField const &name, STAmount const &amt)
template<AssetType A>
 STAmount (A const &asset, std::uint64_t mantissa=0, int exponent=0, bool negative=false)
template<AssetType A>
 STAmount (A const &asset, std::uint32_t mantissa, int exponent=0, bool negative=false)
template<AssetType A>
 STAmount (A const &asset, std::int64_t mantissa, int exponent=0)
template<AssetType A>
 STAmount (A const &asset, int mantissa, int exponent=0)
template<AssetType A>
 STAmount (A const &asset, Number const &number)
 STAmount (IOUAmount const &amount, Issue const &issue)
 STAmount (XRPAmount const &amount)
 STAmount (MPTAmount const &amount, MPTIssue const &mptIssue)
 operator Number () const
int exponent () const noexcept
bool integral () const noexcept
bool native () const noexcept
template<ValidIssueType TIss>
constexpr bool holds () const noexcept
bool negative () const noexcept
std::uint64_t mantissa () const noexcept
Asset const & asset () const
template<ValidIssueType TIss>
constexpr TIss const & get () const
template<ValidIssueType TIss>
TIss & get ()
AccountID const & getIssuer () const
int signum () const noexcept
STAmount zeroed () const
 Returns a zero value with the same issuer and currency.
void setJson (json::Value &) const
STAmount const & value () const noexcept
bool isZeroAtScale (int scale) const
 Checks if this amount evaluates to zero when constrained to a specific accounting scale.
 operator bool () const noexcept
STAmountoperator+= (STAmount const &)
STAmountoperator-= (STAmount const &)
STAmountoperator= (beast::Zero)
STAmountoperator= (XRPAmount const &amount)
STAmountoperator= (Number const &)
void negate ()
void clear ()
void clear (Asset const &asset)
void setIssue (Asset const &asset)
 Set the Issue for this amount.
SerializedTypeID getSType () const override
std::string getFullText () const override
std::string getText () const override
json::Value getJson (JsonOptions=JsonOptions::Values::None) const override
void add (Serializer &s) const override
bool isEquivalent (STBase const &t) const override
bool isDefault () const override
XRPAmount xrp () const
IOUAmount iou () const
MPTAmount mpt () const
template<ValidIssueType TIss>
constexpr TIss const & get () const
bool operator== (STBase const &t) const
template<class D>
D & downcast ()
template<class D>
D const & downcast () const
template<class D>
D const & downcast () const
void setFName (SField const &n)
 A STBase is a field.
SField const & getFName () const
void addFieldID (Serializer &s) const

Public Attributes

friend Object

Static Public Attributes

static constexpr int kMinOffset = -96
static constexpr int kMaxOffset = 80
static constexpr std::uint64_t kMinValue = 1'000'000'000'000'000ull
static constexpr std::uint64_t kMaxValue = (kMinValue * 10) - 1
static constexpr std::uint64_t kMaxNative = 9'000'000'000'000'000'000ull
static constexpr std::uint64_t kMaxNativeN = 100'000'000'000'000'000ull
static constexpr std::uint64_t kIssuedCurrency = 0x8'000'000'000'000'000ull
static constexpr std::uint64_t kPositive = 0x4'000'000'000'000'000ull
static constexpr std::uint64_t kMpToken = 0x2'000'000'000'000'000ull
static constexpr std::uint64_t kValueMask = ~(kPositive | kMpToken)
static std::uint64_t const kURateOne = getRate(STAmount(1), STAmount(1))

Static Protected Member Functions

template<class T>
static STBaseemplace (std::size_t n, void *buf, T &&val)

Private Member Functions

void set (std::int64_t v)
void canonicalize ()
STBasecopy (std::size_t n, void *buf) const override
STBasemove (std::size_t n, void *buf) override
STAmountoperator= (IOUAmount const &iou)

Static Private Member Functions

template<AssetType A>
static STAmount fromNumber (A const &asset, Number const &number)
static std::unique_ptr< STAmountconstruct (SerialIter &, SField const &name)
static auto & getCounter () noexcept

Private Attributes

Asset asset_
mantissa_type value_ {}
exponent_type offset_
bool isNegative_ {}
SField const * fName_

Friends

class detail::STVar
STAmount operator+ (STAmount const &v1, STAmount const &v2)

Detailed Description

Definition at line 45 of file STAmount.h.

Member Typedef Documentation

◆ mantissa_type

Definition at line 48 of file STAmount.h.

◆ exponent_type

Definition at line 49 of file STAmount.h.

◆ rep

Definition at line 50 of file STAmount.h.

◆ value_type

Definition at line 59 of file STAmount.h.

Constructor & Destructor Documentation

◆ STAmount() [1/16]

xrpl::STAmount::STAmount ( SerialIter & sit,
SField const & name )

Definition at line 112 of file STAmount.cpp.

◆ STAmount() [2/16]

template<AssetType A>
xrpl::STAmount::STAmount ( SField const & name,
A const & asset,
mantissa_type mantissa,
exponent_type exponent,
bool negative,
Unchecked  )

Definition at line 327 of file STAmount.h.

◆ STAmount() [3/16]

template<AssetType A>
xrpl::STAmount::STAmount ( A const & asset,
mantissa_type mantissa,
exponent_type exponent,
bool negative,
Unchecked  )

Definition at line 339 of file STAmount.h.

◆ STAmount() [4/16]

template<AssetType A>
xrpl::STAmount::STAmount ( SField const & name,
A const & asset,
mantissa_type mantissa = 0,
exponent_type exponent = 0,
bool negative = false )

Definition at line 350 of file STAmount.h.

◆ STAmount() [5/16]

xrpl::STAmount::STAmount ( SField const & name,
std::int64_t mantissa )

Definition at line 193 of file STAmount.cpp.

◆ STAmount() [6/16]

xrpl::STAmount::STAmount ( SField const & name,
std::uint64_t mantissa = 0,
bool negative = false )

Definition at line 199 of file STAmount.cpp.

◆ STAmount() [7/16]

xrpl::STAmount::STAmount ( std::uint64_t mantissa = 0,
bool negative = false )
explicit

Definition at line 223 of file STAmount.cpp.

◆ STAmount() [8/16]

xrpl::STAmount::STAmount ( SField const & name,
STAmount const & amt )
explicit

Definition at line 208 of file STAmount.cpp.

◆ STAmount() [9/16]

template<AssetType A>
xrpl::STAmount::STAmount ( A const & asset,
std::uint64_t mantissa = 0,
int exponent = 0,
bool negative = false )

Definition at line 124 of file STAmount.h.

◆ STAmount() [10/16]

template<AssetType A>
xrpl::STAmount::STAmount ( A const & asset,
std::uint32_t mantissa,
int exponent = 0,
bool negative = false )

Definition at line 383 of file STAmount.h.

◆ STAmount() [11/16]

template<AssetType A>
xrpl::STAmount::STAmount ( A const & asset,
std::int64_t mantissa,
int exponent = 0 )

Definition at line 375 of file STAmount.h.

◆ STAmount() [12/16]

template<AssetType A>
xrpl::STAmount::STAmount ( A const & asset,
int mantissa,
int exponent = 0 )

Definition at line 389 of file STAmount.h.

◆ STAmount() [13/16]

template<AssetType A>
xrpl::STAmount::STAmount ( A const & asset,
Number const & number )

Definition at line 141 of file STAmount.h.

◆ STAmount() [14/16]

xrpl::STAmount::STAmount ( IOUAmount const & amount,
Issue const & issue )

Definition at line 395 of file STAmount.h.

◆ STAmount() [15/16]

xrpl::STAmount::STAmount ( XRPAmount const & amount)

Definition at line 232 of file STAmount.cpp.

◆ STAmount() [16/16]

xrpl::STAmount::STAmount ( MPTAmount const & amount,
MPTIssue const & mptIssue )

Definition at line 410 of file STAmount.h.

Member Function Documentation

◆ operator Number()

xrpl::STAmount::operator Number ( ) const

Definition at line 541 of file STAmount.h.

◆ exponent()

int xrpl::STAmount::exponent ( ) const
nodiscardnoexcept

Definition at line 459 of file STAmount.h.

◆ integral()

bool xrpl::STAmount::integral ( ) const
nodiscardnoexcept

Definition at line 465 of file STAmount.h.

◆ native()

bool xrpl::STAmount::native ( ) const
nodiscardnoexcept

Definition at line 471 of file STAmount.h.

◆ holds()

template<ValidIssueType TIss>
bool xrpl::STAmount::holds ( ) const
nodiscardconstexprnoexcept

Definition at line 478 of file STAmount.h.

◆ negative()

bool xrpl::STAmount::negative ( ) const
nodiscardnoexcept

Definition at line 484 of file STAmount.h.

◆ mantissa()

std::uint64_t xrpl::STAmount::mantissa ( ) const
nodiscardnoexcept

Definition at line 490 of file STAmount.h.

◆ asset()

Asset const & xrpl::STAmount::asset ( ) const
nodiscard

Definition at line 496 of file STAmount.h.

◆ get() [1/3]

template<ValidIssueType TIss>
TIss const & xrpl::STAmount::get ( ) const
constexpr

◆ get() [2/3]

template<ValidIssueType TIss>
TIss & xrpl::STAmount::get ( )

Definition at line 510 of file STAmount.h.

◆ getIssuer()

AccountID const & xrpl::STAmount::getIssuer ( ) const
nodiscard

Definition at line 516 of file STAmount.h.

◆ signum()

int xrpl::STAmount::signum ( ) const
nodiscardnoexcept

Definition at line 522 of file STAmount.h.

◆ zeroed()

STAmount xrpl::STAmount::zeroed ( ) const
nodiscard

Returns a zero value with the same issuer and currency.

Definition at line 530 of file STAmount.h.

◆ setJson()

void xrpl::STAmount::setJson ( json::Value & elem) const

Definition at line 606 of file STAmount.cpp.

◆ value()

STAmount const & xrpl::STAmount::value ( ) const
nodiscardnoexcept

Definition at line 610 of file STAmount.h.

◆ isZeroAtScale()

bool xrpl::STAmount::isZeroAtScale ( int scale) const
nodiscard

Checks if this amount evaluates to zero when constrained to a specific accounting scale.

For XRP and MPT roundToScale is a no-op, returns true only when the amount itself is zero. The scale argument is ignored in that case. For IOU, the amount is rounded to the given scale using Number::RoundingMode::ToNearest mode and the result is checked for zero; if scale <= exponent(), roundToScale short-circuits and returns the value unchanged, so this returns false for any non-zero amount.

Parameters
scaleThe target accounting scale to evaluate against.
Returns
true if this amount rounds to zero at the given scale, false otherwise.
See also
roundToScale

Definition at line 1738 of file STAmount.cpp.

◆ operator bool()

xrpl::STAmount::operator bool ( ) const
explicitnoexcept

Definition at line 535 of file STAmount.h.

◆ operator+=()

STAmount & xrpl::STAmount::operator+= ( STAmount const & a)

Definition at line 358 of file STAmount.cpp.

◆ operator-=()

STAmount & xrpl::STAmount::operator-= ( STAmount const & a)

Definition at line 365 of file STAmount.cpp.

◆ operator=() [1/4]

STAmount & xrpl::STAmount::operator= ( beast::Zero )

Definition at line 554 of file STAmount.h.

◆ operator=() [2/4]

STAmount & xrpl::STAmount::operator= ( XRPAmount const & amount)

Definition at line 561 of file STAmount.h.

◆ operator=() [3/4]

STAmount & xrpl::STAmount::operator= ( Number const & number)

Definition at line 333 of file STAmount.cpp.

◆ negate()

void xrpl::STAmount::negate ( )

Definition at line 586 of file STAmount.h.

◆ clear() [1/2]

void xrpl::STAmount::clear ( )

Definition at line 593 of file STAmount.h.

◆ clear() [2/2]

void xrpl::STAmount::clear ( Asset const & asset)

Definition at line 603 of file STAmount.h.

◆ setIssue()

void xrpl::STAmount::setIssue ( Asset const & asset)

Set the Issue for this amount.

Definition at line 407 of file STAmount.cpp.

◆ getSType()

SerializedTypeID xrpl::STAmount::getSType ( ) const
nodiscardoverridevirtual

Reimplemented from xrpl::STBase.

Definition at line 630 of file STAmount.cpp.

◆ getFullText()

std::string xrpl::STAmount::getFullText ( ) const
nodiscardoverridevirtual

Reimplemented from xrpl::STBase.

Definition at line 636 of file STAmount.cpp.

◆ getText()

std::string xrpl::STAmount::getText ( ) const
nodiscardoverridevirtual

Reimplemented from xrpl::STBase.

Definition at line 646 of file STAmount.cpp.

◆ getJson()

json::Value xrpl::STAmount::getJson ( JsonOptions = JsonOptions::Values::None) const
nodiscardoverridevirtual

Reimplemented from xrpl::STBase.

Definition at line 734 of file STAmount.cpp.

◆ add()

void xrpl::STAmount::add ( Serializer & s) const
overridevirtual

Reimplemented from xrpl::STBase.

Definition at line 742 of file STAmount.cpp.

◆ isEquivalent()

bool xrpl::STAmount::isEquivalent ( STBase const & t) const
nodiscardoverridevirtual

Reimplemented from xrpl::STBase.

Definition at line 790 of file STAmount.cpp.

◆ isDefault()

bool xrpl::STAmount::isDefault ( ) const
nodiscardoverridevirtual

Reimplemented from xrpl::STBase.

Definition at line 797 of file STAmount.cpp.

◆ xrp()

XRPAmount xrpl::STAmount::xrp ( ) const
nodiscard

Definition at line 271 of file STAmount.cpp.

◆ iou()

IOUAmount xrpl::STAmount::iou ( ) const
nodiscard

Definition at line 286 of file STAmount.cpp.

◆ mpt()

MPTAmount xrpl::STAmount::mpt ( ) const
nodiscard

Definition at line 301 of file STAmount.cpp.

◆ fromNumber()

template<AssetType A>
STAmount xrpl::STAmount::fromNumber ( A const & asset,
Number const & number )
staticprivate

Definition at line 569 of file STAmount.h.

◆ construct()

std::unique_ptr< STAmount > xrpl::STAmount::construct ( SerialIter & sit,
SField const & name )
staticprivate

Definition at line 248 of file STAmount.cpp.

◆ set()

void xrpl::STAmount::set ( std::int64_t v)
private

Definition at line 878 of file STAmount.cpp.

◆ canonicalize()

void xrpl::STAmount::canonicalize ( )
private

Definition at line 821 of file STAmount.cpp.

◆ copy()

STBase * xrpl::STAmount::copy ( std::size_t n,
void * buf ) const
overrideprivatevirtual

Reimplemented from xrpl::STBase.

Definition at line 254 of file STAmount.cpp.

◆ move()

STBase * xrpl::STAmount::move ( std::size_t n,
void * buf )
overrideprivatevirtual

Reimplemented from xrpl::STBase.

Definition at line 260 of file STAmount.cpp.

◆ operator=() [4/4]

STAmount & xrpl::STAmount::operator= ( IOUAmount const & iou)
private

Definition at line 316 of file STAmount.cpp.

◆ get() [3/3]

template<ValidIssueType TIss>
TIss const & xrpl::STAmount::get ( ) const
nodiscardconstexpr

Definition at line 503 of file STAmount.h.

◆ operator==()

bool xrpl::STBase::operator== ( STBase const & t) const
inherited

Definition at line 36 of file STBase.cpp.

◆ downcast() [1/3]

template<class D>
D & xrpl::STBase::downcast ( )
inherited

Definition at line 206 of file STBase.h.

◆ downcast() [2/3]

template<class D>
D const & xrpl::STBase::downcast ( ) const
inherited

◆ downcast() [3/3]

template<class D>
D const & xrpl::STBase::downcast ( ) const
nodiscardinherited

Definition at line 216 of file STBase.h.

◆ setFName()

void xrpl::STBase::setFName ( SField const & n)
inherited

A STBase is a field.

This sets the name.

Definition at line 113 of file STBase.cpp.

◆ getFName()

SField const & xrpl::STBase::getFName ( ) const
nodiscardinherited

Definition at line 120 of file STBase.cpp.

◆ addFieldID()

void xrpl::STBase::addFieldID ( Serializer & s) const
inherited

Definition at line 126 of file STBase.cpp.

◆ emplace()

template<class T>
STBase * xrpl::STBase::emplace ( std::size_t n,
void * buf,
T && val )
staticprotectedinherited

Definition at line 226 of file STBase.h.

◆ getCounter()

auto & xrpl::CountedObject< STAmount >::getCounter ( )
staticprivatenoexceptinherited

Definition at line 113 of file CountedObject.h.

◆ detail::STVar

friend class detail::STVar
friend

Definition at line 320 of file STAmount.h.

◆ operator+

STAmount operator+ ( STAmount const & v1,
STAmount const & v2 )
friend

Definition at line 372 of file STAmount.cpp.

Member Data Documentation

◆ asset_

Asset xrpl::STAmount::asset_
private

Definition at line 53 of file STAmount.h.

◆ value_

mantissa_type xrpl::STAmount::value_ {}
private

Definition at line 54 of file STAmount.h.

◆ offset_

exponent_type xrpl::STAmount::offset_
private

Definition at line 55 of file STAmount.h.

◆ isNegative_

bool xrpl::STAmount::isNegative_ {}
private

Definition at line 56 of file STAmount.h.

◆ kMinOffset

int xrpl::STAmount::kMinOffset = -96
staticconstexpr

Definition at line 61 of file STAmount.h.

◆ kMaxOffset

int xrpl::STAmount::kMaxOffset = 80
staticconstexpr

Definition at line 62 of file STAmount.h.

◆ kMinValue

std::uint64_t xrpl::STAmount::kMinValue = 1'000'000'000'000'000ull
staticconstexpr

Definition at line 65 of file STAmount.h.

◆ kMaxValue

std::uint64_t xrpl::STAmount::kMaxValue = (kMinValue * 10) - 1
staticconstexpr

Definition at line 67 of file STAmount.h.

◆ kMaxNative

std::uint64_t xrpl::STAmount::kMaxNative = 9'000'000'000'000'000'000ull
staticconstexpr

Definition at line 69 of file STAmount.h.

◆ kMaxNativeN

std::uint64_t xrpl::STAmount::kMaxNativeN = 100'000'000'000'000'000ull
staticconstexpr

Definition at line 72 of file STAmount.h.

◆ kIssuedCurrency

std::uint64_t xrpl::STAmount::kIssuedCurrency = 0x8'000'000'000'000'000ull
staticconstexpr

Definition at line 73 of file STAmount.h.

◆ kPositive

std::uint64_t xrpl::STAmount::kPositive = 0x4'000'000'000'000'000ull
staticconstexpr

Definition at line 74 of file STAmount.h.

◆ kMpToken

std::uint64_t xrpl::STAmount::kMpToken = 0x2'000'000'000'000'000ull
staticconstexpr

Definition at line 75 of file STAmount.h.

◆ kValueMask

std::uint64_t xrpl::STAmount::kValueMask = ~(kPositive | kMpToken)
staticconstexpr

Definition at line 76 of file STAmount.h.

◆ kURateOne

std::uint64_t const xrpl::STAmount::kURateOne = getRate(STAmount(1), STAmount(1))
static

Definition at line 78 of file STAmount.h.

◆ fName_

SField const* xrpl::STBase::fName_
privateinherited

Definition at line 130 of file STBase.h.

◆ Object

Definition at line 138 of file CountedObject.h.