From e4f7ffe99569208710923c6b095b53ea17f01238 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Tue, 28 Aug 2012 16:07:44 -0700 Subject: [PATCH] Some cleanups that should make Arthur happy. --- src/HashedObject.cpp | 12 +++++----- src/NetworkOPs.cpp | 42 +++++++++++++++------------------ src/SerializedObject.cpp | 33 +++++++++++--------------- src/SerializedTransaction.cpp | 7 +++--- src/TransactionEngine.cpp | 1 + src/TransactionMeta.cpp | 44 +++++++++++++++-------------------- src/ValidationCollection.cpp | 16 ++++++++----- 7 files changed, 73 insertions(+), 82 deletions(-) diff --git a/src/HashedObject.cpp b/src/HashedObject.cpp index 71730bfb19..fcbbee41bc 100644 --- a/src/HashedObject.cpp +++ b/src/HashedObject.cpp @@ -2,6 +2,7 @@ #include "HashedObject.h" #include +#include #include "Serializer.h" #include "Application.h" @@ -63,13 +64,12 @@ void HashedObjectStore::bulkWrite() db->executeSQL("BEGIN TRANSACTION;"); - for (std::vector< boost::shared_ptr >::iterator it = set.begin(), end = set.end(); it != end; ++it) + BOOST_FOREACH(const boost::shared_ptr& it, set) { - HashedObject& obj = **it; - if (!SQL_EXISTS(db, boost::str(fExists % obj.getHash().GetHex()))) + if (!SQL_EXISTS(db, boost::str(fExists % it->getHash().GetHex()))) { char type; - switch(obj.getType()) + switch(it->getType()) { case LEDGER: type = 'L'; break; case TRANSACTION: type = 'T'; break; @@ -78,8 +78,8 @@ void HashedObjectStore::bulkWrite() default: type = 'U'; } std::string rawData; - db->escape(&(obj.getData().front()), obj.getData().size(), rawData); - db->executeSQL(boost::str(fAdd % obj.getHash().GetHex() % type % obj.getIndex() % rawData )); + db->escape(&(it->getData().front()), it->getData().size(), rawData); + db->executeSQL(boost::str(fAdd % it->getHash().GetHex() % type % it->getIndex() % rawData )); } } diff --git a/src/NetworkOPs.cpp b/src/NetworkOPs.cpp index 40cd4cc856..32e0c61620 100644 --- a/src/NetworkOPs.cpp +++ b/src/NetworkOPs.cpp @@ -444,23 +444,23 @@ bool NetworkOPs::checkLastClosedLedger(const std::vector& peerLis ourVC.highNode = theApp->getWallet().getNodePublic(); } - for (std::vector::const_iterator it = peerList.begin(), end = peerList.end(); it != end; ++it) + BOOST_FOREACH(const Peer::pointer& it, peerList) { - if (!*it) + if (!it) { Log(lsDEBUG) << "NOP::CS Dead pointer in peer list"; } - else if ((*it)->isConnected()) + else if (it->isConnected()) { - uint256 peerLedger = (*it)->getClosedLedgerHash(); + uint256 peerLedger = it->getClosedLedgerHash(); if (peerLedger.isNonZero()) { ValidationCount& vc = ledgers[peerLedger]; - if ((vc.nodesUsing == 0) || ((*it)->getNodePublic() > vc.highNode)) - vc.highNode = (*it)->getNodePublic(); + if ((vc.nodesUsing == 0) || (it->getNodePublic() > vc.highNode)) + vc.highNode = it->getNodePublic(); ++vc.nodesUsing; } - else Log(lsTRACE) << "Connected peer announces no LCL " << (*it)->getIP(); + else Log(lsTRACE) << "Connected peer announces no LCL " << it->getIP(); } } @@ -522,23 +522,19 @@ bool NetworkOPs::checkLastClosedLedger(const std::vector& peerLis { // add more peers int count = 0; std::vector peers=theApp->getConnectionPool().getPeerVector(); - for (std::vector::const_iterator it = peerList.begin(), end = peerList.end(); - it != end; ++it) + BOOST_FOREACH(const Peer::pointer& it, peerList) { - if ((*it)->getClosedLedgerHash() == closedLedger) + if (it->getClosedLedgerHash() == closedLedger) { ++count; - mAcquiringLedger->peerHas(*it); + mAcquiringLedger->peerHas(it); } } if (!count) { // just ask everyone - for (std::vector::const_iterator it = peerList.begin(), end = peerList.end(); - it != end; ++it) - { - if ((*it)->isConnected()) - mAcquiringLedger->peerHas(*it); - } + BOOST_FOREACH(const Peer::pointer& it, peerList) + if (it->isConnected()) + mAcquiringLedger->peerHas(it); } return true; } @@ -678,12 +674,12 @@ void NetworkOPs::endConsensus(bool correctLCL) Log(lsTRACE) << "Ledger " << deadLedger.GetHex() << " is now dead"; theApp->getValidations().addDeadLedger(deadLedger); std::vector peerList = theApp->getConnectionPool().getPeerVector(); - for (std::vector::const_iterator it = peerList.begin(), end = peerList.end(); it != end; ++it) - if (*it && ((*it)->getClosedLedgerHash() == deadLedger)) - { - Log(lsTRACE) << "Killing obsolete peer status"; - (*it)->cycleStatus(); - } + BOOST_FOREACH(const Peer::pointer& it, peerList) + if (it && (it->getClosedLedgerHash() == deadLedger)) + { + Log(lsTRACE) << "Killing obsolete peer status"; + it->cycleStatus(); + } mConsensus = boost::shared_ptr(); } diff --git a/src/SerializedObject.cpp b/src/SerializedObject.cpp index 0f9af758e5..7600d803b7 100644 --- a/src/SerializedObject.cpp +++ b/src/SerializedObject.cpp @@ -185,15 +185,13 @@ std::string STObject::getFullText() const } else ret = "{"; - for (boost::ptr_vector::const_iterator it = mData.begin(), end = mData.end(); it != end; ++it) - { - if (it->getSType() != STI_NOTPRESENT) + BOOST_FOREACH(const SerializedType& it, mData) + if (it.getSType() != STI_NOTPRESENT) { if (!first) ret += ", "; else first = false; - ret += it->getFullText(); + ret += it.getFullText(); } - } ret += "}"; return ret; @@ -202,29 +200,29 @@ std::string STObject::getFullText() const int STObject::getLength() const { int ret = 0; - for (boost::ptr_vector::const_iterator it = mData.begin(), end = mData.end(); it != end; ++it) - ret += it->getLength(); + BOOST_FOREACH(const SerializedType& it, mData) + ret += it.getLength(); return ret; } void STObject::add(Serializer& s) const { - for (boost::ptr_vector::const_iterator it = mData.begin(), end = mData.end(); it != end; ++it) - it->add(s); + BOOST_FOREACH(const SerializedType& it, mData) + it.add(s); } std::string STObject::getText() const { std::string ret = "{"; bool first = false; - for (boost::ptr_vector::const_iterator it = mData.begin(), end = mData.end(); it != end; ++it) + BOOST_FOREACH(const SerializedType& it, mData) { if (!first) { ret += ", "; first = false; } - ret += it->getText(); + ret += it.getText(); } ret += "}"; return ret; @@ -654,14 +652,13 @@ Json::Value STObject::getJson(int options) const { Json::Value ret(Json::objectValue); int index = 1; - for(boost::ptr_vector::const_iterator it = mData.begin(), end = mData.end(); it != end; - ++it, ++index) + BOOST_FOREACH(const SerializedType& it, mData) { - if (it->getSType() != STI_NOTPRESENT) + if (it.getSType() != STI_NOTPRESENT) { - if (it->getName() == NULL) - ret[boost::lexical_cast(index)] = it->getJson(options); - else ret[it->getName()] = it->getJson(options); + if (it.getName() == NULL) + ret[boost::lexical_cast(index)] = it.getJson(options); + else ret[it.getName()] = it.getJson(options); } } return ret; @@ -672,9 +669,7 @@ Json::Value STVector256::getJson(int options) const Json::Value ret(Json::arrayValue); BOOST_FOREACH(std::vector::const_iterator::value_type vEntry, mValue) - { ret.append(vEntry.ToString()); - } return ret; } diff --git a/src/SerializedTransaction.cpp b/src/SerializedTransaction.cpp index bab0a4a9f5..0ee218028c 100644 --- a/src/SerializedTransaction.cpp +++ b/src/SerializedTransaction.cpp @@ -1,6 +1,8 @@ #include "SerializedTransaction.h" +#include + #include "Application.h" #include "Log.h" #include "HashPrefixes.h" @@ -83,10 +85,9 @@ std::vector SerializedTransaction::getAffectedAccounts() const std::vector accounts; accounts.push_back(mSourceAccount); - for(boost::ptr_vector::const_iterator it = mInnerTxn.peekData().begin(), - end = mInnerTxn.peekData().end(); it != end ; ++it) + BOOST_FOREACH(const SerializedType& it, mInnerTxn.peekData()) { - const STAccount* sa = dynamic_cast(&*it); + const STAccount* sa = dynamic_cast(&it); if (sa != NULL) { bool found = false; diff --git a/src/TransactionEngine.cpp b/src/TransactionEngine.cpp index df8a0c7082..ec277b2e4a 100644 --- a/src/TransactionEngine.cpp +++ b/src/TransactionEngine.cpp @@ -8,6 +8,7 @@ #include #include +#include #include #include "../json/writer.h" diff --git a/src/TransactionMeta.cpp b/src/TransactionMeta.cpp index 396f863f52..8a14cbbf14 100644 --- a/src/TransactionMeta.cpp +++ b/src/TransactionMeta.cpp @@ -4,6 +4,7 @@ #include #include +#include bool TransactionMetaNodeEntry::operator<(const TransactionMetaNodeEntry& e) const { @@ -167,27 +168,24 @@ void TransactionMetaNode::addRaw(Serializer& s) s.add8(mType); s.add256(mNode); mEntries.sort(); - for (boost::ptr_vector::const_iterator it = mEntries.begin(), end = mEntries.end(); - it != end; ++it) - it->addRaw(s); + BOOST_FOREACH(TransactionMetaNodeEntry& it, mEntries) + it.addRaw(s); s.add8(TMSEndOfNode); } TransactionMetaNodeEntry* TransactionMetaNode::findEntry(int nodeType) { - for (boost::ptr_vector::iterator it = mEntries.begin(), end = mEntries.end(); - it != end; ++it) - if (it->getType() == nodeType) - return &*it; + BOOST_FOREACH(TransactionMetaNodeEntry& it, mEntries) + if (it.getType() == nodeType) + return ⁢ return NULL; } TMNEAmount* TransactionMetaNode::findAmount(int nType) { - for (boost::ptr_vector::iterator it = mEntries.begin(), end = mEntries.end(); - it != end; ++it) - if (it->getType() == nType) - return dynamic_cast(&*it); + BOOST_FOREACH(TransactionMetaNodeEntry& it, mEntries) + if (it.getType() == nType) + return dynamic_cast(&it); TMNEAmount* node = new TMNEAmount(nType); mEntries.push_back(node); return node; @@ -200,9 +198,8 @@ void TransactionMetaNode::addNode(TransactionMetaNodeEntry* node) bool TransactionMetaNode::thread(const uint256& prevTx, uint32 prevLgr) { - for (boost::ptr_vector::iterator it = mEntries.begin(), end = mEntries.end(); - it != end; ++it) - if (it->getType() == TMSThread) + BOOST_FOREACH(TransactionMetaNodeEntry& it, mEntries) + if (it.getType() == TMSThread) return false; addNode(new TMNEThread(prevTx, prevLgr)); return true; @@ -210,11 +207,10 @@ bool TransactionMetaNode::thread(const uint256& prevTx, uint32 prevLgr) bool TransactionMetaNode::addAmount(int nodeType, const STAmount& amount) { - for (boost::ptr_vector::iterator it = mEntries.begin(), end = mEntries.end(); - it != end; ++it) - if (it->getType() == nodeType) + BOOST_FOREACH(TransactionMetaNodeEntry& it, mEntries) + if (it.getType() == nodeType) { - TMNEAmount* a = dynamic_cast(&*it); + TMNEAmount* a = dynamic_cast(&it); assert(a && (a->getAmount() == amount)); return false; } @@ -224,11 +220,10 @@ bool TransactionMetaNode::addAmount(int nodeType, const STAmount& amount) bool TransactionMetaNode::addAccount(int nodeType, const NewcoinAddress& account) { - for (boost::ptr_vector::iterator it = mEntries.begin(), end = mEntries.end(); - it != end; ++it) - if (it->getType() == nodeType) + BOOST_FOREACH(TransactionMetaNodeEntry& it, mEntries) + if (it.getType() == nodeType) { - TMNEAccount* a = dynamic_cast(&*it); + TMNEAccount* a = dynamic_cast(&it); assert(a && (a->getAccount() == account)); return false; } @@ -252,9 +247,8 @@ Json::Value TransactionMetaNode::getJson(int v) const ret["node"] = mNode.GetHex(); Json::Value e = Json::arrayValue; - for (boost::ptr_vector::const_iterator it = mEntries.begin(), end = mEntries.end(); - it != end; ++it) - e.append(it->getJson(v)); + BOOST_FOREACH(const TransactionMetaNodeEntry& it, mEntries) + e.append(it.getJson(v)); ret["entries"] = e; return ret; diff --git a/src/ValidationCollection.cpp b/src/ValidationCollection.cpp index 1bb971c576..0dee29b63e 100644 --- a/src/ValidationCollection.cpp +++ b/src/ValidationCollection.cpp @@ -1,6 +1,8 @@ #include "ValidationCollection.h" +#include + #include "Application.h" #include "LedgerTiming.h" #include "Log.h" @@ -192,8 +194,8 @@ boost::unordered_map ValidationCollection::getCurrentValidations() bool ValidationCollection::isDeadLedger(const uint256& ledger) { - for (std::list::iterator it = mDeadLedgers.begin(), end = mDeadLedgers.end(); it != end; ++it) - if (*it == ledger) + BOOST_FOREACH(const uint256& it, mDeadLedgers) + if (it == ledger) return true; return false; } @@ -259,10 +261,12 @@ void ValidationCollection::doWrite() ScopedLock dbl(theApp->getLedgerDB()->getDBLock()); Database *db = theApp->getLedgerDB()->getDB(); db->executeSQL("BEGIN TRANSACTION;"); - for (std::vector::iterator it = vector.begin(); it != vector.end(); ++it) - db->executeSQL(boost::str(insVal % (*it)->getLedgerHash().GetHex() - % (*it)->getSignerPublic().humanNodePublic() % (*it)->getFlags() % (*it)->getCloseTime() - % db->escape(strCopy((*it)->getSignature())))); + + + BOOST_FOREACH(const SerializedValidation::pointer& it, vector) + db->executeSQL(boost::str(insVal % it->getLedgerHash().GetHex() + % it->getSignerPublic().humanNodePublic() % it->getFlags() % it->getCloseTime() + % db->escape(strCopy(it->getSignature())))); db->executeSQL("END TRANSACTION;"); }