From 47593730d684ba88f238bf67d9d0bd0f11166f76 Mon Sep 17 00:00:00 2001 From: Nik Bougalis Date: Wed, 31 Dec 2014 22:02:14 -0800 Subject: [PATCH] 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 --- Builds/VisualStudio2013/RippleD.vcxproj | 0 .../VisualStudio2013/RippleD.vcxproj.filters | 0 src/ripple/app/book/impl/OfferStream.cpp | 7 +- src/ripple/app/ledger/AcceptedLedgerTx.cpp | 3 +- src/ripple/app/ledger/InboundLedger.cpp | 13 +- src/ripple/app/ledger/Ledger.cpp | 16 +- src/ripple/app/ledger/LedgerEntrySet.cpp | 51 +++---- src/ripple/app/misc/AmendmentTableImpl.cpp | 16 +- src/ripple/app/misc/HashRouter.cpp | 5 +- src/ripple/app/misc/NetworkOPs.cpp | 12 +- src/ripple/app/paths/PathRequests.cpp | 3 +- src/ripple/app/peers/UniqueNodeList.cpp | 68 ++++----- src/ripple/app/tx/TransactionAcquire.cpp | 7 +- src/ripple/app/tx/TransactionEngine.cpp | 15 +- src/ripple/app/tx/TransactionMeta.cpp | 52 +++---- src/ripple/basics/StringUtilities.h | 15 -- src/ripple/basics/impl/RangeSet.cpp | 6 +- src/ripple/core/impl/Config.cpp | 5 +- src/ripple/crypto/impl/RFC1751.cpp | 3 +- src/ripple/net/impl/SNTPClient.cpp | 5 +- src/ripple/protocol/STAccount.h | 15 +- src/ripple/protocol/STAmount.h | 17 ++- src/ripple/protocol/STArray.h | 51 ++++--- src/ripple/protocol/STBase.h | 20 +-- src/ripple/protocol/STBitString.h | 109 ++++++++------ src/ripple/protocol/STBlob.h | 87 ++++++----- src/ripple/protocol/STInteger.h | 69 +++++---- src/ripple/protocol/STLedgerEntry.h | 17 ++- src/ripple/protocol/STObject.h | 9 +- src/ripple/protocol/STPathSet.h | 140 +++++++++--------- src/ripple/protocol/STTx.h | 15 +- src/ripple/protocol/STValidation.h | 2 +- src/ripple/protocol/STVector256.h | 113 +++++++++----- src/ripple/protocol/impl/STAmount.cpp | 19 +-- src/ripple/protocol/impl/STBase.cpp | 8 +- src/ripple/protocol/impl/STBlob.cpp | 11 +- src/ripple/protocol/impl/STInteger.cpp | 70 +++++---- src/ripple/protocol/impl/STObject.cpp | 5 +- src/ripple/protocol/impl/STParsedJSON.cpp | 4 +- src/ripple/protocol/impl/STPathSet.cpp | 60 ++++++-- src/ripple/protocol/impl/STVector256.cpp | 37 +++-- src/ripple/rpc/handlers/GetCounts.cpp | 3 +- src/ripple/rpc/handlers/LogLevel.cpp | 2 +- 43 files changed, 638 insertions(+), 547 deletions(-) mode change 100755 => 100644 Builds/VisualStudio2013/RippleD.vcxproj mode change 100755 => 100644 Builds/VisualStudio2013/RippleD.vcxproj.filters diff --git a/Builds/VisualStudio2013/RippleD.vcxproj b/Builds/VisualStudio2013/RippleD.vcxproj old mode 100755 new mode 100644 diff --git a/Builds/VisualStudio2013/RippleD.vcxproj.filters b/Builds/VisualStudio2013/RippleD.vcxproj.filters old mode 100755 new mode 100644 diff --git a/src/ripple/app/book/impl/OfferStream.cpp b/src/ripple/app/book/impl/OfferStream.cpp index 9af92f7c0a..0c5cc87a4e 100644 --- a/src/ripple/app/book/impl/OfferStream.cpp +++ b/src/ripple/app/book/impl/OfferStream.cpp @@ -54,10 +54,9 @@ OfferStream::erase (LedgerView& view) } auto v (p->getFieldV256 (sfIndexes)); - auto& x (v.peekValue()); - auto it (std::find (x.begin(), x.end(), m_tip.index())); + auto it (std::find (v.begin(), v.end(), m_tip.index())); - if (it == x.end()) + if (it == v.end()) { if (m_journal.error) m_journal.error << "Missing offer " << m_tip.index() << @@ -65,7 +64,7 @@ OfferStream::erase (LedgerView& view) return; } - x.erase (it); + v.erase (it); p->setFieldV256 (sfIndexes, v); view.entryModify (p); diff --git a/src/ripple/app/ledger/AcceptedLedgerTx.cpp b/src/ripple/app/ledger/AcceptedLedgerTx.cpp index a3ee78f4d5..4ff61016fb 100644 --- a/src/ripple/app/ledger/AcceptedLedgerTx.cpp +++ b/src/ripple/app/ledger/AcceptedLedgerTx.cpp @@ -22,7 +22,6 @@ #include #include #include -#include namespace ripple { @@ -84,7 +83,7 @@ void AcceptedLedgerTx::buildJson () if (!mAffected.empty ()) { Json::Value& affected = (mJson[jss::affected] = Json::arrayValue); - BOOST_FOREACH (const RippleAddress & ra, mAffected) + for (auto const& ra : mAffected) { affected.append (ra.humanAccountID ()); } diff --git a/src/ripple/app/ledger/InboundLedger.cpp b/src/ripple/app/ledger/InboundLedger.cpp index 6f5788b76d..1e241b00b9 100644 --- a/src/ripple/app/ledger/InboundLedger.cpp +++ b/src/ripple/app/ledger/InboundLedger.cpp @@ -32,7 +32,6 @@ #include #include #include -#include namespace ripple { @@ -604,9 +603,9 @@ void InboundLedger::trigger (Peer::ptr const& peer) if (!nodeIDs.empty ()) { tmGL.set_itype (protocol::liAS_NODE); - BOOST_FOREACH (SHAMapNodeID const& it, nodeIDs) + for (auto const& id : nodeIDs) { - * (tmGL.add_nodeids ()) = it.getRawString (); + * (tmGL.add_nodeids ()) = id.getRawString (); } if (m_journal.trace) m_journal.trace << "Sending AS node " << nodeIDs.size () << @@ -675,9 +674,9 @@ void InboundLedger::trigger (Peer::ptr const& peer) if (!nodeIDs.empty ()) { tmGL.set_itype (protocol::liTX_NODE); - BOOST_FOREACH (SHAMapNodeID const& it, nodeIDs) + for (auto const& id : nodeIDs) { - * (tmGL.add_nodeids ()) = it.getRawString (); + * (tmGL.add_nodeids ()) = id.getRawString (); } if (m_journal.trace) m_journal.trace << "Sending TX node " << nodeIDs.size () << @@ -716,7 +715,7 @@ void InboundLedger::filterNodes (std::vector& nodeIDs, int dupCount = 0; - BOOST_FOREACH(SHAMapNodeID const& nodeID, nodeIDs) + for(auto const& nodeID : nodeIDs) { if (recentNodes.count (nodeID) != 0) { @@ -769,7 +768,7 @@ void InboundLedger::filterNodes (std::vector& nodeIDs, nodeHashes.resize (max); } - BOOST_FOREACH (const SHAMapNodeID & n, nodeIDs) + for (auto const& n : nodeIDs) { recentNodes.insert (n); } diff --git a/src/ripple/app/ledger/Ledger.cpp b/src/ripple/app/ledger/Ledger.cpp index b532ca7bb0..ab7e3804ea 100644 --- a/src/ripple/app/ledger/Ledger.cpp +++ b/src/ripple/app/ledger/Ledger.cpp @@ -1264,7 +1264,7 @@ void Ledger::visitAccountItems ( if (!ownerDir || (ownerDir->getType () != ltDIR_NODE)) return; - for (auto const& node : ownerDir->getFieldV256 (sfIndexes).peekValue ()) + for (auto const& node : ownerDir->getFieldV256 (sfIndexes)) { func (getSLEi (node)); } @@ -1621,13 +1621,13 @@ Ledger::LedgerHashes Ledger::getLedgerHashes () const std::vector Ledger::getLedgerAmendments () const { - std::vector usAmendments; + std::vector amendments; SLE::pointer sleAmendments = getSLEi (getLedgerAmendmentIndex ()); if (sleAmendments) - usAmendments = sleAmendments->getFieldV256 (sfAmendments).peekValue (); + amendments = static_cast (sleAmendments->getFieldV256 (sfAmendments)); - return usAmendments; + return amendments; } bool Ledger::walkLedger () const @@ -1701,7 +1701,7 @@ void Ledger::updateSkipList () if (!skipList) skipList = std::make_shared (ltLEDGER_HASHES, hash); else - hashes = skipList->getFieldV256 (sfHashes).peekValue (); + hashes = static_cast (skipList->getFieldV256 (sfHashes)); assert (hashes.size () <= 256); hashes.push_back (mParentHash); @@ -1722,13 +1722,9 @@ void Ledger::updateSkipList () std::vector hashes; if (!skipList) - { skipList = std::make_shared (ltLEDGER_HASHES, hash); - } else - { - hashes = skipList->getFieldV256 (sfHashes).peekValue (); - } + hashes = static_cast(skipList->getFieldV256 (sfHashes)); assert (hashes.size () <= 256); diff --git a/src/ripple/app/ledger/LedgerEntrySet.cpp b/src/ripple/app/ledger/LedgerEntrySet.cpp index f69655e206..72a2074f3a 100644 --- a/src/ripple/app/ledger/LedgerEntrySet.cpp +++ b/src/ripple/app/ledger/LedgerEntrySet.cpp @@ -599,7 +599,7 @@ TER LedgerEntrySet::dirCount (uint256 const& uRootIndex, std::uint32_t& uCount) if (sleNode) { - uCount += sleNode->getFieldV256 (sfIndexes).peekValue ().size (); + uCount += sleNode->getFieldV256 (sfIndexes).size (); uNodeDir = sleNode->getFieldU64 (sfIndexNext); // Get next node. } @@ -626,7 +626,7 @@ bool LedgerEntrySet::dirIsEmpty (uint256 const& uRootIndex) if (!sleNode) return true; - if (!sleNode->getFieldV256 (sfIndexes).peekValue ().empty ()) + if (!sleNode->getFieldV256 (sfIndexes).empty ()) return false; // If there's another page, it must be non-empty @@ -681,7 +681,7 @@ TER LedgerEntrySet::dirAdd ( svIndexes = sleNode->getFieldV256 (sfIndexes); - if (DIR_NODE_MAX != svIndexes.peekValue ().size ()) + if (DIR_NODE_MAX != svIndexes.size ()) { // Add to current node. entryModify (sleNode); @@ -714,7 +714,7 @@ TER LedgerEntrySet::dirAdd ( } } - svIndexes.peekValue ().push_back (uLedgerIndex); // Append entry. + svIndexes.push_back (uLedgerIndex); // Append entry. sleNode->setFieldV256 (sfIndexes, svIndexes); // Save entry. WriteLog (lsTRACE, LedgerEntrySet) << @@ -723,7 +723,6 @@ TER LedgerEntrySet::dirAdd ( "dirAdd: appending: Entry: " << to_string (uLedgerIndex); WriteLog (lsTRACE, LedgerEntrySet) << "dirAdd: appending: Node: " << strHex (uNodeDir); - // WriteLog (lsINFO, LedgerEntrySet) << "dirAdd: appending: PREV: " << svIndexes.peekValue()[0].ToString(); return tesSUCCESS; } @@ -764,56 +763,51 @@ TER LedgerEntrySet::dirDelete ( } } - STVector256 svIndexes = sleNode->getFieldV256 (sfIndexes); - std::vector& vuiIndexes = svIndexes.peekValue (); + STVector256 svIndexes = sleNode->getFieldV256 (sfIndexes); - auto it = std::find (vuiIndexes.begin (), vuiIndexes.end (), uLedgerIndex); + auto it = std::find (svIndexes.begin (), svIndexes.end (), uLedgerIndex); - if (vuiIndexes.end () == it) + if (svIndexes.end () == it) { if (!bSoft) { assert (false); - WriteLog (lsWARNING, LedgerEntrySet) << "dirDelete: no such entry"; - return tefBAD_LEDGER; } - else if (uNodeDir < 20) + + if (uNodeDir < 20) { // Go the extra mile. Even if entry not in node, try the next node. - return dirDelete (bKeepRoot, uNodeDir + 1, uRootIndex, uLedgerIndex, bStable, true); } - else - { - return tefBAD_LEDGER; - } + + return tefBAD_LEDGER; } // Remove the element. - if (vuiIndexes.size () > 1) + if (svIndexes.size () > 1) { if (bStable) { - vuiIndexes.erase (it); + svIndexes.erase (it); } else { - *it = vuiIndexes[vuiIndexes.size () - 1]; - vuiIndexes.resize (vuiIndexes.size () - 1); + *it = svIndexes[svIndexes.size () - 1]; + svIndexes.resize (svIndexes.size () - 1); } } else { - vuiIndexes.clear (); + svIndexes.clear (); } sleNode->setFieldV256 (sfIndexes, svIndexes); entryModify (sleNode); - if (vuiIndexes.empty ()) + if (svIndexes.empty ()) { // May be able to delete nodes. std::uint64_t uNodePrevious = sleNode->getFieldU64 (sfIndexPrevious); @@ -844,7 +838,7 @@ TER LedgerEntrySet::dirDelete ( assert (sleLast); - if (sleLast->getFieldV256 (sfIndexes).peekValue ().empty ()) + if (sleLast->getFieldV256 (sfIndexes).empty ()) { // Both nodes are empty. @@ -908,7 +902,7 @@ TER LedgerEntrySet::dirDelete ( assert (sleRoot); - if (sleRoot->getFieldV256 (sfIndexes).peekValue ().empty ()) + if (sleRoot->getFieldV256 (sfIndexes).empty ()) { // Both nodes are empty. @@ -950,11 +944,10 @@ bool LedgerEntrySet::dirNext ( uint256& uEntryIndex) // <-- The entry, if available. Otherwise, zero. { STVector256 svIndexes = sleNode->getFieldV256 (sfIndexes); - std::vector& vuiIndexes = svIndexes.peekValue (); - assert (uDirEntry <= vuiIndexes.size ()); + assert (uDirEntry <= svIndexes.size ()); - if (uDirEntry >= vuiIndexes.size ()) + if (uDirEntry >= svIndexes.size ()) { std::uint64_t uNodeNext = sleNode->getFieldU64 (sfIndexNext); @@ -983,7 +976,7 @@ bool LedgerEntrySet::dirNext ( } } - uEntryIndex = vuiIndexes[uDirEntry++]; + uEntryIndex = svIndexes[uDirEntry++]; WriteLog (lsTRACE, LedgerEntrySet) << "dirNext:" << " uDirEntry=" << uDirEntry << diff --git a/src/ripple/app/misc/AmendmentTableImpl.cpp b/src/ripple/app/misc/AmendmentTableImpl.cpp index 8125cc1e97..e0a0f8476e 100644 --- a/src/ripple/app/misc/AmendmentTableImpl.cpp +++ b/src/ripple/app/misc/AmendmentTableImpl.cpp @@ -24,6 +24,7 @@ #include #include #include +#include namespace ripple { /** Track the list of "amendments" @@ -498,16 +499,19 @@ void AmendmentTableImpl::doValidation (Ledger::ref lastClosedLedger, STObject& baseValidation) { - amendmentList_t lAmendments = getDesired(); + auto lAmendments = getDesired(); if (lAmendments.empty()) return; - STVector256 vAmendments (sfAmendments); - for (auto const& uAmendment : lAmendments) - vAmendments.push_back (uAmendment); - vAmendments.sort (); - baseValidation.setFieldV256 (sfAmendments, vAmendments); + STVector256 amendments (sfAmendments); + + for (auto const& id : lAmendments) + amendments.push_back (id); + + std::sort (amendments.begin (), amendments.end ()); + + baseValidation.setFieldV256 (sfAmendments, amendments); } template diff --git a/src/ripple/app/misc/HashRouter.cpp b/src/ripple/app/misc/HashRouter.cpp index fc9e067126..b1a3d27ad2 100644 --- a/src/ripple/app/misc/HashRouter.cpp +++ b/src/ripple/app/misc/HashRouter.cpp @@ -22,7 +22,6 @@ #include #include #include -#include #include #include @@ -146,8 +145,8 @@ HashRouter::Entry& HashRouter::findCreateEntry (uint256 const& index, bool& crea if ((it != mSuppressionTimes.end ()) && (it->first <= expireTime)) { - BOOST_FOREACH (uint256 const& lit, it->second) - mSuppressionMap.erase (lit); + for(auto const& lit : it->second) + mSuppressionMap.erase (lit); mSuppressionTimes.erase (it); } diff --git a/src/ripple/app/misc/NetworkOPs.cpp b/src/ripple/app/misc/NetworkOPs.cpp index 9efd446139..56e2765904 100644 --- a/src/ripple/app/misc/NetworkOPs.cpp +++ b/src/ripple/app/misc/NetworkOPs.cpp @@ -59,7 +59,6 @@ #include #include #include // -#include #include namespace ripple { @@ -1738,9 +1737,10 @@ void NetworkOPsImp::endConsensus (bool correctLCL) { uint256 deadLedger = m_ledgerMaster.getClosedLedger ()->getParentHash (); + // Why do we make a copy of the peer list here? std::vector peerList = getApp().overlay ().getActivePeers (); - BOOST_FOREACH (Peer::ptr const& it, peerList) + for (auto const& it : peerList) { if (it && (it->getClosedLedgerHash () == deadLedger)) { @@ -2582,7 +2582,7 @@ void NetworkOPsImp::pubLedger (Ledger::ref accepted) } // Don't lock since pubAcceptedTransaction is locking. - BOOST_FOREACH (const AcceptedLedger::value_type & vt, alpAccepted->getMap ()) + for (auto const& vt : alpAccepted->getMap ()) { m_journal.trace << "pubAccepted: " << vt.second->getJson (); pubValidatedTransaction (lpAccepted, *vt.second); @@ -2775,7 +2775,7 @@ void NetworkOPsImp::pubAccountTransaction ( std::string sObj = to_string (jvObj); - BOOST_FOREACH (InfoSub::ref isrListener, notify) + for (InfoSub::ref isrListener : notify) { isrListener->send (jvObj, sObj, true); } @@ -2793,7 +2793,7 @@ void NetworkOPsImp::subAccount (InfoSub::ref isrListener, SubInfoMapType& subMap = rt ? mSubRTAccount : mSubAccount; // For the connection, monitor each account. - BOOST_FOREACH (const RippleAddress & naAccountID, vnaAccountIDs) + for (auto const& naAccountID : vnaAccountIDs) { m_journal.trace << "subAccount:" " account: " << naAccountID.humanAccountID (); @@ -2803,7 +2803,7 @@ void NetworkOPsImp::subAccount (InfoSub::ref isrListener, ScopedLockType sl (mLock); - BOOST_FOREACH (const RippleAddress & naAccountID, vnaAccountIDs) + for (auto const& naAccountID : vnaAccountIDs) { auto simIterator = subMap.find (naAccountID.getAccountID ()); if (simIterator == subMap.end ()) diff --git a/src/ripple/app/paths/PathRequests.cpp b/src/ripple/app/paths/PathRequests.cpp index a972452c15..576bf2fdf7 100644 --- a/src/ripple/app/paths/PathRequests.cpp +++ b/src/ripple/app/paths/PathRequests.cpp @@ -23,7 +23,6 @@ #include #include #include -#include namespace ripple { @@ -77,7 +76,7 @@ void PathRequests::updateAll (Ledger::ref inLedger, do { - BOOST_FOREACH (PathRequest::wref wRequest, requests) + for (auto& wRequest : requests) { if (shouldCancel()) break; diff --git a/src/ripple/app/peers/UniqueNodeList.cpp b/src/ripple/app/peers/UniqueNodeList.cpp index 74e408bb6d..4e878a3656 100644 --- a/src/ripple/app/peers/UniqueNodeList.cpp +++ b/src/ripple/app/peers/UniqueNodeList.cpp @@ -35,7 +35,6 @@ #include // #include #include -#include #include #include #include @@ -75,6 +74,20 @@ namespace ripple { #define REFERRAL_VALIDATORS_MAX 50 #define REFERRAL_IPS_MAX 50 +template +std::string +strJoin (Iterator first, Iterator last, std::string strSeperator) +{ + std::ostringstream ossValues; + + for (Iterator start = first; first != last; first++) + { + ossValues << str (boost::format ("%s%s") % (start == first ? "" : strSeperator) % *first); + } + + return ossValues.str (); +} + // VFALCO TODO move all function definitions inlined into the class. class UniqueNodeListImp : public UniqueNodeList @@ -115,10 +128,6 @@ private: std::vector viReferrals; }; - typedef hash_map strIndex; - typedef std::pair IPAndPortNumber; - typedef hash_map, score> epScore; - public: explicit UniqueNodeListImp (Stoppable& parent) : UniqueNodeList (parent) @@ -705,7 +714,7 @@ private: void trustedLoad () { boost::regex rNode ("\\`\\s*(\\S+)[\\s]*(.*)\\'"); - BOOST_FOREACH (std::string const& c, getConfig ().CLUSTER_NODES) + for (auto const& c : getConfig ().CLUSTER_NODES) { boost::smatch match; @@ -743,7 +752,7 @@ private: bool bDist = false; // For each node, distribute roundSeed to roundScores. - BOOST_FOREACH (scoreNode & sn, vsnNodes) + for (auto& sn : vsnNodes) { int iEntries = sn.viReferrals.size (); @@ -752,7 +761,8 @@ private: score iTotal = (iEntries + 1) * iEntries / 2; score iBase = sn.iRoundSeed * iEntries / iTotal; - // Distribute the current entires' seed score to validators prioritized by mention order. + // Distribute the current entires' seed score to validators + // prioritized by mention order. for (int i = 0; i != iEntries; i++) { score iPoints = iBase * (iEntries - i) / iEntries; @@ -765,7 +775,7 @@ private: if (ShouldLog (lsTRACE, UniqueNodeList)) { WriteLog (lsTRACE, UniqueNodeList) << "midway: "; - BOOST_FOREACH (scoreNode & sn, vsnNodes) + for (auto& sn : vsnNodes) { WriteLog (lsTRACE, UniqueNodeList) << str (boost::format ("%s| %d, %d, %d: [%s]") % sn.strValidator @@ -778,7 +788,7 @@ private: // Add roundScore to score. // Make roundScore new roundSeed. - BOOST_FOREACH (scoreNode & sn, vsnNodes) + for (auto& sn : vsnNodes) { if (!bDist && sn.iRoundScore) bDist = true; @@ -791,7 +801,7 @@ private: if (ShouldLog (lsTRACE, UniqueNodeList)) { WriteLog (lsTRACE, UniqueNodeList) << "finish: "; - BOOST_FOREACH (scoreNode & sn, vsnNodes) + for (auto& sn : vsnNodes) { WriteLog (lsTRACE, UniqueNodeList) << str (boost::format ("%s| %d, %d, %d: [%s]") % sn.strValidator @@ -813,8 +823,8 @@ private: // void scoreCompute () { - strIndex umPulicIdx; // Map of public key to index. - strIndex umDomainIdx; // Map of domain to index. + hash_map umPulicIdx; // Map of public key to index. + hash_map umDomainIdx; // Map of domain to index. std::vector vsnNodes; // Index to scoring node. auto db = getApp().getWalletDB ().getDB (); @@ -836,7 +846,7 @@ private: std::string strPublicKey = db->getStrBinary ("PublicKey"); std::string strSource = db->getStrBinary ("Source"); int iScore = iSourceScore (static_cast (strSource[0])); - strIndex::iterator siOld = umPulicIdx.find (strPublicKey); + auto siOld = umPulicIdx.find (strPublicKey); if (siOld == umPulicIdx.end ()) { @@ -882,7 +892,7 @@ private: std::string strPublicKey = db->getStrBinary ("PublicKey"); std::string strSource = db->getStrBinary ("Source"); int iScore = iSourceScore (static_cast (strSource[0])); - strIndex::iterator siOld = umPulicIdx.find (strPublicKey); + auto siOld = umPulicIdx.find (strPublicKey); if (siOld == umPulicIdx.end ()) { @@ -919,7 +929,7 @@ private: // For debugging, print out initial scores. if (ShouldLog (lsTRACE, UniqueNodeList)) { - BOOST_FOREACH (scoreNode & sn, vsnNodes) + for (auto& sn : vsnNodes) { WriteLog (lsTRACE, UniqueNodeList) << str (boost::format ("%s| %d, %d, %d") % sn.strValidator @@ -947,14 +957,12 @@ private: std::string strReferral = db->getStrBinary ("Referral"); int iReferral; - strIndex::iterator itEntry; - RippleAddress na; if (na.setNodePublic (strReferral)) { // Referring a public key. - itEntry = umPulicIdx.find (strReferral); + auto itEntry = umPulicIdx.find (strReferral); if (itEntry == umPulicIdx.end ()) { @@ -977,19 +985,14 @@ private: { iReferral = itEntry->second; } - - // WriteLog (lsTRACE, UniqueNodeList) << str(boost::format("%s: Public=%s iReferral=%d") % strValidator % strReferral % iReferral); - } else { // Referring a domain. - itEntry = umDomainIdx.find (strReferral); + auto itEntry = umDomainIdx.find (strReferral); iReferral = itEntry == umDomainIdx.end () ? -1 // We ignore domains we can't find entires for. : itEntry->second; - - // WriteLog (lsTRACE, UniqueNodeList) << str(boost::format("%s: Domain=%s iReferral=%d") % strValidator % strReferral % iReferral); } if (iReferral >= 0 && iNode != iReferral) @@ -1008,7 +1011,7 @@ private: if (ShouldLog (lsTRACE, UniqueNodeList)) { WriteLog (lsTRACE, UniqueNodeList) << "Scored:"; - BOOST_FOREACH (scoreNode & sn, vsnNodes) + for (auto& sn : vsnNodes) { WriteLog (lsTRACE, UniqueNodeList) << str (boost::format ("%s| %d, %d, %d: [%s]") % sn.strValidator @@ -1094,14 +1097,13 @@ private: // For each validator, get each referral and add its score to ip's score. // map of pair :: score - epScore umScore; + hash_map, score> umScore; - typedef hash_map::value_type vcType; - BOOST_FOREACH (vcType & vc, umValidators) + for (auto& vc : umValidators) { std::string strValidator = vc.first; - strIndex::iterator itIndex = umPulicIdx.find (strValidator); + auto itIndex = umPulicIdx.find (strValidator); if (itIndex != umPulicIdx.end ()) { @@ -1121,7 +1123,7 @@ private: std::pair< std::string, int> ep = std::make_pair (db->getStrBinary ("IP"), iPort); - epScore::iterator itEp = umScore.find (ep); + auto itEp = umScore.find (ep); umScore[ep] = itEp == umScore.end () ? iPoints : itEp->second + iPoints; iEntry++; @@ -1590,7 +1592,7 @@ private: vstrValues.resize (std::min ((int) pmtVecStrIps->size (), REFERRAL_IPS_MAX)); int iValues = 0; - BOOST_FOREACH (std::string const& strReferral, *pmtVecStrIps) + for (auto const& strReferral : *pmtVecStrIps) { if (iValues == REFERRAL_VALIDATORS_MAX) break; @@ -1664,7 +1666,7 @@ private: vstrValues.reserve (std::min ((int) pmtVecStrValidators->size (), REFERRAL_VALIDATORS_MAX)); - BOOST_FOREACH (std::string const& strReferral, *pmtVecStrValidators) + for (auto const& strReferral : *pmtVecStrValidators) { if (iValues == REFERRAL_VALIDATORS_MAX) break; diff --git a/src/ripple/app/tx/TransactionAcquire.cpp b/src/ripple/app/tx/TransactionAcquire.cpp index 1b2767442b..a306c639d1 100644 --- a/src/ripple/app/tx/TransactionAcquire.cpp +++ b/src/ripple/app/tx/TransactionAcquire.cpp @@ -25,7 +25,6 @@ #include #include #include -#include #include namespace ripple { @@ -118,7 +117,7 @@ void TransactionAcquire::onTimer (bool progress, ScopedLockType& psl) bool found = false; Overlay::PeerSequence peerList = getApp().overlay ().getActivePeers (); - BOOST_FOREACH (Peer::ptr const& peer, peerList) + for (auto const& peer : peerList) { if (peer->hasTxSet (getHash ())) { @@ -129,8 +128,8 @@ void TransactionAcquire::onTimer (bool progress, ScopedLockType& psl) if (!found) { - BOOST_FOREACH (Peer::ptr const& peer, peerList) - peerHas (peer); + for (auto const& peer : peerList) + peerHas (peer); } } else if (!progress) diff --git a/src/ripple/app/tx/TransactionEngine.cpp b/src/ripple/app/tx/TransactionEngine.cpp index 59240054d5..f904ba288a 100644 --- a/src/ripple/app/tx/TransactionEngine.cpp +++ b/src/ripple/app/tx/TransactionEngine.cpp @@ -23,7 +23,6 @@ #include #include #include -#include #include namespace ripple { @@ -35,10 +34,9 @@ namespace ripple { void TransactionEngine::txnWrite () { // Write back the account states - typedef std::map::value_type u256_LES_pair; - BOOST_FOREACH (u256_LES_pair & it, mNodes) + for (auto& it : mNodes) { - SLE::ref sleEntry = it.second.mEntry; + SLE::ref sleEntry = it.second.mEntry; switch (it.second.mAction) { @@ -51,7 +49,8 @@ void TransactionEngine::txnWrite () case taaCREATE: { - WriteLog (lsDEBUG, TransactionEngine) << "applyTransaction: taaCREATE: " << sleEntry->getText (); + WriteLog (lsDEBUG, TransactionEngine) << + "applyTransaction: taaCREATE: " << sleEntry->getText (); if (mLedger->writeBack (lepCREATE, sleEntry) & lepERROR) assert (false); @@ -60,7 +59,8 @@ void TransactionEngine::txnWrite () case taaMODIFY: { - WriteLog (lsDEBUG, TransactionEngine) << "applyTransaction: taaMODIFY: " << sleEntry->getText (); + WriteLog (lsDEBUG, TransactionEngine) << + "applyTransaction: taaMODIFY: " << sleEntry->getText (); if (mLedger->writeBack (lepNONE, sleEntry) & lepERROR) assert (false); @@ -69,7 +69,8 @@ void TransactionEngine::txnWrite () case taaDELETE: { - WriteLog (lsDEBUG, TransactionEngine) << "applyTransaction: taaDELETE: " << sleEntry->getText (); + WriteLog (lsDEBUG, TransactionEngine) << + "applyTransaction: taaDELETE: " << sleEntry->getText (); if (!mLedger->peekAccountStateMap ()->delItem (it.first)) assert (false); diff --git a/src/ripple/app/tx/TransactionMeta.cpp b/src/ripple/app/tx/TransactionMeta.cpp index b12db2dbd2..cd1de09bbc 100644 --- a/src/ripple/app/tx/TransactionMeta.cpp +++ b/src/ripple/app/tx/TransactionMeta.cpp @@ -22,7 +22,6 @@ #include #include #include -#include #include namespace ripple { @@ -51,10 +50,11 @@ TransactionMetaSet::TransactionMetaSet (uint256 const& txid, std::uint32_t ledge bool TransactionMetaSet::isNodeAffected (uint256 const& node) const { - BOOST_FOREACH (const STObject & it, mNodes) - - if (it.getFieldH256 (sfLedgerIndex) == node) - return true; + for (auto const& n : mNodes) + { + if (n.getFieldH256 (sfLedgerIndex) == node) + return true; + } return false; } @@ -63,12 +63,12 @@ void TransactionMetaSet::setAffectedNode (uint256 const& node, SField::ref type, std::uint16_t nodeType) { // make sure the node exists and force its type - BOOST_FOREACH (STObject & it, mNodes) + for (auto& n : mNodes) { - if (it.getFieldH256 (sfLedgerIndex) == node) + if (n.getFieldH256 (sfLedgerIndex) == node) { - it.setFName (type); - it.setFieldU16 (sfLedgerEntryType, nodeType); + n.setFName (type); + n.setFieldU16 (sfLedgerEntryType, nodeType); return; } } @@ -83,10 +83,11 @@ void TransactionMetaSet::setAffectedNode (uint256 const& node, SField::ref type, static void addIfUnique (std::vector& vector, RippleAddress const& address) { - BOOST_FOREACH (const RippleAddress & a, vector) - - if (a == address) - return; + for (auto const& a : vector) + { + if (a == address) + return; + } vector.push_back (address); } @@ -98,7 +99,7 @@ std::vector TransactionMetaSet::getAffectedAccounts () // This code should match the behavior of the JS method: // Meta#getAffectedAccounts - BOOST_FOREACH (const STObject & it, mNodes) + for (auto const& it : mNodes) { int index = it.getFieldIndex ((it.getFName () == sfCreatedNode) ? sfNewFields : sfFinalFields); @@ -108,7 +109,7 @@ std::vector TransactionMetaSet::getAffectedAccounts () if (inner) { - BOOST_FOREACH (const STBase & field, inner->peekData ()) + for (auto const& field : inner->peekData ()) { const STAccount* sa = dynamic_cast (&field); @@ -148,10 +149,10 @@ STObject& TransactionMetaSet::getAffectedNode (SLE::ref node, SField::ref type) { assert (&type); uint256 index = node->getIndex (); - BOOST_FOREACH (STObject & it, mNodes) + for (auto& n : mNodes) { - if (it.getFieldH256 (sfLedgerIndex) == index) - return it; + if (n.getFieldH256 (sfLedgerIndex) == index) + return n; } mNodes.push_back (STObject (type)); STObject& obj = mNodes.back (); @@ -165,10 +166,10 @@ STObject& TransactionMetaSet::getAffectedNode (SLE::ref node, SField::ref type) STObject& TransactionMetaSet::getAffectedNode (uint256 const& node) { - BOOST_FOREACH (STObject & it, mNodes) + for (auto& n : mNodes) { - if (it.getFieldH256 (sfLedgerIndex) == node) - return it; + if (n.getFieldH256 (sfLedgerIndex) == node) + return n; } assert (false); throw std::runtime_error ("Affected node not found"); @@ -176,10 +177,11 @@ STObject& TransactionMetaSet::getAffectedNode (uint256 const& node) const STObject& TransactionMetaSet::peekAffectedNode (uint256 const& node) const { - BOOST_FOREACH (const STObject & it, mNodes) - - if (it.getFieldH256 (sfLedgerIndex) == node) - return it; + for (auto const& n : mNodes) + { + if (n.getFieldH256 (sfLedgerIndex) == node) + return n; + } throw std::runtime_error ("Affected node not found"); } diff --git a/src/ripple/basics/StringUtilities.h b/src/ripple/basics/StringUtilities.h index 986afbbda3..a39e760eae 100644 --- a/src/ripple/basics/StringUtilities.h +++ b/src/ripple/basics/StringUtilities.h @@ -32,21 +32,6 @@ namespace ripple { extern std::string urlEncode (std::string const& strSrc); -// NIKB TODO remove this function - it's only used for some logging in the UNL -// code which can be trivially rewritten. -template -std::string strJoin (Iterator first, Iterator last, std::string strSeperator) -{ - std::ostringstream ossValues; - - for (Iterator start = first; first != last; first++) - { - ossValues << str (boost::format ("%s%s") % (start == first ? "" : strSeperator) % *first); - } - - return ossValues.str (); -} - // NIKB TODO Remove the need for all these overloads. Move them out of here. inline const std::string strHex (std::string const& strSrc) { diff --git a/src/ripple/basics/impl/RangeSet.cpp b/src/ripple/basics/impl/RangeSet.cpp index 3420ec7d10..362545c0e1 100644 --- a/src/ripple/basics/impl/RangeSet.cpp +++ b/src/ripple/basics/impl/RangeSet.cpp @@ -42,7 +42,7 @@ inline std::uint32_t max (std::uint32_t x, std::uint32_t y) bool RangeSet::hasValue (std::uint32_t v) const { - BOOST_FOREACH (const value_type & it, mRanges) + for (auto const& it : mRanges) { if (contains (it, v)) return true; @@ -62,7 +62,7 @@ std::uint32_t RangeSet::getFirst () const std::uint32_t RangeSet::getNext (std::uint32_t v) const { - BOOST_FOREACH (const value_type & it, mRanges) + for (auto const& it : mRanges) { if (it.first > v) return it.first; @@ -190,7 +190,7 @@ void RangeSet::clearValue (std::uint32_t v) std::string RangeSet::toString () const { std::string ret; - BOOST_FOREACH (value_type const & it, mRanges) + for (auto const& it : mRanges) { if (!ret.empty ()) ret += ","; diff --git a/src/ripple/core/impl/Config.cpp b/src/ripple/core/impl/Config.cpp index 11098dcb11..371a335f43 100644 --- a/src/ripple/core/impl/Config.cpp +++ b/src/ripple/core/impl/Config.cpp @@ -28,7 +28,6 @@ #include #include #include -#include #include #include #include @@ -79,7 +78,7 @@ parseIniFile (std::string const& strInput, const bool bTrim) secResult[strSection] = IniFileSections::mapped_type (); // Parse each line. - BOOST_FOREACH (std::string & strValue, vLines) + for (auto& strValue : vLines) { if (strValue.empty () || strValue[0] == '#') { @@ -448,7 +447,7 @@ void Config::load () { RPC_STARTUP = Json::arrayValue; - BOOST_FOREACH (std::string const& strJson, *smtTmp) + for (auto const& strJson : *smtTmp) { Json::Reader jrReader; Json::Value jvCommand; diff --git a/src/ripple/crypto/impl/RFC1751.cpp b/src/ripple/crypto/impl/RFC1751.cpp index 16ea357a63..9f9a8720ad 100644 --- a/src/ripple/crypto/impl/RFC1751.cpp +++ b/src/ripple/crypto/impl/RFC1751.cpp @@ -21,7 +21,6 @@ #include #include #include -#include #include #include #include @@ -403,7 +402,7 @@ int RFC1751::etob (std::string& strData, std::vector vsHuman) memset (b, 0, sizeof (b)); p = 0; - BOOST_FOREACH (std::string & strWord, vsHuman) + for (auto& strWord : vsHuman) { l = strWord.length (); diff --git a/src/ripple/net/impl/SNTPClient.cpp b/src/ripple/net/impl/SNTPClient.cpp index 478e42fbbe..d28bc4052a 100644 --- a/src/ripple/net/impl/SNTPClient.cpp +++ b/src/ripple/net/impl/SNTPClient.cpp @@ -24,7 +24,6 @@ #include #include #include -#include #include namespace ripple { @@ -143,8 +142,8 @@ public: return; } - BOOST_FOREACH (std::string const& it, servers) - addServer (it); + for (auto const& it : servers) + addServer (it); queryAll (); } diff --git a/src/ripple/protocol/STAccount.h b/src/ripple/protocol/STAccount.h index ce5fabbcd3..58fefbdc44 100644 --- a/src/ripple/protocol/STAccount.h +++ b/src/ripple/protocol/STAccount.h @@ -26,7 +26,8 @@ namespace ripple { -class STAccount : public STBlob +class STAccount final + : public STBlob { public: STAccount (Blob const& v) : STBlob (v) @@ -51,11 +52,11 @@ public: return std::unique_ptr (construct (sit, name)); } - SerializedTypeID getSType () const + SerializedTypeID getSType () const override { return STI_ACCOUNT; } - std::string getText () const; + std::string getText () const override; RippleAddress getValueNCA () const; void setValueNCA (RippleAddress const& nca); @@ -79,11 +80,13 @@ public: bool isValueH160 () const; -private: - virtual STAccount* duplicate () const + std::unique_ptr + duplicate () const override { - return new STAccount (*this); + return std::make_unique(*this); } + +private: static STAccount* construct (SerializerIterator&, SField::ref); }; diff --git a/src/ripple/protocol/STAmount.h b/src/ripple/protocol/STAmount.h index 66597b04f5..255b646070 100644 --- a/src/ripple/protocol/STAmount.h +++ b/src/ripple/protocol/STAmount.h @@ -38,7 +38,8 @@ 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 : public STBase +class STAmount final + : public STBase { public: typedef std::uint64_t mantissa_type; @@ -110,6 +111,9 @@ private: std::unique_ptr construct (SerializerIterator&, SField::ref name); + void + setSNValue (std::int64_t); + public: static STAmount @@ -213,9 +217,6 @@ public: // VFALCO TODO Remove this, it is only called from the unit test void roundSelf(); - void setNValue (std::uint64_t v); - void setSNValue (std::int64_t); - void negate() { if (*this != zero) @@ -288,9 +289,11 @@ public: return (mValue == 0) && mIsNative; } -private: - STAmount* - duplicate() const override; + std::unique_ptr + duplicate () const override + { + return std::make_unique(*this); + } void canonicalize(); void set (std::int64_t v); diff --git a/src/ripple/protocol/STArray.h b/src/ripple/protocol/STArray.h index ba66188957..6079c7575d 100644 --- a/src/ripple/protocol/STArray.h +++ b/src/ripple/protocol/STArray.h @@ -42,40 +42,45 @@ public: typedef vector::size_type size_type; public: - STArray () - { - ; - } - explicit STArray (int n) + STArray () = default; + + explicit + STArray (int n) { value.reserve (n); } - explicit STArray (SField::ref f) : STBase (f) - { - ; - } - STArray (SField::ref f, int n) : STBase (f) + + explicit + STArray (SField::ref f) + : STBase (f) + { } + + STArray (SField::ref f, int n) + : STBase (f) { value.reserve (n); } - STArray (SField::ref f, const vector & v) : STBase (f), value (v) - { - ; - } - explicit STArray (vector & v) : value (v) - { - ; - } - virtual ~STArray () { } + STArray (SField::ref f, const vector& v) + : STBase (f), value (v) + { } - static std::unique_ptr + explicit + STArray (vector & v) + : value (v) + { } + + virtual ~STArray () = default; + + static + std::unique_ptr deserialize (SerializerIterator & sit, SField::ref name); const vector& getValue () const { return value; } + vector& getValue () { return value; @@ -197,10 +202,10 @@ public: return value.empty (); } -private: - virtual STArray* duplicate () const override + std::unique_ptr + duplicate () const override { - return new STArray (*this); + return std::make_unique(*this); } private: diff --git a/src/ripple/protocol/STBase.h b/src/ripple/protocol/STBase.h index 27be58f559..097a57cd5b 100644 --- a/src/ripple/protocol/STBase.h +++ b/src/ripple/protocol/STBase.h @@ -23,6 +23,7 @@ #include #include #include +#include // #include #include @@ -126,9 +127,6 @@ public: SField::ref getFName() const; - std::unique_ptr - clone() const; - void addFieldID (Serializer& s) const; @@ -136,17 +134,15 @@ public: std::unique_ptr deserialize (SField::ref name); + virtual + std::unique_ptr + duplicate () const + { + return std::make_unique(*fName); + } + protected: SField::ptr fName; - -private: - // VFALCO TODO Return std::unique_ptr - virtual - STBase* - duplicate() const - { - return new STBase (*fName); - } }; //------------------------------------------------------------------------------ diff --git a/src/ripple/protocol/STBitString.h b/src/ripple/protocol/STBitString.h index 0c69303761..ee112ea6ae 100644 --- a/src/ripple/protocol/STBitString.h +++ b/src/ripple/protocol/STBitString.h @@ -25,57 +25,71 @@ namespace ripple { template -class STBitString : public STBase +class STBitString final + : public STBase { public: typedef base_uint BitString; - STBitString () {} - STBitString (SField::ref n) : STBase (n) {} - STBitString (const BitString& v) : bitString_ (v) {} + STBitString () = default; + + STBitString (SField::ref n) + : STBase (n) + { } + + STBitString (const BitString& v) + : bitString_ (v) + { } STBitString (SField::ref n, const BitString& v) - : STBase (n), bitString_ (v) - { - } + : STBase (n), bitString_ (v) + { } - STBitString (SField::ref n, const char* v) : STBase (n) + STBitString (SField::ref n, const char* v) + : STBase (n) { bitString_.SetHex (v); } - STBitString (SField::ref n, std::string const& v) : STBase (n) + STBitString (SField::ref n, std::string const& v) + : STBase (n) { bitString_.SetHex (v); } - static std::unique_ptr deserialize ( - SerializerIterator& sit, SField::ref name) + static + std::unique_ptr + deserialize (SerializerIterator& sit, SField::ref name) { - return std::unique_ptr (construct (sit, name)); + return std::make_unique (name, sit.getBitString ()); } - SerializedTypeID getSType () const; + SerializedTypeID + getSType () const override; - std::string getText () const + std::string + getText () const override { return to_string (bitString_); } - bool isEquivalent (const STBase& t) const + bool + isEquivalent (const STBase& t) const override { const STBitString* v = dynamic_cast (&t); return v && (bitString_ == v->bitString_); } - void add (Serializer& s) const + void + add (Serializer& s) const override { assert (fName->isBinary ()); assert (fName->fieldType == getSType()); s.addBitString (bitString_); } - const BitString& getValue () const + const BitString& + getValue () const { return bitString_; } @@ -91,47 +105,50 @@ public: return bitString_; } - virtual bool isDefault () const + bool + isDefault () const override { return bitString_ == zero; } + std::unique_ptr + duplicate () const override + { + return std::make_unique(*this); + } + private: BitString bitString_; - - STBitString* duplicate () const - { - return new STBitString (*this); - } - - static STBitString* construct (SerializerIterator& u, SField::ref name) - { - return new STBitString (name, u.getBitString ()); - } }; -template <> -inline SerializedTypeID STBitString<128>::getSType () const -{ - return STI_HASH128; -} - -template <> -inline SerializedTypeID STBitString<160>::getSType () const -{ - return STI_HASH160; -} - -template <> -inline SerializedTypeID STBitString<256>::getSType () const -{ - return STI_HASH256; -} - using STHash128 = STBitString<128>; using STHash160 = STBitString<160>; using STHash256 = STBitString<256>; +template <> +inline +SerializedTypeID +STHash128::getSType () const +{ + return STI_HASH128; +} + +template <> +inline +SerializedTypeID +STHash160::getSType () const +{ + return STI_HASH160; +} + +template <> +inline +SerializedTypeID +STHash256::getSType () const +{ + return STI_HASH256; +} + } // ripple #endif diff --git a/src/ripple/protocol/STBlob.h b/src/ripple/protocol/STBlob.h index 68466569de..110acea5f5 100644 --- a/src/ripple/protocol/STBlob.h +++ b/src/ripple/protocol/STBlob.h @@ -26,37 +26,44 @@ namespace ripple { // variable length byte string -class STBlob : public STBase +class STBlob + : public STBase { public: - STBlob (Blob const& v) : value (v) - { - ; - } - STBlob (SField::ref n, Blob const& v) : STBase (n), value (v) - { - ; - } - STBlob (SField::ref n) : STBase (n) - { - ; - } + STBlob () = default; + + STBlob (Blob const& v) + : value (v) + { } + + STBlob (SField::ref n, Blob const& v) + : STBase (n), value (v) + { } + + STBlob (SField::ref n) + : STBase (n) + { } + STBlob (SerializerIterator&, SField::ref name = sfGeneric); - STBlob () + + static + std::unique_ptr + deserialize (SerializerIterator& sit, SField::ref name) { - ; - } - static std::unique_ptr deserialize (SerializerIterator& sit, SField::ref name) - { - return std::unique_ptr (construct (sit, name)); + return std::make_unique (name, sit.getVL ()); } - virtual SerializedTypeID getSType () const + SerializedTypeID + getSType () const override { return STI_VL; } - virtual std::string getText () const; - void add (Serializer& s) const + + std::string + getText () const override; + + void + add (Serializer& s) const override { assert (fName->isBinary ()); assert ((fName->fieldType == STI_VL) || @@ -64,41 +71,53 @@ public: s.addVL (value); } - Blob const& peekValue () const + Blob const& + peekValue () const { return value; } - Blob& peekValue () + + Blob& + peekValue () { return value; } - Blob getValue () const + + Blob + getValue () const { return value; } - void setValue (Blob const& v) + + void + setValue (Blob const& v) { value = v; } + explicit operator Blob () const { return value; } - virtual bool isEquivalent (const STBase& t) const; - virtual bool isDefault () const + + bool + isEquivalent (const STBase& t) const override; + + bool + isDefault () const override { return value.empty (); } + std::unique_ptr + duplicate () const override + { + return std::make_unique(*this); + } + private: Blob value; - - virtual STBlob* duplicate () const - { - return new STBlob (*this); - } - static STBlob* construct (SerializerIterator&, SField::ref); }; } // ripple diff --git a/src/ripple/protocol/STInteger.h b/src/ripple/protocol/STInteger.h index 4a3f8b6f11..2ecd48e370 100644 --- a/src/ripple/protocol/STInteger.h +++ b/src/ripple/protocol/STInteger.h @@ -25,70 +25,79 @@ namespace ripple { template -class STInteger : public STBase +class STInteger + : public STBase { public: - explicit STInteger (Integer v) : value_ (v) - { - } + explicit + STInteger (Integer v) + : value_ (v) + { } - STInteger (SField::ref n, Integer v = 0) : STBase (n), value_ (v) - { - } + STInteger (SField::ref n, Integer v = 0) + : STBase (n), value_ (v) + { } - static std::unique_ptr deserialize ( - SerializerIterator& sit, SField::ref name) - { - return std::unique_ptr (construct (sit, name)); - } + static + std::unique_ptr + deserialize (SerializerIterator& sit, SField::ref name); - SerializedTypeID getSType () const - { - return STI_UINT8; - } + SerializedTypeID + getSType () const override; - Json::Value getJson (int) const; - std::string getText () const; + Json::Value + getJson (int) const override; - void add (Serializer& s) const + std::string + getText () const override; + + void + add (Serializer& s) const override { assert (fName->isBinary ()); assert (fName->fieldType == getSType ()); s.addInteger (value_); } - Integer getValue () const + Integer + getValue () const { return value_; } - void setValue (Integer v) + + void + setValue (Integer v) { value_ = v; } - operator Integer () const + operator + Integer () const { return value_; } - virtual bool isDefault () const + + virtual + bool isDefault () const override { return value_ == 0; } - bool isEquivalent (const STBase& t) const + bool + isEquivalent (const STBase& t) const override { const STInteger* v = dynamic_cast (&t); return v && (value_ == v->value_); } + std::unique_ptr + duplicate () const override + { + return std::make_unique(*this); + } + private: Integer value_; - - STInteger* duplicate () const - { - return new STInteger (*this); - } - static STInteger* construct (SerializerIterator&, SField::ref f); }; using STUInt8 = STInteger; diff --git a/src/ripple/protocol/STLedgerEntry.h b/src/ripple/protocol/STLedgerEntry.h index 41fe88cde1..94886c23cd 100644 --- a/src/ripple/protocol/STLedgerEntry.h +++ b/src/ripple/protocol/STLedgerEntry.h @@ -25,7 +25,7 @@ namespace ripple { -class STLedgerEntry +class STLedgerEntry final : public STObject , public CountedObject { @@ -41,13 +41,13 @@ public: STLedgerEntry (LedgerEntryType type, uint256 const& index); STLedgerEntry (const STObject & object, uint256 const& index); - SerializedTypeID getSType () const + SerializedTypeID getSType () const override { return STI_LEDGERENTRY; } - std::string getFullText () const; - std::string getText () const; - Json::Value getJson (int options) const; + std::string getFullText () const override; + std::string getText () const override; + Json::Value getJson (int options) const override; uint256 const& getIndex () const { @@ -94,12 +94,13 @@ public: std::uint32_t & prevLedgerID); std::vector getOwners (); // nodes notified if this node is deleted -private: - STLedgerEntry* duplicate () const + std::unique_ptr + duplicate () const override { - return new STLedgerEntry (*this); + return std::make_unique(*this); } +private: /** Make STObject comply with the template for this SLE type Can throw */ diff --git a/src/ripple/protocol/STObject.h b/src/ripple/protocol/STObject.h index 0e8c9c333b..4d17b19b24 100644 --- a/src/ripple/protocol/STObject.h +++ b/src/ripple/protocol/STObject.h @@ -125,7 +125,7 @@ public: int addObject (const STBase & t) { - mData.push_back (t.clone ().release ()); + mData.push_back (t.duplicate ().release ()); return mData.size () - 1; } int giveObject (std::unique_ptr t) @@ -317,12 +317,13 @@ public: return ! (*this == o); } -private: - virtual STObject* duplicate () const override + std::unique_ptr + duplicate () const override { - return new STObject (*this); + return std::make_unique(*this); } +private: // Implementation for getting (most) fields that return by value. // // The remove_cv and remove_reference are necessitated by the STBitString diff --git a/src/ripple/protocol/STPathSet.h b/src/ripple/protocol/STPathSet.h index f5acfe1eca..6c2f445e85 100644 --- a/src/ripple/protocol/STPathSet.h +++ b/src/ripple/protocol/STPathSet.h @@ -28,7 +28,6 @@ namespace ripple { -// VFALCO Why isn't this derived from STBase? class STPathElement { public: @@ -82,35 +81,46 @@ public: hash_value_ = get_hash (*this); } - int getNodeType () const + int + getNodeType () const { return mType; } - bool isOffer () const + + bool + isOffer () const { return is_offer_; } - bool isAccount () const + + bool + isAccount () const { return !isOffer (); } // Nodes are either an account ID or a offer prefix. Offer prefixs denote a // class of offers. - Account const& getAccountID () const + Account const& + getAccountID () const { return mAccountID; } - Currency const& getCurrency () const + + Currency const& + getCurrency () const { return mCurrencyID; } - Account const& getIssuerID () const + + Account const& + getIssuerID () const { return mIssuerID; } - bool operator== (const STPathElement& t) const + bool + operator== (const STPathElement& t) const { return (mType & typeAccount) == (t.mType & typeAccount) && hash_value_ == t.hash_value_ && @@ -162,9 +172,13 @@ public: mPath.emplace_back (std::forward (args)...); } - bool hasSeen (Account const& account, Currency const& currency, - Account const& issuer) const; - Json::Value getJson (int) const; + bool + hasSeen ( + Account const& account, Currency const& currency, + Account const& issuer) const; + + Json::Value + getJson (int) const; std::vector::const_iterator begin () const @@ -178,7 +192,8 @@ public: return mPath.end (); } - bool operator== (STPath const& t) const + bool + operator== (STPath const& t) const { return mPath == t.mPath; } @@ -212,7 +227,8 @@ private: //------------------------------------------------------------------------------ // A set of zero or more payment paths -class STPathSet : public STBase +class STPathSet final + : public STBase { public: STPathSet () = default; @@ -223,91 +239,77 @@ public: static std::unique_ptr - deserialize (SerializerIterator& sit, SField::ref name) + deserialize (SerializerIterator& sit, SField::ref name); + + std::unique_ptr + duplicate () const override { - return std::unique_ptr (construct (sit, name)); + return std::make_unique(*this); } - void add (Serializer& s) const; - virtual Json::Value getJson (int) const; + void + add (Serializer& s) const override; - SerializedTypeID getSType () const + Json::Value + getJson (int) const override; + + SerializedTypeID + getSType () const override { return STI_PATHSET; } - std::vector::size_type - size () const - { - return value.size (); - } - bool empty () const - { - return value.empty (); - } - - void push_back (STPath const& e) - { - value.push_back (e); - } - - bool assembleAdd(STPath const& base, STPathElement const& tail) - { // assemble base+tail and add it to the set if it's not a duplicate - value.push_back (base); - - std::vector::reverse_iterator it = value.rbegin (); - - STPath& newPath = *it; - newPath.push_back (tail); - - while (++it != value.rend ()) - { - if (*it == newPath) - { - value.pop_back (); - return false; - } - } - return true; - } - - virtual bool isEquivalent (const STBase& t) const; - virtual bool isDefault () const + bool + assembleAdd(STPath const& base, STPathElement const& tail); + + bool + isEquivalent (const STBase& t) const override; + + bool + isDefault () const override { return value.empty (); } + // std::vector like interface: std::vector::const_reference operator[] (std::vector::size_type n) const { return value[n]; } - std::vector::const_iterator begin () const + std::vector::const_iterator + begin () const { return value.begin (); } - std::vector::const_iterator end () const + std::vector::const_iterator + end () const { return value.end (); } -private: - std::vector value; - - STPathSet (SField::ref n, const std::vector& v) - : STBase (n), value (v) - { } - - STPathSet* duplicate () const + std::vector::size_type + size () const { - return new STPathSet (*this); + return value.size (); } - static - STPathSet* - construct (SerializerIterator&, SField::ref); + bool + empty () const + { + return value.empty (); + } + + void + push_back (STPath const& e) + { + value.push_back (e); + } + +private: + std::vector value; }; } // ripple diff --git a/src/ripple/protocol/STTx.h b/src/ripple/protocol/STTx.h index abe045bb52..934bf3f841 100644 --- a/src/ripple/protocol/STTx.h +++ b/src/ripple/protocol/STTx.h @@ -34,7 +34,7 @@ namespace ripple { #define TXN_SQL_INCLUDED 'I' #define TXN_SQL_UNKNOWN 'U' -class STTx +class STTx final : public STObject , public CountedObject { @@ -57,11 +57,11 @@ public: explicit STTx (STObject const& object); // STObject functions - SerializedTypeID getSType () const + SerializedTypeID getSType () const override { return STI_TRANSACTION; } - std::string getFullText () const; + std::string getFullText () const override; // outer transaction functions / signature functions Blob getSignature () const; @@ -105,7 +105,7 @@ public: uint256 getTransactionID () const; - virtual Json::Value getJson (int options) const; + virtual Json::Value getJson (int options) const override; virtual Json::Value getJson (int options, bool binary) const; void sign (RippleAddress const& private_key); @@ -143,12 +143,13 @@ public: char status, std::string const& escapedMetaData) const; -private: - STTx* duplicate () const override + std::unique_ptr + duplicate () const override { - return new STTx (*this); + return std::make_unique(*this); } +private: TxType tx_type_; mutable boost::tribool sig_state_; diff --git a/src/ripple/protocol/STValidation.h b/src/ripple/protocol/STValidation.h index be77e4e41c..ce3d3f28d9 100644 --- a/src/ripple/protocol/STValidation.h +++ b/src/ripple/protocol/STValidation.h @@ -30,7 +30,7 @@ namespace ripple { // Validation flags const std::uint32_t vfFullyCanonicalSig = 0x80000000; // signature is fully canonical -class STValidation +class STValidation final : public STObject , public CountedObject { diff --git a/src/ripple/protocol/STVector256.h b/src/ripple/protocol/STVector256.h index 10b329ab5a..52d99ceb93 100644 --- a/src/ripple/protocol/STVector256.h +++ b/src/ripple/protocol/STVector256.h @@ -27,100 +27,139 @@ namespace ripple { -class STVector256 : public STBase +class STVector256 final + : public STBase { public: STVector256 () = default; + explicit STVector256 (SField::ref n) : STBase (n) { } + explicit STVector256 (std::vector const& vector) : mValue (vector) { } - SerializedTypeID getSType () const + SerializedTypeID + getSType () const override { return STI_VECTOR256; } - void add (Serializer& s) const; + + void + add (Serializer& s) const override; static std::unique_ptr - deserialize (SerializerIterator& sit, SField::ref name) - { - return std::unique_ptr (construct (sit, name)); - } + deserialize (SerializerIterator& sit, SField::ref name); - const std::vector& - peekValue () const - { - return mValue; - } + Json::Value + getJson (int) const override; - std::vector& - peekValue () - { - return mValue; - } - - virtual bool isEquivalent (const STBase& t) const; - virtual bool isDefault () const + bool + isEquivalent (const STBase& t) const override; + + bool + isDefault () const override { return mValue.empty (); } + void + setValue (const STVector256& v) + { + mValue = v.mValue; + } + + std::unique_ptr + duplicate () const override + { + return std::make_unique(*this); + } + + /** Retrieve a copy of the vector we contain */ + explicit + operator std::vector () const + { + return mValue; + } + + // std::vector interface: std::vector::size_type size () const { return mValue.size (); } - bool empty () const + + void + resize (std::vector::size_type n) + { + return mValue.resize (n); + } + + bool + empty () const { return mValue.empty (); } + std::vector::reference + operator[] (std::vector::size_type n) + { + return mValue[n]; + } + std::vector::const_reference operator[] (std::vector::size_type n) const { return mValue[n]; } - void setValue (const STVector256& v) - { - mValue = v.mValue; - } - - void push_back (uint256 const& v) + void + push_back (uint256 const& v) { mValue.push_back (v); } - void sort () + std::vector::iterator + begin() { - std::sort (mValue.begin (), mValue.end ()); + return mValue.begin (); } - Json::Value getJson (int) const; - std::vector::const_iterator begin() const { return mValue.begin (); } + + std::vector::iterator + end() + { + return mValue.end (); + } + std::vector::const_iterator end() const { return mValue.end (); } + std::vector::iterator + erase (std::vector::iterator position) + { + return mValue.erase (position); + } + + void + clear () noexcept + { + return mValue.clear (); + } + private: std::vector mValue; - - STVector256* duplicate () const - { - return new STVector256 (*this); - } - static STVector256* construct (SerializerIterator&, SField::ref); }; } // ripple diff --git a/src/ripple/protocol/impl/STAmount.cpp b/src/ripple/protocol/impl/STAmount.cpp index 10f140c8a6..5be7c52a5e 100644 --- a/src/ripple/protocol/impl/STAmount.cpp +++ b/src/ripple/protocol/impl/STAmount.cpp @@ -28,6 +28,8 @@ #include #include #include // +#include // +#include namespace ripple { @@ -35,6 +37,9 @@ static const std::uint64_t tenTo14 = 100000000000000ull; static const std::uint64_t tenTo14m1 = tenTo14 - 1; static const std::uint64_t tenTo17 = tenTo14 * 1000; +STAmount const saZero (noIssue(), 0u); +STAmount const saOne (noIssue(), 1u); + //------------------------------------------------------------------------------ STAmount::STAmount (SField::ref name, Issue const& issue, @@ -494,14 +499,6 @@ std::string STAmount::getHumanCurrency () const return to_string (mIssue.currency); } -void -STAmount::setNValue (std::uint64_t v) -{ - if (!mIsNative) - throw std::runtime_error ("not native"); - mValue = v; -} - void STAmount::setSNValue (std::int64_t v) { @@ -752,12 +749,6 @@ STAmount::isEquivalent (const STBase& t) const return v && (*v == *this); } -STAmount* -STAmount::duplicate () const -{ - return new STAmount (*this); -} - //------------------------------------------------------------------------------ // amount = value * [10 ^ offset] diff --git a/src/ripple/protocol/impl/STBase.cpp b/src/ripple/protocol/impl/STBase.cpp index 47e6eb07ca..d07aa5d46e 100644 --- a/src/ripple/protocol/impl/STBase.cpp +++ b/src/ripple/protocol/impl/STBase.cpp @@ -138,12 +138,6 @@ STBase::getFName() const return *fName; } -std::unique_ptr -STBase::clone() const -{ - return std::unique_ptr (duplicate()); -} - void STBase::addFieldID (Serializer& s) const { @@ -162,7 +156,7 @@ STBase::deserialize (SField::ref name) STBase* new_clone (const STBase& s) { - STBase* const copy (s.clone ().release ()); + STBase* const copy (s.duplicate ().release ()); assert (typeid (*copy) == typeid (s)); return copy; } diff --git a/src/ripple/protocol/impl/STBlob.cpp b/src/ripple/protocol/impl/STBlob.cpp index c5cc0ce285..43d0405c45 100644 --- a/src/ripple/protocol/impl/STBlob.cpp +++ b/src/ripple/protocol/impl/STBlob.cpp @@ -29,17 +29,14 @@ STBlob::STBlob (SerializerIterator& st, SField::ref name) value = st.getVL (); } -std::string STBlob::getText () const +std::string +STBlob::getText () const { return strHex (value); } -STBlob* STBlob::construct (SerializerIterator& u, SField::ref name) -{ - return new STBlob (name, u.getVL ()); -} - -bool STBlob::isEquivalent (const STBase& t) const +bool +STBlob::isEquivalent (const STBase& t) const { const STBlob* v = dynamic_cast (&t); return v && (value == v->value); diff --git a/src/ripple/protocol/impl/STInteger.cpp b/src/ripple/protocol/impl/STInteger.cpp index cdc8753f94..287c5f2050 100644 --- a/src/ripple/protocol/impl/STInteger.cpp +++ b/src/ripple/protocol/impl/STInteger.cpp @@ -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 +STUInt8::deserialize (SerializerIterator& sit, SField::ref name) { - return new STUInt8 (name, u.get8 ()); + return std::make_unique (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 +STUInt16::deserialize (SerializerIterator& sit, SField::ref name) { - return new STUInt16 (name, u.get16 ()); + return std::make_unique (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 (value_)); + auto item =TxFormats::getInstance().findByType ( + static_cast (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 (value_)); + auto item = LedgerFormats::getInstance ().findByType ( + static_cast (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 (value_)); + auto item = TxFormats::getInstance().findByType ( + static_cast (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 +STUInt32::deserialize (SerializerIterator& sit, SField::ref name) { - return new STUInt32 (name, u.get32 ()); + return std::make_unique (name, sit.get32 ()); } template <> -std::string STUInt32::getText () const +std::string +STUInt32::getText () const { return beast::lexicalCastThrow (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 +STUInt64::deserialize (SerializerIterator& sit, SField::ref name) { - return new STUInt64 (name, u.get64 ()); + return std::make_unique (name, sit.get64 ()); } template <> -std::string STUInt64::getText () const +std::string +STUInt64::getText () const { return beast::lexicalCastThrow (value_); } template <> -Json::Value STUInt64::getJson (int) const +Json::Value +STUInt64::getJson (int) const { return strHex (value_); } diff --git a/src/ripple/protocol/impl/STObject.cpp b/src/ripple/protocol/impl/STObject.cpp index 37049d5aba..d7f7dc5975 100644 --- a/src/ripple/protocol/impl/STObject.cpp +++ b/src/ripple/protocol/impl/STObject.cpp @@ -373,7 +373,6 @@ void STObject::add (Serializer& s, bool withSigningFields) const } } - typedef std::map::value_type field_iterator; for (auto const& mapEntry : fields) { // insert them in sorted order @@ -741,13 +740,13 @@ Blob STObject::getFieldVL (SField::ref field) const STAmount const& STObject::getFieldAmount (SField::ref field) const { - static STAmount const empty; + static STAmount const empty{}; return getFieldByConstRef (field, empty); } const STArray& STObject::getFieldArray (SField::ref field) const { - static STArray const empty; + static STArray const empty{}; return getFieldByConstRef (field, empty); } diff --git a/src/ripple/protocol/impl/STParsedJSON.cpp b/src/ripple/protocol/impl/STParsedJSON.cpp index 2e7194746b..abd0dffdfb 100644 --- a/src/ripple/protocol/impl/STParsedJSON.cpp +++ b/src/ripple/protocol/impl/STParsedJSON.cpp @@ -695,10 +695,8 @@ static bool parseObject ( boost::ptr_vector data; Json::Value::Members members (json.getMemberNames ()); - for (Json::Value::Members::iterator it (members.begin ()); - it != members.end (); ++it) + for (auto const& fieldName : members) { - std::string const& fieldName = *it; Json::Value const& value = json [fieldName]; SField::ref field = SField::getField (fieldName); diff --git a/src/ripple/protocol/impl/STPathSet.cpp b/src/ripple/protocol/impl/STPathSet.cpp index 72da163baf..83a5061116 100644 --- a/src/ripple/protocol/impl/STPathSet.cpp +++ b/src/ripple/protocol/impl/STPathSet.cpp @@ -50,37 +50,39 @@ STPathElement::get_hash (STPathElement const& element) return (hash_account ^ hash_currency ^ hash_issuer); } -STPathSet* STPathSet::construct (SerializerIterator& s, SField::ref name) +std::unique_ptr +STPathSet::deserialize (SerializerIterator& sit, SField::ref name) { - std::vector paths; std::vector path; + auto pathset = std::make_unique (name); + do { - int iType = s.get8 (); + int iType = sit.get8 (); if (iType == STPathElement::typeNone || iType == STPathElement::typeBoundary) { if (path.empty ()) { - WriteLog (lsINFO, STBase) << "STPathSet: Empty path."; - + WriteLog (lsINFO, STBase) + << "STPathSet: Empty path."; throw std::runtime_error ("empty path"); } - paths.push_back (path); + pathset->push_back (path); path.clear (); if (iType == STPathElement::typeNone) { - return new STPathSet (name, paths); + return std::move (pathset); } } else if (iType & ~STPathElement::typeAll) { WriteLog (lsINFO, STBase) - << "STPathSet: Bad path element: " << iType; + << "STPathSet: Bad path element: " << iType; throw std::runtime_error ("bad path element"); } @@ -95,13 +97,13 @@ STPathSet* STPathSet::construct (SerializerIterator& s, SField::ref name) Account issuer; if (hasAccount) - account.copyFrom (s.get160 ()); + account.copyFrom (sit.get160 ()); if (hasCurrency) - currency.copyFrom (s.get160 ()); + currency.copyFrom (sit.get160 ()); if (hasIssuer) - issuer.copyFrom (s.get160 ()); + issuer.copyFrom (sit.get160 ()); path.emplace_back (account, currency, issuer, hasCurrency); } @@ -109,13 +111,36 @@ STPathSet* STPathSet::construct (SerializerIterator& s, SField::ref name) while (1); } -bool STPathSet::isEquivalent (const STBase& t) const +bool +STPathSet::assembleAdd(STPath const& base, STPathElement const& tail) +{ // assemble base+tail and add it to the set if it's not a duplicate + value.push_back (base); + + std::vector::reverse_iterator it = value.rbegin (); + + STPath& newPath = *it; + newPath.push_back (tail); + + while (++it != value.rend ()) + { + if (*it == newPath) + { + value.pop_back (); + return false; + } + } + return true; +} + +bool +STPathSet::isEquivalent (const STBase& t) const { const STPathSet* v = dynamic_cast (&t); return v && (value == v->value); } -bool STPath::hasSeen ( +bool +STPath::hasSeen ( Account const& account, Currency const& currency, Account const& issuer) const { @@ -130,7 +155,8 @@ bool STPath::hasSeen ( return false; } -Json::Value STPath::getJson (int) const +Json::Value +STPath::getJson (int) const { Json::Value ret (Json::arrayValue); @@ -157,7 +183,8 @@ Json::Value STPath::getJson (int) const return ret; } -Json::Value STPathSet::getJson (int options) const +Json::Value +STPathSet::getJson (int options) const { Json::Value ret (Json::arrayValue); for (auto it: value) @@ -166,7 +193,8 @@ Json::Value STPathSet::getJson (int options) const return ret; } -void STPathSet::add (Serializer& s) const +void +STPathSet::add (Serializer& s) const { assert (fName->isBinary ()); assert (fName->fieldType == STI_PATHSET); diff --git a/src/ripple/protocol/impl/STVector256.cpp b/src/ripple/protocol/impl/STVector256.cpp index d2a175a62b..5bb113b547 100644 --- a/src/ripple/protocol/impl/STVector256.cpp +++ b/src/ripple/protocol/impl/STVector256.cpp @@ -22,56 +22,53 @@ #include #include #include -#include namespace ripple { -const STAmount saZero (noIssue(), 0u); -const STAmount saOne (noIssue(), 1u); - -// -// STVector256 -// - -// Return a new object from a SerializerIterator. -STVector256* STVector256::construct (SerializerIterator& u, SField::ref name) +std::unique_ptr +STVector256::deserialize (SerializerIterator& sit, SField::ref name) { - Blob data = u.getVL (); - Blob ::iterator begin = data.begin (); + auto vec = std::make_unique (name); - std::unique_ptr vec (new STVector256 (name)); + Blob data = sit.getVL (); + + auto const count = data.size () / (256 / 8); - int count = data.size () / (256 / 8); vec->mValue.reserve (count); - unsigned int uStart = 0; + Blob::iterator begin = data.begin (); + unsigned int uStart = 0; for (unsigned int i = 0; i != count; i++) { unsigned int uEnd = uStart + (256 / 8); - // This next line could be optimized to construct a default uint256 in the vector and then copy into it + // This next line could be optimized to construct a default uint256 + // in the vector and then copy into it vec->mValue.push_back (uint256 (Blob (begin + uStart, begin + uEnd))); uStart = uEnd; } - return vec.release (); + return std::move (vec); } -void STVector256::add (Serializer& s) const +void +STVector256::add (Serializer& s) const { assert (fName->isBinary ()); assert (fName->fieldType == STI_VECTOR256); s.addVL (mValue.empty () ? nullptr : mValue[0].begin (), mValue.size () * (256 / 8)); } -bool STVector256::isEquivalent (const STBase& t) const +bool +STVector256::isEquivalent (const STBase& t) const { const STVector256* v = dynamic_cast (&t); return v && (mValue == v->mValue); } -Json::Value STVector256::getJson (int) const +Json::Value +STVector256::getJson (int) const { Json::Value ret (Json::arrayValue); diff --git a/src/ripple/rpc/handlers/GetCounts.cpp b/src/ripple/rpc/handlers/GetCounts.cpp index 79665a719c..7fa00d44e9 100644 --- a/src/ripple/rpc/handlers/GetCounts.cpp +++ b/src/ripple/rpc/handlers/GetCounts.cpp @@ -23,7 +23,6 @@ #include #include #include -#include namespace ripple { @@ -43,7 +42,7 @@ Json::Value doGetCounts (RPC::Context& context) Json::Value ret (Json::objectValue); - BOOST_FOREACH (CountedObjects::Entry& it, objectCounts) + for (auto const& it : objectCounts) { ret [it.first] = it.second; } diff --git a/src/ripple/rpc/handlers/LogLevel.cpp b/src/ripple/rpc/handlers/LogLevel.cpp index 53ccb2f693..7a73f4a134 100644 --- a/src/ripple/rpc/handlers/LogLevel.cpp +++ b/src/ripple/rpc/handlers/LogLevel.cpp @@ -36,7 +36,7 @@ Json::Value doLogLevel (RPC::Context& context) std::vector< std::pair > logTable ( deprecatedLogs().partition_severities()); typedef std::map::value_type stringPair; - BOOST_FOREACH (const stringPair & it, logTable) + for (auto const& it : logTable) lev[it.first] = it.second; ret["levels"] = lev;