5 #ifndef BITCOIN_LEVELDBWRAPPER_H
6 #define BITCOIN_LEVELDBWRAPPER_H
12 #include <boost/filesystem/path.hpp>
13 #include <leveldb/db.h>
14 #include <leveldb/write_batch.h>
33 template<
typename K,
typename V>
void Write(
const K& key,
const V& value) {
37 leveldb::Slice slKey(&ssKey[0], ssKey.
size());
40 ssValue.reserve(ssValue.GetSerializeSize(value));
42 leveldb::Slice slValue(&ssValue[0], ssValue.size());
44 batch.Put(slKey, slValue);
47 template<
typename K>
void Erase(
const K& key) {
51 leveldb::Slice slKey(&ssKey[0], ssKey.
size());
82 CLevelDBWrapper(
const boost::filesystem::path &path,
size_t nCacheSize,
bool fMemory =
false,
bool fWipe =
false);
89 leveldb::Slice slKey(&ssKey[0], ssKey.
size());
92 leveldb::Status status = pdb->Get(readoptions, slKey, &strValue);
94 if (status.IsNotFound())
96 LogPrintf(
"LevelDB read failure: %s\n", status.ToString().c_str());
102 }
catch(std::exception &e) {
108 template<
typename K,
typename V>
bool Write(
const K& key,
const V& value,
bool fSync =
false) throw(
leveldb_error) {
110 batch.
Write(key, value);
118 leveldb::Slice slKey(&ssKey[0], ssKey.
size());
120 std::string strValue;
121 leveldb::Status status = pdb->Get(readoptions, slKey, &strValue);
123 if (status.IsNotFound())
125 LogPrintf(
"LevelDB read failure: %s\n", status.ToString().c_str());
151 return pdb->NewIterator(iteroptions);
155 #endif // BITCOIN_LEVELDBWRAPPER_H
bool Erase(const K &key, bool fSync=false)
static const int CLIENT_VERSION
bool Write(const K &key, const V &value, bool fSync=false)
Double ended buffer combining vector and stream-like interfaces.
leveldb::WriteOptions syncoptions
void Write(const K &key, const V &value)
bool Exists(const K &key)
leveldb::WriteBatch batch
CLevelDBWrapper(const boost::filesystem::path &path, size_t nCacheSize, bool fMemory=false, bool fWipe=false)
leveldb::WriteOptions writeoptions
leveldb::ReadOptions iteroptions
bool Read(const K &key, V &value)
bool WriteBatch(CLevelDBBatch &batch, bool fSync=false)
void reserve(size_type n)
unsigned int GetSerializeSize(const T &obj)
leveldb_error(const std::string &msg)
void HandleError(const leveldb::Status &status)
leveldb::Iterator * NewIterator()
leveldb::ReadOptions readoptions