mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Continue currency work.
This commit is contained in:
@@ -18,6 +18,9 @@ protected:
|
|||||||
uint160 mValue;
|
uint160 mValue;
|
||||||
CurrencyType mType;
|
CurrencyType mType;
|
||||||
|
|
||||||
|
static uint160 sNatMask; // bits that indicate national currency ISO code and version
|
||||||
|
static uint160 sNatZero; // bits that must be zero on a national currency
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Currency() : mType(ctNATIVE) { ; }
|
Currency() : mType(ctNATIVE) { ; }
|
||||||
Currency(const uint160& v);
|
Currency(const uint160& v);
|
||||||
@@ -30,6 +33,7 @@ public:
|
|||||||
|
|
||||||
const uint160& getCurrency() { return mValue; }
|
const uint160& getCurrency() { return mValue; }
|
||||||
unsigned char getScale() const;
|
unsigned char getScale() const;
|
||||||
|
void setScale(unsigned char c);
|
||||||
|
|
||||||
// These are only valid for national currencies
|
// These are only valid for national currencies
|
||||||
std::string getISO() const;
|
std::string getISO() const;
|
||||||
@@ -38,13 +42,19 @@ public:
|
|||||||
|
|
||||||
class Amount
|
class Amount
|
||||||
{
|
{
|
||||||
|
// CAUTION: Currency operations throw on overflows, underflos, or
|
||||||
|
// incommensurate currency opeations (like adding USD to Euros)
|
||||||
protected:
|
protected:
|
||||||
Currency mCurrency;
|
Currency mCurrency;
|
||||||
uint64 mQuantity;
|
uint64 mQuantity;
|
||||||
|
|
||||||
|
void canonicalize();
|
||||||
|
|
||||||
|
static uint64 sMaxCanon; // Max native currency value before shift
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Amount(const Currency& c, const uint64& q) : mCurrency(c), mQuantity(q) { ; }
|
Amount(const Currency& c, const uint64& q) : mCurrency(c), mQuantity(q) { canonicalize(); }
|
||||||
|
|
||||||
const Currency& getCurrency() const { return mCurrency; }
|
const Currency& getCurrency() const { return mCurrency; }
|
||||||
uint64 getQuantity() const { return mQuantity; }
|
uint64 getQuantity() const { return mQuantity; }
|
||||||
@@ -58,13 +68,13 @@ public:
|
|||||||
bool operator<=(const Amount&) const;
|
bool operator<=(const Amount&) const;
|
||||||
bool operator>(const Amount&) const;
|
bool operator>(const Amount&) const;
|
||||||
bool operator<(const Amount&) const;
|
bool operator<(const Amount&) const;
|
||||||
Amount operator+(const Amount&) const;
|
Amount& operator+=(const Amount& a) { return *this = *this + a; }
|
||||||
Amount operator-(const Amount&) const;
|
Amount& operator-=(const Amount& a) { return *this = *this - a; }
|
||||||
Amount& operator+=(const Amount&);
|
|
||||||
Amount& operator-=(const Amount&);
|
|
||||||
|
|
||||||
// This is used to score offers and works with incommensurate currencies
|
// This is used to score offers and works with incommensurate currencies
|
||||||
friend void divide(const Amount& offering, const Amount& taking, uint16& exponent, uint64& mantissa);
|
friend void divide(const Amount& offering, const Amount& taking, uint16& exponent, uint64& mantissa);
|
||||||
|
friend Amount& operator+(const Amount&, const Amount&);
|
||||||
|
friend Amount& operator-(const Amount&, const Amount&);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user