xrpld
Loading...
Searching...
No Matches
xrpl::STNumber Class Reference

A serializable number. More...

#include <STNumber.h>

Inheritance diagram for xrpl::STNumber:
Collaboration diagram for xrpl::STNumber:

Public Types

using value_type = Number

Public Member Functions

 STNumber ()=default
 STNumber (SField const &field, Number const &value=Number())
 STNumber (SerialIter &sit, SField const &field)
SerializedTypeID getSType () const override
std::string getText () const override
void add (Serializer &s) const override
Number const & value () const
void setValue (Number const &v)
STNumberoperator= (Number const &rhs)
bool isEquivalent (STBase const &t) const override
bool isDefault () const override
void associateAsset (Asset const &a) override
 operator Number () const
 STBase ()
 STBase (STBase const &)=default
 STBase (SField const &n)
bool operator== (STBase const &t) 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
virtual std::string getFullText () const
virtual json::Value getJson (JsonOptions=JsonOptions::Values::None) 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 Protected Member Functions

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

Protected Attributes

std::optional< Assetasset_

Private Member Functions

STBasecopy (std::size_t n, void *buf) const override
STBasemove (std::size_t n, void *buf) override

Static Private Member Functions

static auto & getCounter () noexcept

Private Attributes

Number value_
SField const * fName_

Detailed Description

A serializable number.

This type is-a Number, and can be used everywhere that is accepted. This type simply integrates Number with the serialization framework, letting it be used for fields in ledger entries and transactions. It is effectively an STAmount sans Asset: it can represent a value of any token type (XRP, IOU, or MPT) without paying the storage cost of duplicating asset information that may be deduced from the context.

STNumber derives from STTakesAsset, so that it can be associated with the related Asset during transaction processing. Which asset is relevant depends on the object and transaction. As of this writing, only Vault, LoanBroker, and Loan objects use STNumber fields. All of those fields represent amounts of the Vault's Asset, so they should be associated with the Vault's Asset.

e.g. associateAsset(*loanSle, asset); associateAsset(*brokerSle, asset); associateAsset(*vaultSle, asset);

Definition at line 34 of file STNumber.h.

Member Typedef Documentation

◆ value_type

Definition at line 40 of file STNumber.h.

Constructor & Destructor Documentation

◆ STNumber() [1/3]

xrpl::STNumber::STNumber ( )
default

◆ STNumber() [2/3]

xrpl::STNumber::STNumber ( SField const & field,
Number const & value = Number() )
explicit

Definition at line 30 of file STNumber.cpp.

◆ STNumber() [3/3]

xrpl::STNumber::STNumber ( SerialIter & sit,
SField const & field )

Definition at line 34 of file STNumber.cpp.

Member Function Documentation

◆ getSType()

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

Reimplemented from xrpl::STBase.

Definition at line 44 of file STNumber.cpp.

◆ getText()

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

Reimplemented from xrpl::STBase.

Definition at line 50 of file STNumber.cpp.

◆ add()

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

Reimplemented from xrpl::STBase.

Definition at line 69 of file STNumber.cpp.

◆ value()

Number const & xrpl::STNumber::value ( ) const
nodiscard

Definition at line 117 of file STNumber.cpp.

◆ setValue()

void xrpl::STNumber::setValue ( Number const & v)

Definition at line 123 of file STNumber.cpp.

◆ operator=()

STNumber & xrpl::STNumber::operator= ( Number const & rhs)

Definition at line 59 of file STNumber.h.

◆ isEquivalent()

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

Reimplemented from xrpl::STBase.

Definition at line 141 of file STNumber.cpp.

◆ isDefault()

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

Reimplemented from xrpl::STBase.

Definition at line 150 of file STNumber.cpp.

◆ associateAsset()

void xrpl::STNumber::associateAsset ( Asset const & a)
overridevirtual

Reimplemented from xrpl::STTakesAsset.

Definition at line 56 of file STNumber.cpp.

◆ operator Number()

xrpl::STNumber::operator Number ( ) const

Definition at line 73 of file STNumber.h.

◆ copy()

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

Reimplemented from xrpl::STBase.

Definition at line 129 of file STNumber.cpp.

◆ move()

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

Reimplemented from xrpl::STBase.

Definition at line 135 of file STNumber.cpp.

◆ STBase() [1/3]

xrpl::STBase::STBase ( )
inherited

Definition at line 122 of file STBase.cpp.

◆ STBase() [2/3]

xrpl::STBase::STBase ( STBase const & )
defaultinherited

◆ STBase() [3/3]

xrpl::STBase::STBase ( SField const & n)
explicitinherited

Definition at line 127 of file STBase.cpp.

◆ operator==()

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

Definition at line 36 of file STBase.cpp.

◆ operator!=()

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

Definition at line 42 of file STBase.cpp.

◆ downcast() [1/3]

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

Definition at line 195 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 205 of file STBase.h.

◆ getFullText()

std::string xrpl::STBase::getFullText ( ) const
nodiscardvirtualinherited

Reimplemented in xrpl::STAmount, xrpl::STArray, xrpl::STLedgerEntry, xrpl::STObject, and xrpl::STTx.

Definition at line 66 of file STBase.cpp.

◆ getJson()

◆ setFName()

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

A STBase is a field.

This sets the name.

Definition at line 119 of file STBase.cpp.

◆ getFName()

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

Definition at line 126 of file STBase.cpp.

◆ addFieldID()

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

Definition at line 132 of file STBase.cpp.

◆ emplace()

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

Definition at line 215 of file STBase.h.

◆ getCounter()

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

Definition at line 109 of file CountedObject.h.

Member Data Documentation

◆ value_

Number xrpl::STNumber::value_
private

Definition at line 37 of file STNumber.h.

◆ asset_

std::optional<Asset> xrpl::STTakesAsset::asset_
protectedinherited

Definition at line 24 of file STTakesAsset.h.

◆ fName_

SField const* xrpl::STBase::fName_
privateinherited

Definition at line 118 of file STBase.h.

◆ Object

Definition at line 134 of file CountedObject.h.