Skip to content

Commit 3de0126

Browse files
committed
Merge #10742: scripted-diff: Use scoped enumerations (C++11, "enum class")
1f45e21 scripted-diff: Convert 11 enums into scoped enums (C++11) (practicalswift) Pull request description: Rationale (from Bjarne Stroustrup's ["C++11 FAQ"](http://www.stroustrup.com/C++11FAQ.html#enum)): > > The enum classes ("new enums", "strong enums") address three problems with traditional C++ enumerations: > > * conventional enums implicitly convert to int, causing errors when someone does not want an enumeration to act as an integer. > * conventional enums export their enumerators to the surrounding scope, causing name clashes. > * the underlying type of an enum cannot be specified, causing confusion, compatibility problems, and makes forward declaration impossible. > > The new enums are "enum class" because they combine aspects of traditional enumerations (names values) with aspects of classes (scoped members and absence of conversions). Tree-SHA512: 9656e1cf4c3cabd4378c7a38d0c2eaf79e4a54d204a3c5762330840e55ee7e141e188a3efb2b4daf0ef3110bbaff80d8b9253abf2a9b015cdc4d60b49ac2b914
2 parents 68484d6 + 1f45e21 commit 3de0126

38 files changed

+295
-295
lines changed

src/bench/verify_script.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ static void VerifyScriptBench(benchmark::State& state)
7575
CMutableTransaction txSpend = BuildSpendingTransaction(scriptSig, txCredit);
7676
CScriptWitness& witness = txSpend.vin[0].scriptWitness;
7777
witness.stack.emplace_back();
78-
key.Sign(SignatureHash(witScriptPubkey, txSpend, 0, SIGHASH_ALL, txCredit.vout[0].nValue, SIGVERSION_WITNESS_V0), witness.stack.back(), 0);
78+
key.Sign(SignatureHash(witScriptPubkey, txSpend, 0, SIGHASH_ALL, txCredit.vout[0].nValue, SigVersion::WITNESS_V0), witness.stack.back(), 0);
7979
witness.stack.back().push_back(static_cast<unsigned char>(SIGHASH_ALL));
8080
witness.stack.push_back(ToByteVector(pubkey));
8181

src/bitcoind.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ bool AppInit(int argc, char* argv[])
7979
strUsage += "\n" + _("Usage:") + "\n" +
8080
" bitcoind [options] " + strprintf(_("Start %s Daemon"), _(PACKAGE_NAME)) + "\n";
8181

82-
strUsage += "\n" + HelpMessage(HMM_BITCOIND);
82+
strUsage += "\n" + HelpMessage(HelpMessageMode::BITCOIND);
8383
}
8484

8585
fprintf(stdout, "%s", strUsage.c_str());

