Skip to content

Commit

Permalink
Remove STBase and CountedObject inheritance from STAmount and STMPTAm…
Browse files Browse the repository at this point in the history
…ount
  • Loading branch information
gregtatcam committed Aug 1, 2024
1 parent 5386172 commit cdd3251
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 219 deletions.
63 changes: 18 additions & 45 deletions include/xrpl/protocol/STAmount.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,16 @@
#include <xrpl/basics/Number.h>
#include <xrpl/basics/XRPAmount.h>
#include <xrpl/protocol/Issue.h>
#include <xrpl/protocol/SField.h>
#include <xrpl/protocol/STBase.h>
#include <xrpl/protocol/Serializer.h>
#include <xrpl/protocol/json_get_or_throw.h>

namespace ripple {

struct int64_tag_t
{
};

// Internal form:
// 1: If amount is zero, then value is zero and offset is -100
// 2: Otherwise:
Expand All @@ -43,7 +46,7 @@ namespace ripple {
// Wire form:
// High 8 bits are (offset+142), legal range is, 80 to 22 inclusive
// Low 56 bits are value, legal range is 10^15 to (10^16 - 1) inclusive
class STAmount final : public STBase, public CountedObject<STAmount>
class STAmount final
{
public:
using mantissa_type = std::uint64_t;
Expand Down Expand Up @@ -76,24 +79,14 @@ class STAmount final : public STBase, public CountedObject<STAmount>
static std::uint64_t const uRateOne;

//--------------------------------------------------------------------------
STAmount(std::uint64_t value, SerialIter& sit, SField const& name);
STAmount(SerialIter& sit, SField const& name);
STAmount(std::uint64_t value, SerialIter& sit);
STAmount(SerialIter& sit);

struct unchecked
{
explicit unchecked() = default;
};

// Do not call canonicalize
STAmount(
SField const& name,
Issue const& issue,
mantissa_type mantissa,
exponent_type exponent,
bool native,
bool negative,
unchecked);

STAmount(
Issue const& issue,
mantissa_type mantissa,
Expand All @@ -104,31 +97,16 @@ class STAmount final : public STBase, public CountedObject<STAmount>

// Call canonicalize
STAmount(
SField const& name,
Issue const& issue,
mantissa_type mantissa,
exponent_type exponent,
bool native,
bool negative);

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

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

STAmount(
SField const& name,
Issue const& issue,
std::uint64_t mantissa = 0,
int exponent = 0,
bool negative = false);
STAmount(std::int64_t mantissa, int64_tag_t);

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

explicit STAmount(SField const& name, STAmount const& amt);

STAmount(
Issue const& issue,
std::uint64_t mantissa = 0,
Expand Down Expand Up @@ -243,24 +221,21 @@ class STAmount final : public STBase, public CountedObject<STAmount>
//--------------------------------------------------------------------------

SerializedTypeID
getSType() const override;
getSType() const;

std::string
getFullText() const override;
getFullText() const;

std::string
getText() const override;
getText() const;

Json::Value getJson(JsonOptions) const override;
Json::Value getJson(JsonOptions) const;

void
add(Serializer& s) const override;

bool
isEquivalent(const STBase& t) const override;
add(Serializer& s) const;

bool
isDefault() const override;
isDefault() const;

XRPAmount
xrp() const;
Expand All @@ -269,18 +244,13 @@ class STAmount final : public STBase, public CountedObject<STAmount>

private:
static std::unique_ptr<STAmount>
construct(SerialIter&, SField const& name);
construct(SerialIter&);

void
set(std::int64_t v);
void
canonicalize();

STBase*
copy(std::size_t n, void* buf) const override;
STBase*
move(std::size_t n, void* buf) override;

STAmount&
operator=(IOUAmount const& iou);

Expand Down Expand Up @@ -478,6 +448,9 @@ operator>=(STAmount const& lhs, STAmount const& rhs)
STAmount
operator-(STAmount const& value);

std::ostream&
operator<<(std::ostream& out, const STAmount& t);

//------------------------------------------------------------------------------
//
// Arithmetic
Expand Down
26 changes: 8 additions & 18 deletions include/xrpl/protocol/STMPTAmount.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,54 +23,44 @@
#include <xrpl/basics/CountedObject.h>
#include <xrpl/basics/MPTAmount.h>
#include <xrpl/protocol/MPTIssue.h>
#include <xrpl/protocol/SField.h>
#include <xrpl/protocol/STBase.h>

namespace ripple {

struct Rate;

class STMPTAmount final : public MPTAmount,
public STBase,
public CountedObject<STMPTAmount>
class STMPTAmount final : public MPTAmount
{
private:
MPTIssue issue_;

public:
static constexpr std::uint64_t cMPToken = 0x2000000000000000ull;

STMPTAmount(std::uint64_t value, SerialIter& sit, SField const& name);
STMPTAmount(
SField const& name,
MPTIssue const& issue,
std::int64_t value = 0);
STMPTAmount(std::uint64_t value, SerialIter& sit);
STMPTAmount(MPTIssue const& issue, std::uint64_t value);
STMPTAmount(MPTIssue const& issue, std::int64_t value = 0);
explicit STMPTAmount(value_type value = 0);

SerializedTypeID
getSType() const override;
getSType() const;

std::string
getFullText() const override;
getFullText() const;

std::string
getText() const override;
getText() const;

Json::Value getJson(JsonOptions) const override;
Json::Value getJson(JsonOptions) const;

void
add(Serializer& s) const override;
add(Serializer& s) const;

void
setJson(Json::Value& elem) const;

bool
isEquivalent(const STBase& t) const override;

bool
isDefault() const override;
isDefault() const;

AccountID const&
getIssuer() const;
Expand Down
Loading

0 comments on commit cdd3251

Please sign in to comment.