|
|
@ -16,18 +16,18 @@ |
|
|
|
#include <leveldb/db.h> |
|
|
|
#include <leveldb/write_batch.h> |
|
|
|
|
|
|
|
class leveldb_error : public std::runtime_error |
|
|
|
class dbwrapper_error : public std::runtime_error |
|
|
|
{ |
|
|
|
public: |
|
|
|
leveldb_error(const std::string& msg) : std::runtime_error(msg) {} |
|
|
|
dbwrapper_error(const std::string& msg) : std::runtime_error(msg) {} |
|
|
|
}; |
|
|
|
|
|
|
|
void HandleError(const leveldb::Status& status); |
|
|
|
|
|
|
|
/** Batch of changes queued to be written to a CLevelDBWrapper */ |
|
|
|
class CLevelDBBatch |
|
|
|
/** Batch of changes queued to be written to a CDBWrapper */ |
|
|
|
class CDBBatch |
|
|
|
{ |
|
|
|
friend class CLevelDBWrapper; |
|
|
|
friend class CDBWrapper; |
|
|
|
|
|
|
|
private: |
|
|
|
leveldb::WriteBatch batch; |
|
|
@ -61,7 +61,7 @@ public: |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
class CLevelDBIterator |
|
|
|
class CDBIterator |
|
|
|
{ |
|
|
|
private: |
|
|
|
leveldb::Iterator *piter; |
|
|
@ -71,9 +71,9 @@ public: |
|
|
|
/**
|
|
|
|
* @param[in] piterIn The original leveldb iterator. |
|
|
|
*/ |
|
|
|
CLevelDBIterator(leveldb::Iterator *piterIn) : |
|
|
|
CDBIterator(leveldb::Iterator *piterIn) : |
|
|
|
piter(piterIn) { }; |
|
|
|
~CLevelDBIterator(); |
|
|
|
~CDBIterator(); |
|
|
|
|
|
|
|
bool Valid(); |
|
|
|
|
|
|
@ -121,7 +121,7 @@ public: |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
class CLevelDBWrapper |
|
|
|
class CDBWrapper |
|
|
|
{ |
|
|
|
private: |
|
|
|
//! custom environment this database is using (may be NULL in case of default environment)
|
|
|
@ -152,8 +152,8 @@ public: |
|
|
|
* @param[in] fMemory If true, use leveldb's memory environment. |
|
|
|
* @param[in] fWipe If true, remove all existing data. |
|
|
|
*/ |
|
|
|
CLevelDBWrapper(const boost::filesystem::path& path, size_t nCacheSize, bool fMemory = false, bool fWipe = false); |
|
|
|
~CLevelDBWrapper(); |
|
|
|
CDBWrapper(const boost::filesystem::path& path, size_t nCacheSize, bool fMemory = false, bool fWipe = false); |
|
|
|
~CDBWrapper(); |
|
|
|
|
|
|
|
template <typename K, typename V> |
|
|
|
bool Read(const K& key, V& value) const |
|
|
@ -183,7 +183,7 @@ public: |
|
|
|
template <typename K, typename V> |
|
|
|
bool Write(const K& key, const V& value, bool fSync = false) |
|
|
|
{ |
|
|
|
CLevelDBBatch batch; |
|
|
|
CDBBatch batch; |
|
|
|
batch.Write(key, value); |
|
|
|
return WriteBatch(batch, fSync); |
|
|
|
} |
|
|
@ -210,12 +210,12 @@ public: |
|
|
|
template <typename K> |
|
|
|
bool Erase(const K& key, bool fSync = false) |
|
|
|
{ |
|
|
|
CLevelDBBatch batch; |
|
|
|
CDBBatch batch; |
|
|
|
batch.Erase(key); |
|
|
|
return WriteBatch(batch, fSync); |
|
|
|
} |
|
|
|
|
|
|
|
bool WriteBatch(CLevelDBBatch& batch, bool fSync = false); |
|
|
|
bool WriteBatch(CDBBatch& batch, bool fSync = false); |
|
|
|
|
|
|
|
// not available for LevelDB; provide for compatibility with BDB
|
|
|
|
bool Flush() |
|
|
@ -225,13 +225,13 @@ public: |
|
|
|
|
|
|
|
bool Sync() |
|
|
|
{ |
|
|
|
CLevelDBBatch batch; |
|
|
|
CDBBatch batch; |
|
|
|
return WriteBatch(batch, true); |
|
|
|
} |
|
|
|
|
|
|
|
CLevelDBIterator *NewIterator() |
|
|
|
CDBIterator *NewIterator() |
|
|
|
{ |
|
|
|
return new CLevelDBIterator(pdb->NewIterator(iteroptions)); |
|
|
|
return new CDBIterator(pdb->NewIterator(iteroptions)); |
|
|
|
} |
|
|
|
|
|
|
|
/**
|
|
|
|