src/init.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ std::string HelpMessage(HelpMessageMode mode)
338338
if (showDebug)
339339
strUsage += HelpMessageOpt("-blocksonly", strprintf(_("Whether to operate in a blocks only mode (default: %u)"), DEFAULT_BLOCKSONLY));
340340
strUsage += HelpMessageOpt("-conf=<file>", strprintf(_("Specify configuration file. Relative paths will be prefixed by datadir location. (default: %s)"), BITCOIN_CONF_FILENAME));
341-
if (mode == HMM_BITCOIND)
341+
if (mode == HelpMessageMode::BITCOIND)
342342
{
343343
#if HAVE_DECL_DAEMON
344344
strUsage += HelpMessageOpt("-daemon", _("Run in the background as a daemon and accept commands"));

src/init.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ bool AppInitLockDataDirectory();
5757
bool AppInitMain();
5858

5959
/** The help message mode determines what help message to show */
60-
enum HelpMessageMode {
61-
HMM_BITCOIND,
62-
HMM_BITCOIN_QT
60+
enum class HelpMessageMode {
61+
BITCOIND,
62+
BITCOIN_QT
6363
};
6464

6565
/** Help for options shared between UI and daemon (for -help) */

src/policy/fees.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class TxConfirmStats;
6868

6969
/* Identifier for each of the 3 different TxConfirmStats which will track
7070
* history over different time horizons. */
71-
enum FeeEstimateHorizon {
71+
enum class FeeEstimateHorizon {
7272
SHORT_HALFLIFE = 0,
7373
MED_HALFLIFE = 1,
7474
LONG_HALFLIFE = 2

src/policy/policy.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ bool AreInputsStandard(const CTransaction& tx, const CCoinsViewCache& mapInputs)
179179
{
180180
std::vector<std::vector<unsigned char> > stack;
181181
// convert the scriptSig into a stack, so we can inspect the redeemScript
182-
if (!EvalScript(stack, tx.vin[i].scriptSig, SCRIPT_VERIFY_NONE, BaseSignatureChecker(), SIGVERSION_BASE))
182+
if (!EvalScript(stack, tx.vin[i].scriptSig, SCRIPT_VERIFY_NONE, BaseSignatureChecker(), SigVersion::BASE))
183183
return false;
184184
if (stack.empty())
185185
return false;
@@ -215,7 +215,7 @@ bool IsWitnessStandard(const CTransaction& tx, const CCoinsViewCache& mapInputs)
215215
// If the scriptPubKey is P2SH, we try to extract the redeemScript casually by converting the scriptSig
216216
// into a stack. We do not check IsPushOnly nor compare the hash as these will be done later anyway.
217217
// If the check fails at this stage, we know that this txid must be a bad one.
218-
if (!EvalScript(stack, tx.vin[i].scriptSig, SCRIPT_VERIFY_NONE, BaseSignatureChecker(), SIGVERSION_BASE))
218+
if (!EvalScript(stack, tx.vin[i].scriptSig, SCRIPT_VERIFY_NONE, BaseSignatureChecker(), SigVersion::BASE))
219219
return false;
220220
if (stack.empty())
221221
return false;

src/policy/rbf.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ RBFTransactionState IsRBFOptIn(const CTransaction &tx, CTxMemPool &pool)
2222

2323
// First check the transaction itself.
2424
if (SignalsOptInRBF(tx)) {
25-
return RBF_TRANSACTIONSTATE_REPLACEABLE_BIP125;
25+
return RBFTransactionState::REPLACEABLE_BIP125;
2626
}
2727

2828
// If this transaction is not in our mempool, then we can't be sure
2929
// we will know about all its inputs.
3030
if (!pool.exists(tx.GetHash())) {
31-
return RBF_TRANSACTIONSTATE_UNKNOWN;
31+
return RBFTransactionState::UNKNOWN;
3232
}
3333

3434
// If all the inputs have nSequence >= maxint-1, it still might be
@@ -40,8 +40,8 @@ RBFTransactionState IsRBFOptIn(const CTransaction &tx, CTxMemPool &pool)
4040

4141
for (CTxMemPool::txiter it : setAncestors) {
4242
if (SignalsOptInRBF(it->GetTx())) {
43-
return RBF_TRANSACTIONSTATE_REPLACEABLE_BIP125;
43+
return RBFTransactionState::REPLACEABLE_BIP125;
4444
}
4545
}
46-
return RBF_TRANSACTIONSTATE_FINAL;
46+
return RBFTransactionState::FINAL;
4747
}

src/policy/rbf.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99

1010
static const uint32_t MAX_BIP125_RBF_SEQUENCE = 0xfffffffd;
1111

12-
enum RBFTransactionState {
13-
RBF_TRANSACTIONSTATE_UNKNOWN,
14-
RBF_TRANSACTIONSTATE_REPLACEABLE_BIP125,
15-
RBF_TRANSACTIONSTATE_FINAL
12+
enum class RBFTransactionState {
13+
UNKNOWN,
14+
REPLACEABLE_BIP125,
15+
FINAL
1616
};
1717

1818
// Check whether the sequence numbers on this transaction are signaling

src/qt/bitcoingui.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -799,25 +799,25 @@ void BitcoinGUI::setNumBlocks(int count, const QDateTime& blockDate, double nVer
799799
// Acquire current block source
800800
enum BlockSource blockSource = clientModel->getBlockSource();
801801
switch (blockSource) {
802-
case BLOCK_SOURCE_NETWORK:
802+
case BlockSource::NETWORK:
803803
if (header) {
804804
updateHeadersSyncProgressLabel();
805805
return;
806806
}
807807
progressBarLabel->setText(tr("Synchronizing with network..."));
808808
updateHeadersSyncProgressLabel();
809809
break;
810-
case BLOCK_SOURCE_DISK:
810+
case BlockSource::DISK:
811811
if (header) {
812812
progressBarLabel->setText(tr("Indexing blocks on disk..."));
813813
} else {
814814
progressBarLabel->setText(tr("Processing blocks on disk..."));
815815
}
816816
break;
817-
case BLOCK_SOURCE_REINDEX:
817+
case BlockSource::REINDEX:
818818
progressBarLabel->setText(tr("Reindexing blocks on disk..."));
819819
break;
820-
case BLOCK_SOURCE_NONE:
820+
case BlockSource::NONE:
821821
if (header) {
822822
return;
823823
}

src/qt/clientmodel.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,13 +177,13 @@ bool ClientModel::inInitialBlockDownload() const
177177
enum BlockSource ClientModel::getBlockSource() const
178178
{
179179
if (fReindex)
180-
return BLOCK_SOURCE_REINDEX;
180+
return BlockSource::REINDEX;
181181
else if (fImporting)
182-
return BLOCK_SOURCE_DISK;
182+
return BlockSource::DISK;
183183
else if (getNumConnections() > 0)
184-
return BLOCK_SOURCE_NETWORK;
184+
return BlockSource::NETWORK;
185185

186-
return BLOCK_SOURCE_NONE;
186+
return BlockSource::NONE;
187187
}
188188

189189
void ClientModel::setNetworkActive(bool active)

0 commit comments

Comments
 (0)