diff options
Diffstat (limited to 'src/db.h')
-rw-r--r-- | src/db.h | 33 |
1 files changed, 16 insertions, 17 deletions
@@ -54,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. @@ -66,7 +68,7 @@ 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(const std::string& strFile); @@ -74,7 +76,7 @@ public: 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); @@ -93,10 +95,10 @@ class CDB protected: Db* pdb; std::string strFile; - DbTxn *activeTxn; + DbTxn* activeTxn; bool fReadOnly; - explicit CDB(const std::string& strFilename, const char* pszMode="r+"); + explicit CDB(const std::string& strFilename, const char* pszMode = "r+"); ~CDB() { Close(); } public: @@ -108,7 +110,7 @@ private: void operator=(const CDB&); protected: - template<typename K, typename T> + template <typename K, typename T> bool Read(const K& key, T& value) { if (!pdb) @@ -132,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 (const std::exception &) { + } catch (const std::exception&) { return false; } @@ -143,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; @@ -172,7 +173,7 @@ protected: return (ret == 0); } - template<typename K> + template <typename K> bool Erase(const K& key) { if (!pdb) @@ -194,7 +195,7 @@ protected: return (ret == 0 || ret == DB_NOTFOUND); } - template<typename K> + template <typename K> bool Exists(const K& key) { if (!pdb) @@ -225,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()); } |