Modernize code:

* Clean STBase-derived class creation interfaces
* Annotate overriden STBase virtual functions
* Optimize path deserialization
* Prefer range-based for
* Prefer std::unique_ptr
* Remove BOOST_FOREACH
This commit is contained in:
Nik Bougalis
2014-12-31 22:02:14 -08:00
parent e742da73bd
commit 47593730d6
43 changed files with 638 additions and 547 deletions

View File

@@ -29,19 +29,22 @@
namespace ripple {
template <>
SerializedTypeID STUInt8::getSType () const
SerializedTypeID
STUInt8::getSType () const
{
return STI_UINT8;
}
template <>
STUInt8* STUInt8::construct (SerializerIterator& u, SField::ref name)
std::unique_ptr<STBase>
STUInt8::deserialize (SerializerIterator& sit, SField::ref name)
{
return new STUInt8 (name, u.get8 ());
return std::make_unique <STUInt8> (name, sit.get8 ());
}
template <>
std::string STUInt8::getText () const
std::string
STUInt8::getText () const
{
if (getFName () == sfTransactionResult)
{
@@ -55,7 +58,8 @@ std::string STUInt8::getText () const
}
template <>
Json::Value STUInt8::getJson (int) const
Json::Value
STUInt8::getJson (int) const
{
if (getFName () == sfTransactionResult)
{
@@ -74,19 +78,22 @@ Json::Value STUInt8::getJson (int) const
//------------------------------------------------------------------------------
template <>
SerializedTypeID STUInt16::getSType () const
SerializedTypeID
STUInt16::getSType () const
{
return STI_UINT16;
}
template <>
STUInt16* STUInt16::construct (SerializerIterator& u, SField::ref name)
std::unique_ptr<STBase>
STUInt16::deserialize (SerializerIterator& sit, SField::ref name)
{
return new STUInt16 (name, u.get16 ());
return std::make_unique <STUInt16> (name, sit.get16 ());
}
template <>
std::string STUInt16::getText () const
std::string
STUInt16::getText () const
{
if (getFName () == sfLedgerEntryType)
{
@@ -99,8 +106,8 @@ std::string STUInt16::getText () const
if (getFName () == sfTransactionType)
{
TxFormats::Item const* const item =
TxFormats::getInstance().findByType (static_cast <TxType> (value_));
auto item =TxFormats::getInstance().findByType (
static_cast <TxType> (value_));
if (item != nullptr)
return item->getName ();
@@ -110,12 +117,13 @@ std::string STUInt16::getText () const
}
template <>
Json::Value STUInt16::getJson (int) const
Json::Value
STUInt16::getJson (int) const
{
if (getFName () == sfLedgerEntryType)
{
LedgerFormats::Item const* const item =
LedgerFormats::getInstance ().findByType (static_cast <LedgerEntryType> (value_));
auto item = LedgerFormats::getInstance ().findByType (
static_cast <LedgerEntryType> (value_));
if (item != nullptr)
return item->getName ();
@@ -123,8 +131,8 @@ Json::Value STUInt16::getJson (int) const
if (getFName () == sfTransactionType)
{
TxFormats::Item const* const item =
TxFormats::getInstance().findByType (static_cast <TxType> (value_));
auto item = TxFormats::getInstance().findByType (
static_cast <TxType> (value_));
if (item != nullptr)
return item->getName ();
@@ -136,49 +144,59 @@ Json::Value STUInt16::getJson (int) const
//------------------------------------------------------------------------------
template <>
SerializedTypeID STUInt32::getSType () const
SerializedTypeID
STUInt32::getSType () const
{
return STI_UINT32;
}
template <>
STUInt32* STUInt32::construct (SerializerIterator& u, SField::ref name)
std::unique_ptr<STBase>
STUInt32::deserialize (SerializerIterator& sit, SField::ref name)
{
return new STUInt32 (name, u.get32 ());
return std::make_unique <STUInt32> (name, sit.get32 ());
}
template <>
std::string STUInt32::getText () const
std::string
STUInt32::getText () const
{
return beast::lexicalCastThrow <std::string> (value_);
}
template <>
Json::Value STUInt32::getJson (int) const
Json::Value
STUInt32::getJson (int) const
{
return value_;
}
//------------------------------------------------------------------------------
template <>
SerializedTypeID STUInt64::getSType () const
SerializedTypeID
STUInt64::getSType () const
{
return STI_UINT64;
}
template <>
STUInt64* STUInt64::construct (SerializerIterator& u, SField::ref name)
std::unique_ptr<STBase>
STUInt64::deserialize (SerializerIterator& sit, SField::ref name)
{
return new STUInt64 (name, u.get64 ());
return std::make_unique <STUInt64> (name, sit.get64 ());
}
template <>
std::string STUInt64::getText () const
std::string
STUInt64::getText () const
{
return beast::lexicalCastThrow <std::string> (value_);
}
template <>
Json::Value STUInt64::getJson (int) const
Json::Value
STUInt64::getJson (int) const
{
return strHex (value_);
}