Skip to content

Commit

Permalink
Use C++11 default member initializers
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoFalke committed Jan 5, 2019
1 parent f7e182a commit fa2510d
Show file tree
Hide file tree
Showing 15 changed files with 35 additions and 82 deletions.
30 changes: 7 additions & 23 deletions src/addrman.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,33 +23,31 @@
*/
class CAddrInfo : public CAddress
{


public:
//! last try whatsoever by us (memory only)
int64_t nLastTry;
int64_t nLastTry{0};

//! last counted attempt (memory only)
int64_t nLastCountAttempt;
int64_t nLastCountAttempt{0};

private:
//! where knowledge about this address first came from
CNetAddr source;

//! last successful connection by us
int64_t nLastSuccess;
int64_t nLastSuccess{0};

//! connection attempts since last successful attempt
int nAttempts;
int nAttempts{0};

//! reference count in new sets (memory only)
int nRefCount;
int nRefCount{0};

//! in tried set? (memory only)
bool fInTried;
bool fInTried{false};

//! position in vRandom
int nRandomPos;
int nRandomPos{-1};

friend class CAddrMan;

Expand All @@ -65,25 +63,12 @@ class CAddrInfo : public CAddress
READWRITE(nAttempts);
}

void Init()
{
nLastSuccess = 0;
nLastTry = 0;
nLastCountAttempt = 0;
nAttempts = 0;
nRefCount = 0;
fInTried = false;
nRandomPos = -1;
}

CAddrInfo(const CAddress &addrIn, const CNetAddr &addrSource) : CAddress(addrIn), source(addrSource)
{
Init();
}

CAddrInfo() : CAddress(), source()
{
Init();
}

//! Calculate in which "tried" bucket this entry belongs
Expand All @@ -106,7 +91,6 @@ class CAddrInfo : public CAddress

//! Calculate the relative chance this entry should be given when selecting nodes to connect to
double GetChance(int64_t nNow = GetAdjustedTime()) const;

};

/** Stochastic address manager
Expand Down
1 change: 0 additions & 1 deletion src/httpserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ class WorkQueue

struct HTTPPathHandler
{
HTTPPathHandler() {}
HTTPPathHandler(std::string _prefix, bool _exactMatch, HTTPRequestHandler _handler):
prefix(_prefix), exactMatch(_exactMatch), handler(_handler)
{
Expand Down
8 changes: 0 additions & 8 deletions src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2317,14 +2317,6 @@ void CConnman::SetNetworkActive(bool active)

CConnman::CConnman(uint64_t nSeed0In, uint64_t nSeed1In) : nSeed0(nSeed0In), nSeed1(nSeed1In)
{
fNetworkActive = true;
setBannedIsDirty = false;
fAddressesInitialized = false;
nLastNodeId = 0;
nPrevNodeCount = 0;
nSendBufferMaxSize = 0;
nReceiveFloodSize = 0;
flagInterruptMsgProc = false;
SetTryNewOutboundPeer(false);

Options connOptions;
Expand Down
16 changes: 8 additions & 8 deletions src/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -404,15 +404,15 @@ class CConnman
// whitelisted (as well as those connecting to whitelisted binds).
std::vector<CSubNet> vWhitelistedRange;

unsigned int nSendBufferMaxSize;
unsigned int nReceiveFloodSize;
unsigned int nSendBufferMaxSize{0};
unsigned int nReceiveFloodSize{0};

std::vector<ListenSocket> vhListenSocket;
std::atomic<bool> fNetworkActive;
std::atomic<bool> fNetworkActive{true};
banmap_t setBanned GUARDED_BY(cs_setBanned);
CCriticalSection cs_setBanned;
bool setBannedIsDirty GUARDED_BY(cs_setBanned);
bool fAddressesInitialized;
bool setBannedIsDirty GUARDED_BY(cs_setBanned){false};
bool fAddressesInitialized{false};
CAddrMan addrman;
std::deque<std::string> vOneShots GUARDED_BY(cs_vOneShots);
CCriticalSection cs_vOneShots;
Expand All @@ -421,8 +421,8 @@ class CConnman
std::vector<CNode*> vNodes;
std::list<CNode*> vNodesDisconnected;
mutable CCriticalSection cs_vNodes;
std::atomic<NodeId> nLastNodeId;
unsigned int nPrevNodeCount;
std::atomic<NodeId> nLastNodeId{0};
unsigned int nPrevNodeCount{0};

/** Services this instance offers */
ServiceFlags nLocalServices;
Expand All @@ -446,7 +446,7 @@ class CConnman

std::condition_variable condMsgProc;
Mutex mutexMsgProc;
std::atomic<bool> flagInterruptMsgProc;
std::atomic<bool> flagInterruptMsgProc{false};

CThreadInterrupt interruptNet;

Expand Down
1 change: 0 additions & 1 deletion src/protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,6 @@ class CInv
std::string GetCommand() const;
std::string ToString() const;

// TODO: make private (improves encapsulation)
public:
int type;
uint256 hash;
Expand Down
6 changes: 2 additions & 4 deletions src/qt/bantablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ class BanTablePriv
public:
/** Local cache of peer information */
QList<CCombinedBan> cachedBanlist;
/** Column to sort nodes by */
int sortColumn;
/** Column to sort nodes by (default to unsorted) */
int sortColumn{-1};
/** Order (ascending or descending) to sort nodes by */
Qt::SortOrder sortOrder;

