Remove nested types SField::ref and SField::ptr...

* This silences a warning about a redundant cv-qualifier.
* This makes future coding mistakes about redundant
  cv-qualifiers much less likely.
* This makes the code easier to read.
This commit is contained in:
Howard Hinnant
2015-04-21 21:33:48 -04:00
committed by Tom Ritchford
parent 47482acf83
commit 100a76f0e8
30 changed files with 198 additions and 197 deletions

View File

@@ -31,7 +31,7 @@ namespace ripple {
// file-scope. The following 3 objects must have scope prior to
// the file-scope SFields.
static std::mutex SField_mutex;
static std::map<int, SField::ptr> knownCodeToField;
static std::map<int, SField const*> knownCodeToField;
static std::map<int, std::unique_ptr<SField const>> unknownCodeToField;
int SField::num = 0;
@@ -267,7 +267,8 @@ SField::SField (SerializedTypeID tid, int fv)
assert ((fv != 1) || ((tid != STI_ARRAY) && (tid != STI_OBJECT)));
}
SField::ref SField::getField (int code)
SField const&
SField::getField (int code)
{
auto it = knownCodeToField.find (code);
@@ -323,7 +324,7 @@ SField::ref SField::getField (int code)
}
}
int SField::compare (SField::ref f1, SField::ref f2)
int SField::compare (SField const& f1, SField const& f2)
{
// -1 = f1 comes before f2, 0 = illegal combination, 1 = f1 comes after f2
if ((f1.fieldCode <= 0) || (f2.fieldCode <= 0))
@@ -350,7 +351,8 @@ std::string SField::getName () const
std::to_string(fieldValue);
}
SField::ref SField::getField (std::string const& fieldName)
SField const&
SField::getField (std::string const& fieldName)
{
for (auto const & fieldPair : knownCodeToField)
{

View File

@@ -55,7 +55,7 @@ void SOTemplate::push_back (SOElement const& r)
mTypes.push_back (value_type (new SOElement (r)));
}
int SOTemplate::getIndex (SField::ref f) const
int SOTemplate::getIndex (SField const& f) const
{
// The mapping table should be large enough for any possible field
//

View File

@@ -22,7 +22,7 @@
namespace ripple {
STAccount::STAccount (SerialIter& sit, SField::ref name)
STAccount::STAccount (SerialIter& sit, SField const& name)
: STAccount(name, sit.getVLBuffer())
{
}
@@ -40,12 +40,12 @@ std::string STAccount::getText () const
}
STAccount*
STAccount::construct (SerialIter& u, SField::ref name)
STAccount::construct (SerialIter& u, SField const& name)
{
return new STAccount (name, u.getVLBuffer ());
}
STAccount::STAccount (SField::ref n, Account const& v)
STAccount::STAccount (SField const& n, Account const& v)
: STBlob (n, v.data (), v.size ())
{
}

View File

@@ -42,7 +42,7 @@ STAmount const saOne (noIssue(), 1u);
//------------------------------------------------------------------------------
STAmount::STAmount(SerialIter& sit, SField::ref name)
STAmount::STAmount(SerialIter& sit, SField const& name)
: STBase(name)
{
std::uint64_t value = sit.get64 ();
@@ -118,7 +118,7 @@ STAmount::STAmount(SerialIter& sit, SField::ref name)
canonicalize();
}
STAmount::STAmount (SField::ref name, Issue const& issue,
STAmount::STAmount (SField const& name, Issue const& issue,
mantissa_type mantissa, exponent_type exponent,
bool native, bool negative)
: STBase (name)
@@ -131,7 +131,7 @@ STAmount::STAmount (SField::ref name, Issue const& issue,
canonicalize();
}
STAmount::STAmount (SField::ref name, Issue const& issue,
STAmount::STAmount (SField const& name, Issue const& issue,
mantissa_type mantissa, exponent_type exponent,
bool native, bool negative, unchecked)
: STBase (name)
@@ -143,7 +143,7 @@ STAmount::STAmount (SField::ref name, Issue const& issue,
{
}
STAmount::STAmount (SField::ref name, std::int64_t mantissa)
STAmount::STAmount (SField const& name, std::int64_t mantissa)
: STBase (name)
, mOffset (0)
, mIsNative (true)
@@ -151,7 +151,7 @@ STAmount::STAmount (SField::ref name, std::int64_t mantissa)
set (mantissa);
}
STAmount::STAmount (SField::ref name,
STAmount::STAmount (SField const& name,
std::uint64_t mantissa, bool negative)
: STBase (name)
, mValue (mantissa)
@@ -161,7 +161,7 @@ STAmount::STAmount (SField::ref name,
{
}
STAmount::STAmount (SField::ref name, Issue const& issue,
STAmount::STAmount (SField const& name, Issue const& issue,
std::uint64_t mantissa, int exponent, bool negative)
: STBase (name)
, mIssue (issue)
@@ -214,13 +214,13 @@ STAmount::STAmount (Issue const& issue,
}
std::unique_ptr<STAmount>
STAmount::construct (SerialIter& sit, SField::ref name)
STAmount::construct (SerialIter& sit, SField const& name)
{
return std::make_unique<STAmount>(sit, name);
}
STAmount
STAmount::createFromInt64 (SField::ref name, std::int64_t value)
STAmount::createFromInt64 (SField const& name, std::int64_t value)
{
return value >= 0
? STAmount (name, static_cast<std::uint64_t> (value), false)
@@ -877,7 +877,7 @@ amountFromQuality (std::uint64_t rate)
}
STAmount
amountFromJson (SField::ref name, Json::Value const& v)
amountFromJson (SField const& name, Json::Value const& v)
{
STAmount::mantissa_type mantissa = 0;
STAmount::exponent_type exponent = 0;

View File

@@ -50,19 +50,19 @@ STArray::STArray (int n)
v_.reserve(n);
}
STArray::STArray (SField::ref f)
STArray::STArray (SField const& f)
: STBase (f)
{
v_.reserve(reserveSize);
}
STArray::STArray (SField::ref f, int n)
STArray::STArray (SField const& f, int n)
: STBase (f)
{
v_.reserve(n);
}
STArray::STArray (SerialIter& sit, SField::ref f)
STArray::STArray (SerialIter& sit, SField const& f)
: STBase(f)
{
while (!sit.empty ())
@@ -80,7 +80,7 @@ STArray::STArray (SerialIter& sit, SField::ref f)
throw std::runtime_error ("Illegal terminator in array");
}
SField::ref const fn = SField::getField (type, field);
auto const& fn = SField::getField (type, field);
if (fn.isInvalid ())
{

View File

@@ -30,7 +30,7 @@ STBase::STBase()
{
}
STBase::STBase (SField::ref n)
STBase::STBase (SField const& n)
: fName(&n)
{
assert(fName);
@@ -126,13 +126,13 @@ STBase::isDefault() const
}
void
STBase::setFName (SField::ref n)
STBase::setFName (SField const& n)
{
fName = &n;
assert (fName);
}
SField::ref
SField const&
STBase::getFName() const
{
return *fName;

View File

@@ -23,7 +23,7 @@
namespace ripple {
STBlob::STBlob (SerialIter& st, SField::ref name)
STBlob::STBlob (SerialIter& st, SField const& name)
: STBase (name)
, value_ (st.getVLBuffer ())
{

View File

@@ -29,7 +29,7 @@
namespace ripple {
template<>
STInteger<unsigned char>::STInteger(SerialIter& sit, SField::ref name)
STInteger<unsigned char>::STInteger(SerialIter& sit, SField const& name)
: STInteger(name, sit.get8())
{
}
@@ -77,7 +77,7 @@ STUInt8::getJson (int) const
//------------------------------------------------------------------------------
template<>
STInteger<std::uint16_t>::STInteger(SerialIter& sit, SField::ref name)
STInteger<std::uint16_t>::STInteger(SerialIter& sit, SField const& name)
: STInteger(name, sit.get16())
{
}
@@ -142,7 +142,7 @@ STUInt16::getJson (int) const
//------------------------------------------------------------------------------
template<>
STInteger<std::uint32_t>::STInteger(SerialIter& sit, SField::ref name)
STInteger<std::uint32_t>::STInteger(SerialIter& sit, SField const& name)
: STInteger(name, sit.get32())
{
}
@@ -171,7 +171,7 @@ STUInt32::getJson (int) const
//------------------------------------------------------------------------------
template<>
STInteger<std::uint64_t>::STInteger(SerialIter& sit, SField::ref name)
STInteger<std::uint64_t>::STInteger(SerialIter& sit, SField const& name)
: STInteger(name, sit.get64())
{
}

View File

@@ -47,7 +47,7 @@ STObject::STObject(STObject&& other)
{
}
STObject::STObject (SField::ref name)
STObject::STObject (SField const& name)
: STBase (name)
, mType (nullptr)
{
@@ -56,14 +56,14 @@ STObject::STObject (SField::ref name)
}
STObject::STObject (SOTemplate const& type,
SField::ref name)
SField const& name)
: STBase (name)
{
set (type);
}
STObject::STObject (SOTemplate const& type,
SerialIter & sit, SField::ref name)
SerialIter & sit, SField const& name)
: STBase (name)
{
v_.reserve(type.peek().size());
@@ -71,7 +71,7 @@ STObject::STObject (SOTemplate const& type,
setType (type);
}
STObject::STObject (SField::ref name,
STObject::STObject (SField const& name,
boost::ptr_vector<STBase>& data)
: STBase (name)
, mType (nullptr)
@@ -81,7 +81,7 @@ STObject::STObject (SField::ref name,
v_.emplace_back(b);
}
STObject::STObject (SerialIter& sit, SField::ref name)
STObject::STObject (SerialIter& sit, SField const& name)
: STBase(name)
, mType(nullptr)
{
@@ -178,7 +178,7 @@ bool STObject::isValidForType ()
return true;
}
bool STObject::isFieldAllowed (SField::ref field)
bool STObject::isFieldAllowed (SField const& field)
{
if (mType == nullptr)
return true;
@@ -217,7 +217,7 @@ bool STObject::set (SerialIter& sit, int depth)
{
// Figure out the field
//
SField::ref fn = SField::getField (type, field);
auto const& fn = SField::getField (type, field);
if (fn.isInvalid ())
{
@@ -380,7 +380,7 @@ uint256 STObject::getSigningHash (std::uint32_t prefix) const
return s.getSHA512Half ();
}
int STObject::getFieldIndex (SField::ref field) const
int STObject::getFieldIndex (SField const& field) const
{
if (mType != nullptr)
return mType->getIndex (field);
@@ -395,7 +395,7 @@ int STObject::getFieldIndex (SField::ref field) const
return -1;
}
const STBase& STObject::peekAtField (SField::ref field) const
const STBase& STObject::peekAtField (SField const& field) const
{
int index = getFieldIndex (field);
@@ -405,7 +405,7 @@ const STBase& STObject::peekAtField (SField::ref field) const
return peekAtIndex (index);
}
STBase& STObject::getField (SField::ref field)
STBase& STObject::getField (SField const& field)
{
int index = getFieldIndex (field);
@@ -415,12 +415,13 @@ STBase& STObject::getField (SField::ref field)
return getIndex (index);
}
SField::ref STObject::getFieldSType (int index) const
SField const&
STObject::getFieldSType (int index) const
{
return v_[index]->getFName ();
}
const STBase* STObject::peekAtPField (SField::ref field) const
const STBase* STObject::peekAtPField (SField const& field) const
{
int index = getFieldIndex (field);
@@ -430,7 +431,7 @@ const STBase* STObject::peekAtPField (SField::ref field) const
return peekAtPIndex (index);
}
STBase* STObject::getPField (SField::ref field, bool createOkay)
STBase* STObject::getPField (SField const& field, bool createOkay)
{
int index = getFieldIndex (field);
@@ -445,7 +446,7 @@ STBase* STObject::getPField (SField::ref field, bool createOkay)
return getPIndex (index);
}
bool STObject::isFieldPresent (SField::ref field) const
bool STObject::isFieldPresent (SField const& field) const
{
int index = getFieldIndex (field);
@@ -455,7 +456,7 @@ bool STObject::isFieldPresent (SField::ref field) const
return peekAtIndex (index).getSType () != STI_NOTPRESENT;
}
STObject& STObject::peekFieldObject (SField::ref field)
STObject& STObject::peekFieldObject (SField const& field)
{
STBase* rf = getPField (field, true);
@@ -510,7 +511,7 @@ std::uint32_t STObject::getFlags (void) const
return t->getValue ();
}
STBase* STObject::makeFieldPresent (SField::ref field)
STBase* STObject::makeFieldPresent (SField const& field)
{
int index = getFieldIndex (field);
@@ -532,7 +533,7 @@ STBase* STObject::makeFieldPresent (SField::ref field)
return getPIndex (index);
}
void STObject::makeFieldAbsent (SField::ref field)
void STObject::makeFieldAbsent (SField const& field)
{
int index = getFieldIndex (field);
@@ -547,7 +548,7 @@ void STObject::makeFieldAbsent (SField::ref field)
detail::nonPresentObject, f.getFName());
}
bool STObject::delField (SField::ref field)
bool STObject::delField (SField const& field)
{
int index = getFieldIndex (field);
@@ -563,7 +564,7 @@ void STObject::delField (int index)
v_.erase (v_.begin () + index);
}
std::string STObject::getFieldString (SField::ref field) const
std::string STObject::getFieldString (SField const& field) const
{
const STBase* rf = peekAtPField (field);
@@ -572,42 +573,42 @@ std::string STObject::getFieldString (SField::ref field) const
return rf->getText ();
}
unsigned char STObject::getFieldU8 (SField::ref field) const
unsigned char STObject::getFieldU8 (SField const& field) const
{
return getFieldByValue <STUInt8> (field);
}
std::uint16_t STObject::getFieldU16 (SField::ref field) const
std::uint16_t STObject::getFieldU16 (SField const& field) const
{
return getFieldByValue <STUInt16> (field);
}
std::uint32_t STObject::getFieldU32 (SField::ref field) const
std::uint32_t STObject::getFieldU32 (SField const& field) const
{
return getFieldByValue <STUInt32> (field);
}
std::uint64_t STObject::getFieldU64 (SField::ref field) const
std::uint64_t STObject::getFieldU64 (SField const& field) const
{
return getFieldByValue <STUInt64> (field);
}
uint128 STObject::getFieldH128 (SField::ref field) const
uint128 STObject::getFieldH128 (SField const& field) const
{
return getFieldByValue <STHash128> (field);
}
uint160 STObject::getFieldH160 (SField::ref field) const
uint160 STObject::getFieldH160 (SField const& field) const
{
return getFieldByValue <STHash160> (field);
}
uint256 STObject::getFieldH256 (SField::ref field) const
uint256 STObject::getFieldH256 (SField const& field) const
{
return getFieldByValue <STHash256> (field);
}
RippleAddress STObject::getFieldAccount (SField::ref field) const
RippleAddress STObject::getFieldAccount (SField const& field) const
{
const STBase* rf = peekAtPField (field);
@@ -626,7 +627,7 @@ RippleAddress STObject::getFieldAccount (SField::ref field) const
return cf->getValueNCA ();
}
Account STObject::getFieldAccount160 (SField::ref field) const
Account STObject::getFieldAccount160 (SField const& field) const
{
auto rf = peekAtPField (field);
if (!rf)
@@ -646,32 +647,32 @@ Account STObject::getFieldAccount160 (SField::ref field) const
return account;
}
Blob STObject::getFieldVL (SField::ref field) const
Blob STObject::getFieldVL (SField const& field) const
{
STBlob empty;
STBlob const& b = getFieldByConstRef <STBlob> (field, empty);
return Blob (b.data (), b.data () + b.size ());
}
STAmount const& STObject::getFieldAmount (SField::ref field) const
STAmount const& STObject::getFieldAmount (SField const& field) const
{
static STAmount const empty{};
return getFieldByConstRef <STAmount> (field, empty);
}
const STArray& STObject::getFieldArray (SField::ref field) const
const STArray& STObject::getFieldArray (SField const& field) const
{
static STArray const empty{};
return getFieldByConstRef <STArray> (field, empty);
}
STPathSet const& STObject::getFieldPathSet (SField::ref field) const
STPathSet const& STObject::getFieldPathSet (SField const& field) const
{
static STPathSet const empty{};
return getFieldByConstRef <STPathSet> (field, empty);
}
const STVector256& STObject::getFieldV256 (SField::ref field) const
const STVector256& STObject::getFieldV256 (SField const& field) const
{
static STVector256 const empty{};
return getFieldByConstRef <STVector256> (field, empty);
@@ -695,42 +696,42 @@ STObject::set (std::unique_ptr<STBase> v)
}
}
void STObject::setFieldU8 (SField::ref field, unsigned char v)
void STObject::setFieldU8 (SField const& field, unsigned char v)
{
setFieldUsingSetValue <STUInt8> (field, v);
}
void STObject::setFieldU16 (SField::ref field, std::uint16_t v)
void STObject::setFieldU16 (SField const& field, std::uint16_t v)
{
setFieldUsingSetValue <STUInt16> (field, v);
}
void STObject::setFieldU32 (SField::ref field, std::uint32_t v)
void STObject::setFieldU32 (SField const& field, std::uint32_t v)
{
setFieldUsingSetValue <STUInt32> (field, v);
}
void STObject::setFieldU64 (SField::ref field, std::uint64_t v)
void STObject::setFieldU64 (SField const& field, std::uint64_t v)
{
setFieldUsingSetValue <STUInt64> (field, v);
}
void STObject::setFieldH128 (SField::ref field, uint128 const& v)
void STObject::setFieldH128 (SField const& field, uint128 const& v)
{
setFieldUsingSetValue <STHash128> (field, v);
}
void STObject::setFieldH256 (SField::ref field, uint256 const& v)
void STObject::setFieldH256 (SField const& field, uint256 const& v)
{
setFieldUsingSetValue <STHash256> (field, v);
}
void STObject::setFieldV256 (SField::ref field, STVector256 const& v)
void STObject::setFieldV256 (SField const& field, STVector256 const& v)
{
setFieldUsingSetValue <STVector256> (field, v);
}
void STObject::setFieldAccount (SField::ref field, Account const& v)
void STObject::setFieldAccount (SField const& field, Account const& v)
{
STBase* rf = getPField (field, true);
@@ -748,23 +749,23 @@ void STObject::setFieldAccount (SField::ref field, Account const& v)
cf->setValueH160 (v);
}
void STObject::setFieldVL (SField::ref field, Blob const& v)
void STObject::setFieldVL (SField const& field, Blob const& v)
{
setFieldUsingSetValue <STBlob>
(field, Buffer(v.data (), v.size ()));
}
void STObject::setFieldAmount (SField::ref field, STAmount const& v)
void STObject::setFieldAmount (SField const& field, STAmount const& v)
{
setFieldUsingAssignment (field, v);
}
void STObject::setFieldPathSet (SField::ref field, STPathSet const& v)
void STObject::setFieldPathSet (SField const& field, STPathSet const& v)
{
setFieldUsingAssignment (field, v);
}
void STObject::setFieldArray (SField::ref field, STArray const& v)
void STObject::setFieldArray (SField const& field, STArray const& v)
{
setFieldUsingAssignment (field, v);
}

View File

@@ -143,13 +143,13 @@ static Json::Value singleton_expected (std::string const& object,
static std::unique_ptr <STBase> parseLeaf (
std::string const& json_name,
std::string const& fieldName,
SField::ptr name,
SField const* name,
Json::Value const& value,
Json::Value& error)
{
std::unique_ptr <STBase> ret;
SField::ref field = SField::getField (fieldName);
auto const& field = SField::getField (fieldName);
if (field == sfInvalid)
{
@@ -664,7 +664,7 @@ static const int maxDepth = 64;
static bool parseArray (
std::string const& json_name,
Json::Value const& json,
SField::ref inName,
SField const& inName,
int depth,
std::unique_ptr <STArray>& sub_array,
Json::Value& error);
@@ -674,7 +674,7 @@ static bool parseArray (
static bool parseObject (
std::string const& json_name,
Json::Value const& json,
SField::ref inName,
SField const& inName,
int depth,
std::unique_ptr <STObject>& sub_object,
Json::Value& error)
@@ -691,7 +691,7 @@ static bool parseObject (
return false;
}
SField::ptr name (&inName);
auto name (&inName);
boost::ptr_vector<STBase> data;
Json::Value::Members members (json.getMemberNames ());
@@ -700,7 +700,7 @@ static bool parseObject (
{
Json::Value const& value = json [fieldName];
SField::ref field = SField::getField (fieldName);
auto const& field = SField::getField (fieldName);
if (field == sfInvalid)
{
@@ -781,7 +781,7 @@ static bool parseObject (
static bool parseArray (
std::string const& json_name,
Json::Value const& json,
SField::ref inName,
SField const& inName,
int depth,
std::unique_ptr <STArray>& sub_array,
Json::Value& error)
@@ -817,7 +817,7 @@ static bool parseArray (
// first/only key in an object without copying all keys into
// a vector
std::string const objectName (json[i].getMemberNames()[0]);;
SField::ref nameField (SField::getField(objectName));
auto const& nameField (SField::getField(objectName));
if (nameField == sfInvalid)
{

View File

@@ -50,7 +50,7 @@ STPathElement::get_hash (STPathElement const& element)
return (hash_account ^ hash_currency ^ hash_issuer);
}
STPathSet::STPathSet (SerialIter& sit, SField::ref name)
STPathSet::STPathSet (SerialIter& sit, SField const& name)
: STBase(name)
{
std::vector<STPathElement> path;

View File

@@ -111,17 +111,17 @@ STVar::operator= (STVar&& rhs)
return *this;
}
STVar::STVar (defaultObject_t, SField::ref name)
STVar::STVar (defaultObject_t, SField const& name)
: STVar(name.fieldType, name)
{
}
STVar::STVar (nonPresentObject_t, SField::ref name)
STVar::STVar (nonPresentObject_t, SField const& name)
: STVar(STI_NOTPRESENT, name)
{
}
STVar::STVar (SerialIter& sit, SField::ref name)
STVar::STVar (SerialIter& sit, SField const& name)
{
switch (name.fieldType)
{
@@ -145,7 +145,7 @@ STVar::STVar (SerialIter& sit, SField::ref name)
}
}
STVar::STVar (SerializedTypeID id, SField::ref name)
STVar::STVar (SerializedTypeID id, SField const& name)
{
assert ((id == STI_NOTPRESENT) || (id == name.fieldType));
switch (id)

View File

@@ -77,9 +77,9 @@ public:
p_ = t.copy(sizeof(d_), &d_);
}
STVar (defaultObject_t, SField::ref name);
STVar (nonPresentObject_t, SField::ref name);
STVar (SerialIter& sit, SField::ref name);
STVar (defaultObject_t, SField const& name);
STVar (nonPresentObject_t, SField const& name);
STVar (SerialIter& sit, SField const& name);
STBase& get() { return *p_; }
STBase& operator*() { return get(); }
@@ -89,7 +89,7 @@ public:
STBase const* operator->() const { return &get(); }
private:
STVar (SerializedTypeID id, SField::ref name);
STVar (SerializedTypeID id, SField const& name);
void destroy();

View File

@@ -25,7 +25,7 @@
namespace ripple {
STVector256::STVector256(SerialIter& sit, SField::ref name)
STVector256::STVector256(SerialIter& sit, SField const& name)
: STBase(name)
{
Blob data = sit.getVL ();