Skip to content

Commit b7b48c8

Browse files
committed
Refactor: Remove using namespace <xxx> from src/*.cpp.
1 parent 9b4d267 commit b7b48c8

13 files changed

+179
-206
lines changed

src/bloom.cpp

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,21 @@
1919
#define LN2SQUARED 0.4804530139182014246671025263266649717305529515945455
2020
#define LN2 0.6931471805599453094172321214581765680755001343602552
2121

22-
using namespace std;
23-
2422
CBloomFilter::CBloomFilter(unsigned int nElements, double nFPRate, unsigned int nTweakIn, unsigned char nFlagsIn) :
2523
/**
2624
* The ideal size for a bloom filter with a given number of elements and false positive rate is:
2725
* - nElements * log(fp rate) / ln(2)^2
2826
* We ignore filter parameters which will create a bloom filter larger than the protocol limits
2927
*/
30-
vData(min((unsigned int)(-1 / LN2SQUARED * nElements * log(nFPRate)), MAX_BLOOM_FILTER_SIZE * 8) / 8),
28+
vData(std::min((unsigned int)(-1 / LN2SQUARED * nElements * log(nFPRate)), MAX_BLOOM_FILTER_SIZE * 8) / 8),
3129
/**
3230
* The ideal number of hash functions is filter size * ln(2) / number of elements
3331
* Again, we ignore filter parameters which will create a bloom filter with more hash functions than the protocol limits
3432
* See https://en.wikipedia.org/wiki/Bloom_filter for an explanation of these formulas
3533
*/
3634
isFull(false),
3735
isEmpty(true),
38-
nHashFuncs(min((unsigned int)(vData.size() * 8 / nElements * LN2), MAX_HASH_FUNCS)),
36+
nHashFuncs(std::min((unsigned int)(vData.size() * 8 / nElements * LN2), MAX_HASH_FUNCS)),
3937
nTweak(nTweakIn),
4038
nFlags(nFlagsIn)
4139
{
@@ -58,7 +56,7 @@ inline unsigned int CBloomFilter::Hash(unsigned int nHashNum, const std::vector<
5856
return MurmurHash3(nHashNum * 0xFBA4C795 + nTweak, vDataToHash) % (vData.size() * 8);
5957
}
6058

61-
void CBloomFilter::insert(const vector<unsigned char>& vKey)
59+
void CBloomFilter::insert(const std::vector<unsigned char>& vKey)
6260
{
6361
if (isFull)
6462
return;
@@ -75,17 +73,17 @@ void CBloomFilter::insert(const COutPoint& outpoint)
7573
{
7674
CDataStream stream(SER_NETWORK, PROTOCOL_VERSION);
7775
stream << outpoint;
78-
vector<unsigned char> data(stream.begin(), stream.end());
76+
std::vector<unsigned char> data(stream.begin(), stream.end());
7977
insert(data);
8078
}
8179

8280
void CBloomFilter::insert(const uint256& hash)
8381
{
84-
vector<unsigned char> data(hash.begin(), hash.end());
82+
std::vector<unsigned char> data(hash.begin(), hash.end());
8583
insert(data);
8684
}
8785

88-
bool CBloomFilter::contains(const vector<unsigned char>& vKey) const
86+
bool CBloomFilter::contains(const std::vector<unsigned char>& vKey) const
8987
{
9088
if (isFull)
9189
return true;
@@ -105,13 +103,13 @@ bool CBloomFilter::contains(const COutPoint& outpoint) const
105103
{
106104
CDataStream stream(SER_NETWORK, PROTOCOL_VERSION);
107105
stream << outpoint;
108-
vector<unsigned char> data(stream.begin(), stream.end());
106+
std::vector<unsigned char> data(stream.begin(), stream.end());
109107
return contains(data);
110108
}
111109

112110
bool CBloomFilter::contains(const uint256& hash) const
113111
{
114-
vector<unsigned char> data(hash.begin(), hash.end());
112+
std::vector<unsigned char> data(hash.begin(), hash.end());
115113
return contains(data);
116114
}
117115

@@ -154,7 +152,7 @@ bool CBloomFilter::IsRelevantAndUpdate(const CTransaction& tx)
154152
// This means clients don't have to update the filter themselves when a new relevant tx
155153
// is discovered in order to find spending transactions, which avoids round-tripping and race conditions.
156154
CScript::const_iterator pc = txout.scriptPubKey.begin();
157-
vector<unsigned char> data;
155+
std::vector<unsigned char> data;
158156
while (pc < txout.scriptPubKey.end())
159157
{
160158
opcodetype opcode;
@@ -168,7 +166,7 @@ bool CBloomFilter::IsRelevantAndUpdate(const CTransaction& tx)
168166
else if ((nFlags & BLOOM_UPDATE_MASK) == BLOOM_UPDATE_P2PUBKEY_ONLY)
169167
{
170168
txnouttype type;
171-
vector<vector<unsigned char> > vSolutions;
169+
std::vector<std::vector<unsigned char> > vSolutions;
172170
if (Solver(txout.scriptPubKey, type, vSolutions) &&
173171
(type == TX_PUBKEY || type == TX_MULTISIG))
174172
insert(COutPoint(hash, i));
@@ -189,7 +187,7 @@ bool CBloomFilter::IsRelevantAndUpdate(const CTransaction& tx)
189187

190188
// Match if the filter contains any arbitrary script data element in any scriptSig in tx
191189
CScript::const_iterator pc = txin.scriptSig.begin();
192-
vector<unsigned char> data;
190+
std::vector<unsigned char> data;
193191
while (pc < txin.scriptSig.end())
194192
{
195193
opcodetype opcode;
@@ -280,7 +278,7 @@ void CRollingBloomFilter::insert(const std::vector<unsigned char>& vKey)
280278

281279
void CRollingBloomFilter::insert(const uint256& hash)
282280
{
283-
vector<unsigned char> vData(hash.begin(), hash.end());
281+
std::vector<unsigned char> vData(hash.begin(), hash.end());
284282
insert(vData);
285283
}
286284

@@ -300,7 +298,7 @@ bool CRollingBloomFilter::contains(const std::vector<unsigned char>& vKey) const
300298

301299
bool CRollingBloomFilter::contains(const uint256& hash) const
302300
{
303-
vector<unsigned char> vData(hash.begin(), hash.end());
301+
std::vector<unsigned char> vData(hash.begin(), hash.end());
304302
return contains(vData);
305303
}
306304

src/chain.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55

66
#include "chain.h"
77

8-
using namespace std;
9-
108
/**
119
* CChain implementation
1210
*/

src/core_read.cpp

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,11 @@
2020
#include <boost/algorithm/string/split.hpp>
2121
#include <boost/assign/list_of.hpp>
2222

23-
using namespace std;
24-
2523
CScript ParseScript(const std::string& s)
2624
{
2725
CScript result;
2826

29-
static map<string, opcodetype> mapOpNames;
27+
static std::map<std::string, opcodetype> mapOpNames;
3028

3129
if (mapOpNames.empty())
3230
{
@@ -39,15 +37,15 @@ CScript ParseScript(const std::string& s)
3937
const char* name = GetOpName((opcodetype)op);
4038
if (strcmp(name, "OP_UNKNOWN") == 0)
4139
continue;
42-
string strName(name);
40+
std::string strName(name);
4341
mapOpNames[strName] = (opcodetype)op;
4442
// Convenience: OP_ADD and just ADD are both recognized:
4543
boost::algorithm::replace_first(strName, "OP_", "");
4644
mapOpNames[strName] = (opcodetype)op;
4745
}
4846
}
4947

50-
vector<string> words;
48+
std::vector<std::string> words;
5149
boost::algorithm::split(words, s, boost::algorithm::is_any_of(" \t\n"), boost::algorithm::token_compress_on);
5250

5351
for (std::vector<std::string>::const_iterator w = words.begin(); w != words.end(); ++w)
@@ -57,16 +55,16 @@ CScript ParseScript(const std::string& s)
5755
// Empty string, ignore. (boost::split given '' will return one word)
5856
}
5957
else if (all(*w, boost::algorithm::is_digit()) ||
60-
(boost::algorithm::starts_with(*w, "-") && all(string(w->begin()+1, w->end()), boost::algorithm::is_digit())))
58+
(boost::algorithm::starts_with(*w, "-") && all(std::string(w->begin()+1, w->end()), boost::algorithm::is_digit())))
6159
{
6260
// Number
6361
int64_t n = atoi64(*w);
6462
result << n;
6563
}
66-
else if (boost::algorithm::starts_with(*w, "0x") && (w->begin()+2 != w->end()) && IsHex(string(w->begin()+2, w->end())))
64+
else if (boost::algorithm::starts_with(*w, "0x") && (w->begin()+2 != w->end()) && IsHex(std::string(w->begin()+2, w->end())))
6765
{
6866
// Raw hex data, inserted NOT pushed onto stack:
69-
std::vector<unsigned char> raw = ParseHex(string(w->begin()+2, w->end()));
67+
std::vector<unsigned char> raw = ParseHex(std::string(w->begin()+2, w->end()));
7068
result.insert(result.end(), raw.begin(), raw.end());
7169
}
7270
else if (w->size() >= 2 && boost::algorithm::starts_with(*w, "'") && boost::algorithm::ends_with(*w, "'"))
@@ -83,7 +81,7 @@ CScript ParseScript(const std::string& s)
8381
}
8482
else
8583
{
86-
throw runtime_error("script parse error");
84+
throw std::runtime_error("script parse error");
8785
}
8886
}
8987

@@ -95,7 +93,7 @@ bool DecodeHexTx(CMutableTransaction& tx, const std::string& strHexTx, bool fTry
9593
if (!IsHex(strHexTx))
9694
return false;
9795

98-
vector<unsigned char> txData(ParseHex(strHexTx));
96+
std::vector<unsigned char> txData(ParseHex(strHexTx));
9997

10098
if (fTryNoWitness) {
10199
CDataStream ssData(txData, SER_NETWORK, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_NO_WITNESS);
@@ -138,9 +136,9 @@ bool DecodeHexBlk(CBlock& block, const std::string& strHexBlk)
138136
return true;
139137
}
140138

141-
uint256 ParseHashUV(const UniValue& v, const string& strName)
139+
uint256 ParseHashUV(const UniValue& v, const std::string& strName)
142140
{
143-
string strHex;
141+
std::string strHex;
144142
if (v.isStr())
145143
strHex = v.getValStr();
146144
return ParseHashStr(strHex, strName); // Note: ParseHashStr("") throws a runtime_error
@@ -149,19 +147,19 @@ uint256 ParseHashUV(const UniValue& v, const string& strName)
149147
uint256 ParseHashStr(const std::string& strHex, const std::string& strName)
150148
{
151149
if (!IsHex(strHex)) // Note: IsHex("") is false
152-
throw runtime_error(strName+" must be hexadecimal string (not '"+strHex+"')");
150+
throw std::runtime_error(strName + " must be hexadecimal string (not '" + strHex + "')");
153151

154152
uint256 result;
155153
result.SetHex(strHex);
156154
return result;
157155
}
158156

159-
vector<unsigned char> ParseHexUV(const UniValue& v, const string& strName)
157+
std::vector<unsigned char> ParseHexUV(const UniValue& v, const std::string& strName)
160158
{
161-
string strHex;
159+
std::string strHex;
162160
if (v.isStr())
163161
strHex = v.getValStr();
164162
if (!IsHex(strHex))
165-
throw runtime_error(strName+" must be hexadecimal string (not '"+strHex+"')");
163+
throw std::runtime_error(strName + " must be hexadecimal string (not '" + strHex + "')");
166164
return ParseHex(strHex);
167165
}

src/core_write.cpp

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,14 @@
1818
#include <boost/assign/list_of.hpp>
1919
#include <boost/foreach.hpp>
2020

21-
using namespace std;
22-
23-
string FormatScript(const CScript& script)
21+
std::string FormatScript(const CScript& script)
2422
{
25-
string ret;
23+
std::string ret;
2624
CScript::const_iterator it = script.begin();
2725
opcodetype op;
2826
while (it != script.end()) {
2927
CScript::const_iterator it2 = it;
30-
vector<unsigned char> vch;
28+
std::vector<unsigned char> vch;
3129
if (script.GetOp2(it, op, &vch)) {
3230
if (op == OP_0) {
3331
ret += "0 ";
@@ -36,9 +34,9 @@ string FormatScript(const CScript& script)
3634
ret += strprintf("%i ", op - OP_1NEGATE - 1);
3735
continue;
3836
} else if (op >= OP_NOP && op <= OP_NOP10) {
39-
string str(GetOpName(op));
40-
if (str.substr(0, 3) == string("OP_")) {
41-
ret += str.substr(3, string::npos) + " ";
37+
std::string str(GetOpName(op));
38+
if (str.substr(0, 3) == std::string("OP_")) {
39+
ret += str.substr(3, std::string::npos) + " ";
4240
continue;
4341
}
4442
}
@@ -55,14 +53,14 @@ string FormatScript(const CScript& script)
5553
return ret.substr(0, ret.size() - 1);
5654
}
5755

58-
const map<unsigned char, string> mapSigHashTypes =
56+
const std::map<unsigned char, std::string> mapSigHashTypes =
5957
boost::assign::map_list_of
60-
(static_cast<unsigned char>(SIGHASH_ALL), string("ALL"))
61-
(static_cast<unsigned char>(SIGHASH_ALL|SIGHASH_ANYONECANPAY), string("ALL|ANYONECANPAY"))
62-
(static_cast<unsigned char>(SIGHASH_NONE), string("NONE"))
63-
(static_cast<unsigned char>(SIGHASH_NONE|SIGHASH_ANYONECANPAY), string("NONE|ANYONECANPAY"))
64-
(static_cast<unsigned char>(SIGHASH_SINGLE), string("SINGLE"))
65-
(static_cast<unsigned char>(SIGHASH_SINGLE|SIGHASH_ANYONECANPAY), string("SINGLE|ANYONECANPAY"))
58+
(static_cast<unsigned char>(SIGHASH_ALL), std::string("ALL"))
59+
(static_cast<unsigned char>(SIGHASH_ALL|SIGHASH_ANYONECANPAY), std::string("ALL|ANYONECANPAY"))
60+
(static_cast<unsigned char>(SIGHASH_NONE), std::string("NONE"))
61+
(static_cast<unsigned char>(SIGHASH_NONE|SIGHASH_ANYONECANPAY), std::string("NONE|ANYONECANPAY"))
62+
(static_cast<unsigned char>(SIGHASH_SINGLE), std::string("SINGLE"))
63+
(static_cast<unsigned char>(SIGHASH_SINGLE|SIGHASH_ANYONECANPAY), std::string("SINGLE|ANYONECANPAY"))
6664
;
6765

6866
/**
@@ -72,11 +70,11 @@ const map<unsigned char, string> mapSigHashTypes =
7270
* of a signature. Only pass true for scripts you believe could contain signatures. For example,
7371
* pass false, or omit the this argument (defaults to false), for scriptPubKeys.
7472
*/
75-
string ScriptToAsmStr(const CScript& script, const bool fAttemptSighashDecode)
73+
std::string ScriptToAsmStr(const CScript& script, const bool fAttemptSighashDecode)
7674
{
77-
string str;
75+
std::string str;
7876
opcodetype opcode;
79-
vector<unsigned char> vch;
77+
std::vector<unsigned char> vch;
8078
CScript::const_iterator pc = script.begin();
8179
while (pc < script.end()) {
8280
if (!str.empty()) {
@@ -87,12 +85,12 @@ string ScriptToAsmStr(const CScript& script, const bool fAttemptSighashDecode)
8785
return str;
8886
}
8987
if (0 <= opcode && opcode <= OP_PUSHDATA4) {
90-
if (vch.size() <= static_cast<vector<unsigned char>::size_type>(4)) {
88+
if (vch.size() <= static_cast<std::vector<unsigned char>::size_type>(4)) {
9189
str += strprintf("%d", CScriptNum(vch, false).getint());
9290
} else {
9391
// the IsUnspendable check makes sure not to try to decode OP_RETURN data that may match the format of a signature
9492
if (fAttemptSighashDecode && !script.IsUnspendable()) {
95-
string strSigHashDecode;
93+
std::string strSigHashDecode;
9694
// goal: only attempt to decode a defined sighash type from data that looks like a signature within a scriptSig.
9795
// this won't decode correctly formatted public keys in Pubkey or Multisig scripts due to
9896
// the restrictions on the pubkey formats (see IsCompressedOrUncompressedPubKey) being incongruous with the
@@ -116,7 +114,7 @@ string ScriptToAsmStr(const CScript& script, const bool fAttemptSighashDecode)
116114
return str;
117115
}
118116

119-
string EncodeHexTx(const CTransaction& tx, const int serialFlags)
117+
std::string EncodeHexTx(const CTransaction& tx, const int serialFlags)
120118
{
121119
CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION | serialFlags);
122120
ssTx << tx;
@@ -127,7 +125,7 @@ void ScriptPubKeyToUniv(const CScript& scriptPubKey,
127125
UniValue& out, bool fIncludeHex)
128126
{
129127
txnouttype type;
130-
vector<CTxDestination> addresses;
128+
std::vector<CTxDestination> addresses;
131129
int nRequired;
132130

133131
out.pushKV("asm", ScriptToAsmStr(scriptPubKey));

0 commit comments

Comments
 (0)