Merge #11351: Refactor: Modernize disallowed copy constructors/assignment

2a07f878a Refactor: Modernize disallowed copy constructors/assignment (Dan Raviv)

Pull request description:

  Use C++11's better capability of expressing an interface of a non-copyable class by publicly deleting its copy ctor and assignment operator instead of just declaring them private.

Tree-SHA512: 878f446be5a136bb2a90643aaeaca62948b575e6ef71ccc5b4b8f373e66f36ced00665128f36504e0ccfee639863d969329c4276154ef9f2a9de9137f0801e01
This commit is contained in:
Pieter Wuille 2017-09-21 22:33:06 -07:00 committed by Pasta
parent 6cf675807e
commit d6c4485412
7 changed files with 30 additions and 34 deletions

View File

@ -214,6 +214,11 @@ protected:
public: public:
CCoinsViewCache(CCoinsView *baseIn); CCoinsViewCache(CCoinsView *baseIn);
/**
* By deleting the copy constructor, we prevent accidentally using it when one intends to create a cache on top of a base cache.
*/
CCoinsViewCache(const CCoinsViewCache &) = delete;
// Standard CCoinsView methods // Standard CCoinsView methods
bool GetCoin(const COutPoint &outpoint, Coin &coin) const override; bool GetCoin(const COutPoint &outpoint, Coin &coin) const override;
bool HaveCoin(const COutPoint &outpoint) const override; bool HaveCoin(const COutPoint &outpoint) const override;
@ -290,11 +295,6 @@ public:
private: private:
CCoinsMap::iterator FetchCoin(const COutPoint &outpoint) const; CCoinsMap::iterator FetchCoin(const COutPoint &outpoint) const;
/**
* By making the copy constructor private, we prevent accidentally using it when one intends to create a cache on top of a base cache.
*/
CCoinsViewCache(const CCoinsViewCache &);
}; };
//! Utility function to add all of a transaction's outputs to a cache. //! Utility function to add all of a transaction's outputs to a cache.

View File

@ -895,13 +895,11 @@ public:
CNode(NodeId id, ServiceFlags nLocalServicesIn, int nMyStartingHeightIn, SOCKET hSocketIn, const CAddress &addrIn, uint64_t nKeyedNetGroupIn, uint64_t nLocalHostNonceIn, const CAddress &addrBindIn, const std::string &addrNameIn = "", bool fInboundIn = false); CNode(NodeId id, ServiceFlags nLocalServicesIn, int nMyStartingHeightIn, SOCKET hSocketIn, const CAddress &addrIn, uint64_t nKeyedNetGroupIn, uint64_t nLocalHostNonceIn, const CAddress &addrBindIn, const std::string &addrNameIn = "", bool fInboundIn = false);
~CNode(); ~CNode();
CNode(const CNode&) = delete;
CNode& operator=(const CNode&) = delete;
private: private:
CNode(const CNode&);
void operator=(const CNode&);
const NodeId id; const NodeId id;
const uint64_t nLocalHostNonce; const uint64_t nLocalHostNonce;
// Services offered to this peer // Services offered to this peer
const ServiceFlags nLocalServices; const ServiceFlags nLocalServices;

View File

