aboutsummaryrefslogtreecommitdiff
path: root/src/db.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/db.h')
-rw-r--r--src/db.h41
1 files changed, 22 insertions, 19 deletions
diff --git a/src/db.h b/src/db.h
index bba267b84..d20239938 100644
--- a/src/db.h
+++ b/src/db.h
@@ -15,12 +15,14 @@
#include <vector>
#include <boost/filesystem/path.hpp>
+
#include <db_cxx.h>
-struct CBlockLocator;
class CDiskBlockIndex;
class COutPoint;
+struct CBlockLocator;
+
extern unsigned int nWalletDBUpdated;
void ThreadFlushWalletDB(const std::string& strWalletFile);
@@ -52,7 +54,9 @@ public:
* This must be called BEFORE strFile is opened.
* Returns true if strFile is OK.
*/
- enum VerifyResult { VERIFY_OK, RECOVER_OK, RECOVER_FAIL };
+ enum VerifyResult { VERIFY_OK,
+ RECOVER_OK,
+ RECOVER_FAIL };
VerifyResult Verify(std::string strFile, bool (*recoverFunc)(CDBEnv& dbenv, std::string strFile));
/*
* Salvage data from a file that Verify says is bad.
@@ -64,15 +68,15 @@ public:
typedef std::pair<std::vector<unsigned char>, std::vector<unsigned char> > KeyValPair;
bool Salvage(std::string strFile, bool fAggressive, std::vector<KeyValPair>& vResult);
- bool Open(const boost::filesystem::path &path);
+ bool Open(const boost::filesystem::path& path);
void Close();
void Flush(bool fShutdown);
- void CheckpointLSN(std::string strFile);
+ void CheckpointLSN(const std::string& strFile);
void CloseDb(const std::string& strFile);
bool RemoveDb(const std::string& strFile);
- DbTxn *TxnBegin(int flags=DB_TXN_WRITE_NOSYNC)
+ DbTxn* TxnBegin(int flags = DB_TXN_WRITE_NOSYNC)
{
DbTxn* ptxn = NULL;
int ret = dbenv.txn_begin(NULL, &ptxn, flags);
@@ -91,20 +95,22 @@ class CDB
protected:
Db* pdb;
std::string strFile;
- DbTxn *activeTxn;
+ DbTxn* activeTxn;
bool fReadOnly;
- explicit CDB(const char* pszFile, const char* pszMode="r+");
+ explicit CDB(const std::string& strFilename, const char* pszMode = "r+");
~CDB() { Close(); }
+
public:
void Flush();
void Close();
+
private:
CDB(const CDB&);
void operator=(const CDB&);
protected:
- template<typename K, typename T>
+ template <typename K, typename T>
bool Read(const K& key, T& value)
{
if (!pdb)
@@ -128,8 +134,7 @@ protected:
try {
CDataStream ssValue((char*)datValue.get_data(), (char*)datValue.get_data() + datValue.get_size(), SER_DISK, CLIENT_VERSION);
ssValue >> value;
- }
- catch (std::exception &e) {
+ } catch (const std::exception&) {
return false;
}
@@ -139,8 +144,8 @@ protected:
return (ret == 0);
}
- template<typename K, typename T>
- bool Write(const K& key, const T& value, bool fOverwrite=true)
+ template <typename K, typename T>
+ bool Write(const K& key, const T& value, bool fOverwrite = true)
{
if (!pdb)
return false;
@@ -168,7 +173,7 @@ protected:
return (ret == 0);
}
- template<typename K>
+ template <typename K>
bool Erase(const K& key)
{
if (!pdb)
@@ -190,7 +195,7 @@ protected:
return (ret == 0 || ret == DB_NOTFOUND);
}
- template<typename K>
+ template <typename K>
bool Exists(const K& key)
{
if (!pdb)
@@ -221,18 +226,16 @@ protected:
return pcursor;
}
- int ReadAtCursor(Dbc* pcursor, CDataStream& ssKey, CDataStream& ssValue, unsigned int fFlags=DB_NEXT)
+ int ReadAtCursor(Dbc* pcursor, CDataStream& ssKey, CDataStream& ssValue, unsigned int fFlags = DB_NEXT)
{
// Read at cursor
Dbt datKey;
- if (fFlags == DB_SET || fFlags == DB_SET_RANGE || fFlags == DB_GET_BOTH || fFlags == DB_GET_BOTH_RANGE)
- {
+ if (fFlags == DB_SET || fFlags == DB_SET_RANGE || fFlags == DB_GET_BOTH || fFlags == DB_GET_BOTH_RANGE) {
datKey.set_data(&ssKey[0]);
datKey.set_size(ssKey.size());
}
Dbt datValue;
- if (fFlags == DB_GET_BOTH || fFlags == DB_GET_BOTH_RANGE)
- {
+ if (fFlags == DB_GET_BOTH || fFlags == DB_GET_BOTH_RANGE) {
datValue.set_data(&ssValue[0]);
datValue.set_size(ssValue.size());
}