Restrict access to the virtual functions move and copy

* These are meant to be used by detail::STVar only and
  are otherwise error-prone to call.
This commit is contained in:
Howard Hinnant
2021-10-19 14:02:30 -04:00
committed by Nik Bougalis
parent 74e6ed1af3
commit 0c13676d5f
13 changed files with 103 additions and 75 deletions

View File

@@ -46,11 +46,6 @@ public:
STAccount(SerialIter& sit, SField const& name);
STAccount(SField const& n, AccountID const& v);
STBase*
copy(std::size_t n, void* buf) const override;
STBase*
move(std::size_t n, void* buf) override;
SerializedTypeID
getSType() const override;
@@ -74,6 +69,14 @@ public:
void
setValue(AccountID const& v);
private:
STBase*
copy(std::size_t n, void* buf) const override;
STBase*
move(std::size_t n, void* buf) override;
friend class detail::STVar;
};
inline STAccount&

View File

@@ -144,11 +144,6 @@ public:
STAmount(IOUAmount const& amount, Issue const& issue);
STAmount(XRPAmount const& amount);
STBase*
copy(std::size_t n, void* buf) const override;
STBase*
move(std::size_t n, void* buf) override;
//--------------------------------------------------------------------------
//
// Observers
@@ -273,6 +268,13 @@ private:
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;
friend class detail::STVar;
};
//------------------------------------------------------------------------------

View File

@@ -50,12 +50,6 @@ public:
explicit STArray(int n);
explicit STArray(SField const& f);
STBase*
copy(std::size_t n, void* buf) const override;
STBase*
move(std::size_t n, void* buf) override;
STObject&
operator[](std::size_t j);
@@ -134,6 +128,14 @@ public:
bool
isDefault() const override;
private:
STBase*
copy(std::size_t n, void* buf) const override;
STBase*
move(std::size_t n, void* buf) override;
friend class detail::STVar;
};
inline STObject&

View File

@@ -33,6 +33,10 @@ namespace ripple {
enum class JsonOptions { none = 0, include_date = 1 };
namespace detail {
class STVar;
}
// VFALCO TODO fix this restriction on copy assignment.
//
// CAUTION: Do not create a vector (or similar container) of any object derived
@@ -77,11 +81,6 @@ public:
bool
operator!=(const STBase& t) const;
virtual STBase*
copy(std::size_t n, void* buf) const;
virtual STBase*
move(std::size_t n, void* buf);
template <class D>
D&
downcast();
@@ -126,6 +125,14 @@ protected:
template <class T>
static STBase*
emplace(std::size_t n, void* buf, T&& val);
private:
virtual STBase*
copy(std::size_t n, void* buf) const;
virtual STBase*
move(std::size_t n, void* buf);
friend class detail::STVar;
};
//------------------------------------------------------------------------------

View File

@@ -42,12 +42,6 @@ public:
STBitString(SField const& n, const value_type& v);
STBitString(SerialIter& sit, SField const& name);
STBase*
copy(std::size_t n, void* buf) const override;
STBase*
move(std::size_t n, void* buf) override;
SerializedTypeID
getSType() const override;
@@ -71,6 +65,14 @@ public:
value() const;
operator value_type() const;
private:
STBase*
copy(std::size_t n, void* buf) const override;
STBase*
move(std::size_t n, void* buf) override;
friend class detail::STVar;
};
using STHash128 = STBitString<128>;

View File

@@ -45,12 +45,6 @@ public:
STBlob(SField const& n);
STBlob(SerialIter&, SField const& name = sfGeneric);
STBase*
copy(std::size_t n, void* buf) const override;
STBase*
move(std::size_t n, void* buf) override;
std::size_t
size() const;
@@ -83,6 +77,14 @@ public:
void
setValue(Buffer&& b);
private:
STBase*
copy(std::size_t n, void* buf) const override;
STBase*
move(std::size_t n, void* buf) override;
friend class detail::STVar;
};
inline STBlob::STBlob(STBlob const& rhs)

View File