@ -412,10 +412,6 @@ public:
class CAutoFile class CAutoFile
{ {
private: private:
// Disallow copies
CAutoFile(const CAutoFile&);
CAutoFile& operator=(const CAutoFile&);
const int nType; const int nType;
const int nVersion; const int nVersion;
@ -432,6 +428,10 @@ public:
fclose(); fclose();
} }
// Disallow copies
CAutoFile(const CAutoFile&) = delete;
CAutoFile& operator=(const CAutoFile&) = delete;
void fclose() void fclose()
{ {
if (file) { if (file) {
@ -521,10 +521,6 @@ public:
class CBufferedFile class CBufferedFile
{ {
private: private:
// Disallow copies
CBufferedFile(const CBufferedFile&);
CBufferedFile& operator=(const CBufferedFile&);
const int nType; const int nType;
const int nVersion; const int nVersion;
@ -566,6 +562,10 @@ public:
fclose(); fclose();
} }
// Disallow copies
CBufferedFile(const CBufferedFile&) = delete;
CBufferedFile& operator=(const CBufferedFile&) = delete;
int GetVersion() const { return nVersion; } int GetVersion() const { return nVersion; }
int GetType() const { return nType; } int GetType() const { return nType; }

View File

@ -50,6 +50,9 @@ public:
Arena(void *base, size_t size, size_t alignment); Arena(void *base, size_t size, size_t alignment);
virtual ~Arena(); virtual ~Arena();
Arena(const Arena& other) = delete; // non construction-copyable
Arena& operator=(const Arena&) = delete; // non copyable
/** Memory statistics. */ /** Memory statistics. */
struct Stats struct Stats
{ {
@ -85,9 +88,6 @@ public:
*/ */
bool addressInArena(void *ptr) const { return ptr >= base && ptr < end; } bool addressInArena(void *ptr) const { return ptr >= base && ptr < end; }
private: private:
Arena(const Arena& other) = delete; // non construction-copyable
Arena& operator=(const Arena&) = delete; // non copyable
/** Map of chunk address to chunk information. This class makes use of the /** Map of chunk address to chunk information. This class makes use of the
* sorted order to merge previous and next chunks during deallocation. * sorted order to merge previous and next chunks during deallocation.
*/ */
@ -153,6 +153,9 @@ public:
explicit LockedPool(std::unique_ptr<LockedPageAllocator> allocator, LockingFailed_Callback lf_cb_in = nullptr); explicit LockedPool(std::unique_ptr<LockedPageAllocator> allocator, LockingFailed_Callback lf_cb_in = nullptr);
~LockedPool(); ~LockedPool();
LockedPool(const LockedPool& other) = delete; // non construction-copyable
LockedPool& operator=(const LockedPool&) = delete; // non copyable
/** Allocate size bytes from this arena. /** Allocate size bytes from this arena.
* Returns pointer on success, or 0 if memory is full or * Returns pointer on success, or 0 if memory is full or
* the application tried to allocate 0 bytes. * the application tried to allocate 0 bytes.
@ -168,9 +171,6 @@ public:
/** Get pool usage statistics */ /** Get pool usage statistics */
Stats stats() const; Stats stats() const;
private: private:
LockedPool(const LockedPool& other) = delete; // non construction-copyable
LockedPool& operator=(const LockedPool&) = delete; // non copyable
std::unique_ptr<LockedPageAllocator> allocator; std::unique_ptr<LockedPageAllocator> allocator;
/** Create an arena from locked pages */ /** Create an arena from locked pages */

View File

@ -112,10 +112,10 @@ class CBlockTreeDB : public CDBWrapper
{ {
public: public:
explicit CBlockTreeDB(size_t nCacheSize, bool fMemory = false, bool fWipe = false); explicit CBlockTreeDB(size_t nCacheSize, bool fMemory = false, bool fWipe = false);
private:
CBlockTreeDB(const CBlockTreeDB&); CBlockTreeDB(const CBlockTreeDB&) = delete;
void operator=(const CBlockTreeDB&); CBlockTreeDB& operator=(const CBlockTreeDB&) = delete;
public:
bool WriteBatchSync(const std::vector<std::pair<int, const CBlockFileInfo*> >& fileInfo, int nLastFile, const std::vector<const CBlockIndex*>& blockinfo); bool WriteBatchSync(const std::vector<std::pair<int, const CBlockFileInfo*> >& fileInfo, int nLastFile, const std::vector<const CBlockIndex*>& blockinfo);
bool ReadBlockFileInfo(int nFile, CBlockFileInfo &fileinfo); bool ReadBlockFileInfo(int nFile, CBlockFileInfo &fileinfo);
bool ReadLastBlockFile(int &nFile); bool ReadLastBlockFile(int &nFile);

View File

@ -156,6 +156,9 @@ public:
explicit CDB(CWalletDBWrapper& dbw, const char* pszMode = "r+", bool fFlushOnCloseIn=true); explicit CDB(CWalletDBWrapper& dbw, const char* pszMode = "r+", bool fFlushOnCloseIn=true);
~CDB() { Close(); } ~CDB() { Close(); }
CDB(const CDB&) = delete;
CDB& operator=(const CDB&) = delete;
void Flush(); void Flush();
void Close(); void Close();
static bool Recover(const std::string& filename, void *callbackDataIn, bool (*recoverKVcallback)(void* callbackData, CDataStream ssKey, CDataStream ssValue), std::string& out_backup_filename); static bool Recover(const std::string& filename, void *callbackDataIn, bool (*recoverKVcallback)(void* callbackData, CDataStream ssKey, CDataStream ssValue), std::string& out_backup_filename);
@ -168,10 +171,6 @@ public:
/* verifies the database file */ /* verifies the database file */
static bool VerifyDatabaseFile(const std::string& walletFile, const fs::path& dataDir, std::string& warningStr, std::string& errorStr, CDBEnv::recoverFunc_type recoverFunc); static bool VerifyDatabaseFile(const std::string& walletFile, const fs::path& dataDir, std::string& warningStr, std::string& errorStr, CDBEnv::recoverFunc_type recoverFunc);
private:
CDB(const CDB&);
void operator=(const CDB&);
public: public:
template <typename K, typename T> template <typename K, typename T>
bool Read(const K& key, T& value) bool Read(const K& key, T& value)

View File

@ -122,6 +122,8 @@ public:
m_dbw(dbw) m_dbw(dbw)
{ {
} }
CWalletDB(const CWalletDB&) = delete;
CWalletDB& operator=(const CWalletDB&) = delete;
bool WriteName(const std::string& strAddress, const std::string& strName); bool WriteName(const std::string& strAddress, const std::string& strName);
bool EraseName(const std::string& strAddress); bool EraseName(const std::string& strAddress);
@ -203,9 +205,6 @@ public:
private: private:
CDB batch; CDB batch;
CWalletDBWrapper& m_dbw; CWalletDBWrapper& m_dbw;
CWalletDB(const CWalletDB&);
void operator=(const CWalletDB&);
}; };
//! Compacts BDB state so that wallet.dat is self-contained (if there are changes) //! Compacts BDB state so that wallet.dat is self-contained (if there are changes)