From 8302bd5479dca9971409658ef9148bd61e1ae2b4 Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Wed, 16 Aug 2017 02:09:10 +0200 Subject: [PATCH] Merge #9964: Add const to methods that do not modify the object for which it is called 6e8c48dc5 Add const to methods that do not modify the object for which it is called (practicalswift) Pull request description: Tree-SHA512: a6888111ba16fb796e320e60806e1a77d36f545989b5405dc7319992291800109eab0b8e8c286b784778f41f1ff5289e7cb6b4afd7aec77f385fbcafc02cffc1 --- src/addrdb.h | 2 +- src/dbwrapper.cpp | 2 +- src/dbwrapper.h | 2 +- src/merkleblock.h | 2 +- src/miner.cpp | 2 +- src/miner.h | 2 +- src/qt/dash.cpp | 2 +- src/qt/modaloverlay.h | 2 +- src/qt/optionsmodel.cpp | 2 +- src/qt/optionsmodel.h | 14 +++++++------- src/qt/transactionrecord.cpp | 2 +- src/qt/transactionrecord.h | 2 +- src/qt/transactiontablemodel.h | 2 +- src/qt/walletmodeltransaction.cpp | 8 ++++---- src/qt/walletmodeltransaction.h | 8 ++++---- src/scheduler.h | 2 +- src/streams.h | 4 ++-- src/sync.h | 2 +- src/test/coins_tests.cpp | 4 ++-- src/test/prevector_tests.cpp | 4 ++-- src/test/script_tests.cpp | 2 +- src/txmempool.h | 2 +- 22 files changed, 37 insertions(+), 37 deletions(-) diff --git a/src/addrdb.h b/src/addrdb.h index 4e3b45c3f0950..4a13b29a0fa37 100644 --- a/src/addrdb.h +++ b/src/addrdb.h @@ -61,7 +61,7 @@ class CBanEntry banReason = BanReasonUnknown; } - std::string banReasonToString() + std::string banReasonToString() const { switch (banReason) { case BanReasonNodeMisbehaving: diff --git a/src/dbwrapper.cpp b/src/dbwrapper.cpp index 703388a4f87ef..ac2de20402807 100644 --- a/src/dbwrapper.cpp +++ b/src/dbwrapper.cpp @@ -190,7 +190,7 @@ bool CDBWrapper::IsEmpty() } CDBIterator::~CDBIterator() { delete piter; } -bool CDBIterator::Valid() { return piter->Valid(); } +bool CDBIterator::Valid() const { return piter->Valid(); } void CDBIterator::SeekToFirst() { piter->SeekToFirst(); } void CDBIterator::Next() { piter->Next(); } diff --git a/src/dbwrapper.h b/src/dbwrapper.h index 66efca4e4a450..670b31289f838 100644 --- a/src/dbwrapper.h +++ b/src/dbwrapper.h @@ -139,7 +139,7 @@ class CDBIterator parent(_parent), piter(_piter) { }; ~CDBIterator(); - bool Valid(); + bool Valid() const; void SeekToFirst(); diff --git a/src/merkleblock.h b/src/merkleblock.h index 8a974d4aaaea4..8e1a35e3de38e 100644 --- a/src/merkleblock.h +++ b/src/merkleblock.h @@ -63,7 +63,7 @@ class CPartialMerkleTree bool fBad; /** helper function to efficiently calculate the number of nodes at given height in the merkle tree */ - unsigned int CalcTreeWidth(int height) { + unsigned int CalcTreeWidth(int height) const { return (nTransactions+(1 << height)-1) >> height; } diff --git a/src/miner.cpp b/src/miner.cpp index 4911eaf5ae6b1..68aa079b33f59 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -260,7 +260,7 @@ void BlockAssembler::onlyUnconfirmed(CTxMemPool::setEntries& testSet) } } -bool BlockAssembler::TestPackage(uint64_t packageSize, unsigned int packageSigOps) +bool BlockAssembler::TestPackage(uint64_t packageSize, unsigned int packageSigOps) const { if (nBlockSize + packageSize >= nBlockMaxSize) return false; diff --git a/src/miner.h b/src/miner.h index 7d64d7f9fa355..4494d57126fbd 100644 --- a/src/miner.h +++ b/src/miner.h @@ -186,7 +186,7 @@ class BlockAssembler /** Remove confirmed (inBlock) entries from given set */ void onlyUnconfirmed(CTxMemPool::setEntries& testSet); /** Test if a new package would "fit" in the block */ - bool TestPackage(uint64_t packageSize, unsigned int packageSigOps); + bool TestPackage(uint64_t packageSize, unsigned int packageSigOps) const; /** Perform checks on each transaction in a package: * locktime * These checks should always succeed, and they're here diff --git a/src/qt/dash.cpp b/src/qt/dash.cpp index 99566e93410c7..41be48a1cf614 100644 --- a/src/qt/dash.cpp +++ b/src/qt/dash.cpp @@ -231,7 +231,7 @@ class BitcoinApplication: public QApplication void requestShutdown(); /// Get process return value - int getReturnValue() { return returnValue; } + int getReturnValue() const { return returnValue; } /// Get window identifier of QMainWindow (BitcoinGUI) WId getMainWinId() const; diff --git a/src/qt/modaloverlay.h b/src/qt/modaloverlay.h index d82983ea7dd4c..71cdadf410ecd 100644 --- a/src/qt/modaloverlay.h +++ b/src/qt/modaloverlay.h @@ -33,7 +33,7 @@ public Q_SLOTS: void showHide(bool hide = false, bool userRequested = false); void closeClicked(); void hideForever(); - bool isLayerVisible() { return layerIsVisible; } + bool isLayerVisible() const { return layerIsVisible; } protected: bool eventFilter(QObject * obj, QEvent * ev); diff --git a/src/qt/optionsmodel.cpp b/src/qt/optionsmodel.cpp index 155bea8a3a7c7..dc57e7781c086 100644 --- a/src/qt/optionsmodel.cpp +++ b/src/qt/optionsmodel.cpp @@ -576,7 +576,7 @@ void OptionsModel::setRestartRequired(bool fRequired) return settings.setValue("fRestartRequired", fRequired); } -bool OptionsModel::isRestartRequired() +bool OptionsModel::isRestartRequired() const { QSettings settings; return settings.value("fRestartRequired", false).toBool(); diff --git a/src/qt/optionsmodel.h b/src/qt/optionsmodel.h index 3dd4ff15167d7..fe80d9fdd4fe8 100644 --- a/src/qt/optionsmodel.h +++ b/src/qt/optionsmodel.h @@ -68,19 +68,19 @@ class OptionsModel : public QAbstractListModel void setDisplayUnit(const QVariant &value); /* Explicit getters */ - bool getHideTrayIcon() { return fHideTrayIcon; } - bool getMinimizeToTray() { return fMinimizeToTray; } - bool getMinimizeOnClose() { return fMinimizeOnClose; } - int getDisplayUnit() { return nDisplayUnit; } - QString getThirdPartyTxUrls() { return strThirdPartyTxUrls; } + bool getHideTrayIcon() const { return fHideTrayIcon; } + bool getMinimizeToTray() const { return fMinimizeToTray; } + bool getMinimizeOnClose() const { return fMinimizeOnClose; } + int getDisplayUnit() const { return nDisplayUnit; } + QString getThirdPartyTxUrls() const { return strThirdPartyTxUrls; } bool getProxySettings(QNetworkProxy& proxy) const; - bool getCoinControlFeatures() { return fCoinControlFeatures; } + bool getCoinControlFeatures() const { return fCoinControlFeatures; } bool getShowAdvancedPSUI() { return fShowAdvancedPSUI; } const QString& getOverriddenByCommandLine() { return strOverriddenByCommandLine; } /* Restart flag helper */ void setRestartRequired(bool fRequired); - bool isRestartRequired(); + bool isRestartRequired() const; bool resetSettings; private: diff --git a/src/qt/transactionrecord.cpp b/src/qt/transactionrecord.cpp index c2d180093e600..716b9a1ef3466 100644 --- a/src/qt/transactionrecord.cpp +++ b/src/qt/transactionrecord.cpp @@ -363,7 +363,7 @@ void TransactionRecord::updateStatus(const CWalletTx &wtx, int chainLockHeight) status.needsUpdate = false; } -bool TransactionRecord::statusUpdateNeeded(int chainLockHeight) +bool TransactionRecord::statusUpdateNeeded(int chainLockHeight) const { AssertLockHeld(cs_main); return status.cur_num_blocks != chainActive.Height() || status.needsUpdate diff --git a/src/qt/transactionrecord.h b/src/qt/transactionrecord.h index 309f3fd005f48..2b6c64c7e93a6 100644 --- a/src/qt/transactionrecord.h +++ b/src/qt/transactionrecord.h @@ -166,7 +166,7 @@ class TransactionRecord /** Return whether a status update is needed. */ - bool statusUpdateNeeded(int chainLockHeight); + bool statusUpdateNeeded(int chainLockHeight) const; }; #endif // BITCOIN_QT_TRANSACTIONRECORD_H diff --git a/src/qt/transactiontablemodel.h b/src/qt/transactiontablemodel.h index 3f2d3a2f4defe..62a8077f2e85a 100644 --- a/src/qt/transactiontablemodel.h +++ b/src/qt/transactiontablemodel.h @@ -86,7 +86,7 @@ class TransactionTableModel : public QAbstractTableModel QVariant data(const QModelIndex &index, int role) const; QVariant headerData(int section, Qt::Orientation orientation, int role) const; QModelIndex index(int row, int column, const QModelIndex & parent = QModelIndex()) const; - bool processingQueuedTransactions() { return fProcessingQueuedTransactions; } + bool processingQueuedTransactions() const { return fProcessingQueuedTransactions; } void updateChainLockHeight(int chainLockHeight); int getChainLockHeight() const; diff --git a/src/qt/walletmodeltransaction.cpp b/src/qt/walletmodeltransaction.cpp index a8a9feb4d08d8..d11c17ea0d3ee 100644 --- a/src/qt/walletmodeltransaction.cpp +++ b/src/qt/walletmodeltransaction.cpp @@ -21,12 +21,12 @@ WalletModelTransaction::~WalletModelTransaction() delete walletTransaction; } -QList WalletModelTransaction::getRecipients() +QList WalletModelTransaction::getRecipients() const { return recipients; } -CWalletTx *WalletModelTransaction::getTransaction() +CWalletTx *WalletModelTransaction::getTransaction() const { return walletTransaction; } @@ -36,7 +36,7 @@ unsigned int WalletModelTransaction::getTransactionSize() return (!walletTransaction ? 0 : (::GetSerializeSize(walletTransaction->tx, SER_NETWORK, PROTOCOL_VERSION))); } -CAmount WalletModelTransaction::getTransactionFee() +CAmount WalletModelTransaction::getTransactionFee() const { return fee; } @@ -85,7 +85,7 @@ void WalletModelTransaction::reassignAmounts() } } -CAmount WalletModelTransaction::getTotalTransactionAmount() +CAmount WalletModelTransaction::getTotalTransactionAmount() const { CAmount totalTransactionAmount = 0; for (const SendCoinsRecipient &rcp : recipients) diff --git a/src/qt/walletmodeltransaction.h b/src/qt/walletmodeltransaction.h index e3eabcc2abcc1..c21aec6997472 100644 --- a/src/qt/walletmodeltransaction.h +++ b/src/qt/walletmodeltransaction.h @@ -22,15 +22,15 @@ class WalletModelTransaction explicit WalletModelTransaction(const QList &recipients); ~WalletModelTransaction(); - QList getRecipients(); + QList getRecipients() const; - CWalletTx *getTransaction(); + CWalletTx *getTransaction() const; unsigned int getTransactionSize(); void setTransactionFee(const CAmount& newFee); - CAmount getTransactionFee(); + CAmount getTransactionFee() const; - CAmount getTotalTransactionAmount(); + CAmount getTotalTransactionAmount() const; void newPossibleKeyChange(CWallet *wallet); CReserveKey *getPossibleKeyChange(); diff --git a/src/scheduler.h b/src/scheduler.h index 0365d668b209b..cc2f01f2ffafe 100644 --- a/src/scheduler.h +++ b/src/scheduler.h @@ -81,7 +81,7 @@ class CScheduler int nThreadsServicingQueue; bool stopRequested; bool stopWhenEmpty; - bool shouldStop() { return stopRequested || (stopWhenEmpty && taskQueue.empty()); } + bool shouldStop() const { return stopRequested || (stopWhenEmpty && taskQueue.empty()); } }; /** diff --git a/src/streams.h b/src/streams.h index 88ae1fe740cb4..375d474bc5442 100644 --- a/src/streams.h +++ b/src/streams.h @@ -289,7 +289,7 @@ class CDataStream // bool eof() const { return size() == 0; } CDataStream* rdbuf() { return this; } - int in_avail() { return size(); } + int in_avail() const { return size(); } void SetType(int n) { nType = n; } int GetType() const { return nType; } @@ -605,7 +605,7 @@ class CBufferedFile } // return the current reading position - uint64_t GetPos() { + uint64_t GetPos() const { return nReadPos; } diff --git a/src/sync.h b/src/sync.h index 90ae3c9634a8d..864d427e1cef1 100644 --- a/src/sync.h +++ b/src/sync.h @@ -283,7 +283,7 @@ class CSemaphoreGrant Release(); } - operator bool() + operator bool() const { return fHaveGrant; } diff --git a/src/test/coins_tests.cpp b/src/test/coins_tests.cpp index 1dee71de46aa5..99c4f7428f1b2 100644 --- a/src/test/coins_tests.cpp +++ b/src/test/coins_tests.cpp @@ -89,8 +89,8 @@ class CCoinsViewCacheTest : public CCoinsViewCache BOOST_CHECK_EQUAL(DynamicMemoryUsage(), ret); } - CCoinsMap& map() { return cacheCoins; } - size_t& usage() { return cachedCoinsUsage; } + CCoinsMap& map() const { return cacheCoins; } + size_t& usage() const { return cachedCoinsUsage; } }; } // namespace diff --git a/src/test/prevector_tests.cpp b/src/test/prevector_tests.cpp index 4b6a29d988570..6baab42f1eb74 100644 --- a/src/test/prevector_tests.cpp +++ b/src/test/prevector_tests.cpp @@ -152,11 +152,11 @@ class prevector_tester { pre_vector.assign(n, value); } - Size size() { + Size size() const { return real_vector.size(); } - Size capacity() { + Size capacity() const { return pre_vector.capacity(); } diff --git a/src/test/script_tests.cpp b/src/test/script_tests.cpp index a80644d8ad914..71565ce5a5797 100644 --- a/src/test/script_tests.cpp +++ b/src/test/script_tests.cpp @@ -377,7 +377,7 @@ class TestBuilder return array; } - std::string GetComment() + std::string GetComment() const { return comment; } diff --git a/src/txmempool.h b/src/txmempool.h index e6b90e3481ad7..123a85d1df9d3 100644 --- a/src/txmempool.h +++ b/src/txmempool.h @@ -642,7 +642,7 @@ class CTxMemPool return mapTx.size(); } - uint64_t GetTotalTxSize() + uint64_t GetTotalTxSize() const { LOCK(cs); return totalTxSize;