Expand Down Expand Up @@ -87,8 +87,6 @@ BanTableModel::BanTableModel(interfaces::Node& node, ClientModel *parent) :
{
columns << tr("IP/Netmask") << tr("Banned Until");
priv.reset(new BanTablePriv());
// default to unsorted
priv->sortColumn = -1;

// load initial data
refresh();
Expand Down
6 changes: 2 additions & 4 deletions src/qt/peertablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ class PeerTablePriv
public:
/** Local cache of peer information */
QList<CNodeCombinedStats> cachedNodeStats;
/** Column to sort nodes by */
int sortColumn;
/** Column to sort nodes by (default to unsorted) */
int sortColumn{-1};
/** Order (ascending or descending) to sort nodes by */
Qt::SortOrder sortOrder;
/** Index of rows by node ID */
Expand Down Expand Up @@ -108,8 +108,6 @@ PeerTableModel::PeerTableModel(interfaces::Node& node, ClientModel *parent) :
{
columns << tr("NodeId") << tr("Node/Service") << tr("Ping") << tr("Sent") << tr("Received") << tr("User Agent");
priv.reset(new PeerTablePriv());
// default to unsorted
priv->sortColumn = -1;

// set up timer for auto refresh
timer = new QTimer(this);
Expand Down
2 changes: 0 additions & 2 deletions src/qt/recentrequeststablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
RecentRequestsTableModel::RecentRequestsTableModel(WalletModel *parent) :
QAbstractTableModel(parent), walletModel(parent)
{
nReceiveRequestsMaxId = 0;

// Load entries from wallet
std::vector<std::string> vReceiveRequests;
parent->loadReceiveRequests(vReceiveRequests);
Expand Down
2 changes: 1 addition & 1 deletion src/qt/recentrequeststablemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public Q_SLOTS:
WalletModel *walletModel;
QStringList columns;
QList<RecentRequestEntry> list;
int64_t nReceiveRequestsMaxId;
int64_t nReceiveRequestsMaxId{0};

/** Updates the column title to "Amount (DisplayUnit)" and emits headerDataChanged() signal for table headers to react. */
void updateAmountColumnTitle();
Expand Down
2 changes: 0 additions & 2 deletions src/qt/walletmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ WalletModel::WalletModel(std::unique_ptr<interfaces::Wallet> wallet, interfaces:
cachedNumBlocks(0)
{
fHaveWatchOnly = m_wallet->haveWatchOnly();
fForceCheckBalanceChanged = false;

addressTableModel = new AddressTableModel(this);
transactionTableModel = new TransactionTableModel(platformStyle, this);
recentRequestsTableModel = new RecentRequestsTableModel(this);
Expand Down
2 changes: 1 addition & 1 deletion src/qt/walletmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ class WalletModel : public QObject
interfaces::Node& m_node;

bool fHaveWatchOnly;
bool fForceCheckBalanceChanged;
bool fForceCheckBalanceChanged{false};

// Wallet has an options model for wallet-specific options
// (transaction fee, for example)
Expand Down
4 changes: 0 additions & 4 deletions src/test/addrman_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,9 @@

class CAddrManTest : public CAddrMan
{
uint64_t state;

public:
explicit CAddrManTest(bool makeDeterministic = true)
{
state = 1;

if (makeDeterministic) {
// Set addrman addr placement to be deterministic.
MakeDeterministic();
Expand Down
9 changes: 3 additions & 6 deletions src/wallet/rpcwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1020,15 +1020,12 @@ static UniValue addmultisigaddress(const JSONRPCRequest& request)

struct tallyitem
{
CAmount nAmount;
int nConf;
CAmount nAmount{0};
int nConf{std::numeric_limits<int>::max()};
std::vector<uint256> txids;
bool fIsWatchonly;
bool fIsWatchonly{false};
tallyitem()
{
nAmount = 0;
nConf = std::numeric_limits<int>::max();
fIsWatchonly = false;
}
};

Expand Down
8 changes: 3 additions & 5 deletions src/wallet/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -1178,18 +1178,16 @@ class CReserveKey final : public CReserveScript
{
protected:
CWallet* pwallet;
int64_t nIndex;
int64_t nIndex{-1};
CPubKey vchPubKey;
bool fInternal;
bool fInternal{false};

public:
explicit CReserveKey(CWallet* pwalletIn)
{
nIndex = -1;
pwallet = pwalletIn;
fInternal = false;
}

CReserveKey() = default;
CReserveKey(const CReserveKey&) = delete;
CReserveKey& operator=(const CReserveKey&) = delete;

Expand Down
20 changes: 8 additions & 12 deletions src/wallet/walletdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,21 +153,17 @@ bool WalletBatch::WriteMinVersion(int nVersion)

class CWalletScanState {
public:
unsigned int nKeys;
unsigned int nCKeys;
unsigned int nWatchKeys;
unsigned int nKeyMeta;
unsigned int m_unknown_records;
bool fIsEncrypted;
bool fAnyUnordered;
int nFileVersion;
unsigned int nKeys{0};
unsigned int nCKeys{0};
unsigned int nWatchKeys{0};
unsigned int nKeyMeta{0};
unsigned int m_unknown_records{0};
bool fIsEncrypted{false};
bool fAnyUnordered{false};
int nFileVersion{0};
std::vector<uint256> vWalletUpgrade;

CWalletScanState() {
nKeys = nCKeys = nWatchKeys = nKeyMeta = m_unknown_records = 0;
fIsEncrypted = false;
fAnyUnordered = false;
nFileVersion = 0;
}
};

Expand Down

0 comments on commit fa2510d

Please sign in to comment.