@@ -38,12 +38,6 @@ public:
STInteger(SField const& n, Integer v = 0);
STInteger(SerialIter& sit, SField const& name);
STBase*
copy(std::size_t n, void* buf) const override;
STBase*
move(std::size_t n, void* buf) override;
SerializedTypeID
getSType() const override;
@@ -71,6 +65,14 @@ public:
setValue(Integer v);
operator Integer() const;
private:
STBase*
copy(std::size_t n, void* buf) const override;
STBase*
move(std::size_t n, void* buf) override;
friend class detail::STVar;
};
using STUInt8 = STInteger<unsigned char>;

View File

@@ -43,12 +43,6 @@ public:
STLedgerEntry(SerialIter&& sit, uint256 const& index);
STLedgerEntry(STObject const& object, uint256 const& index);
STBase*
copy(std::size_t n, void* buf) const override;
STBase*
move(std::size_t n, void* buf) override;
SerializedTypeID
getSType() const override;
@@ -90,6 +84,13 @@ private:
setSLEType();
friend Invariants_test; // this test wants access to the private type_
STBase*
copy(std::size_t n, void* buf) const override;
STBase*
move(std::size_t n, void* buf) override;
friend class detail::STVar;
};
using SLE = STLedgerEntry;

View File

@@ -92,12 +92,6 @@ public:
STObject(SerialIter&& sit, SField const& name);
explicit STObject(SField const& name);
STBase*
copy(std::size_t n, void* buf) const override;
STBase*
move(std::size_t n, void* buf) override;
iterator
begin() const;
@@ -448,6 +442,13 @@ private:
template <typename T>
T&
peekField(SField const& field);
STBase*
copy(std::size_t n, void* buf) const override;
STBase*
move(std::size_t n, void* buf) override;
friend class detail::STVar;
};
//------------------------------------------------------------------------------

View File

@@ -182,12 +182,6 @@ public:
STPathSet(SField const& n);
STPathSet(SerialIter& sit, SField const& name);
STBase*
copy(std::size_t n, void* buf) const override;
STBase*
move(std::size_t n, void* buf) override;
void
add(Serializer& s) const override;
@@ -230,6 +224,14 @@ public:
template <typename... Args>
void
emplace_back(Args&&... args);
private:
STBase*
copy(std::size_t n, void* buf) const override;
STBase*
move(std::size_t n, void* buf) override;
friend class detail::STVar;
};
// ------------ STPathElement ------------

View File

@@ -66,12 +66,6 @@ public:
*/
STTx(TxType type, std::function<void(STObject&)> assembler);
STBase*
copy(std::size_t n, void* buf) const override;
STBase*
move(std::size_t n, void* buf) override;
// STObject functions.
SerializedTypeID
getSType() const override;
@@ -137,6 +131,13 @@ private:
Expected<void, std::string>
checkMultiSign(RequireFullyCanonicalSig requireCanonicalSig) const;
STBase*
copy(std::size_t n, void* buf) const override;
STBase*
move(std::size_t n, void* buf) override;
friend class detail::STVar;
};
bool

View File

@@ -94,12 +94,6 @@ public:
NodeID const& nodeID,
F&& f);
STBase*
copy(std::size_t n, void* buf) const override;
STBase*
move(std::size_t n, void* buf) override;
// Hash of the validated ledger
uint256
getLedgerHash() const;
@@ -150,6 +144,13 @@ public:
private:
static SOTemplate const&
validationFormat();
STBase*
copy(std::size_t n, void* buf) const override;
STBase*
move(std::size_t n, void* buf) override;
friend class detail::STVar;
};
template <class LookupNodeID>

View File

@@ -40,12 +40,6 @@ public:
STVector256(SField const& n, std::vector<uint256> const& vector);
STVector256(SerialIter& sit, SField const& name);
STBase*
copy(std::size_t n, void* buf) const override;
STBase*
move(std::size_t n, void* buf) override;
SerializedTypeID
getSType() const override;
@@ -116,6 +110,14 @@ public:
void
clear() noexcept;
private:
STBase*
copy(std::size_t n, void* buf) const override;
STBase*
move(std::size_t n, void* buf) override;
friend class detail::STVar;
};
inline STVector256::STVector256(SField const& n) : STBase(n)