6 #ifndef ANONCOIN_LEVELDBWRAPPER_H
7 #define ANONCOIN_LEVELDBWRAPPER_H
14 #include <boost/filesystem/path.hpp>
15 #include <leveldb/db.h>
16 #include <leveldb/write_batch.h>
35 template<
typename K,
typename V>
void Write(
const K& key,
const V& value) {
39 leveldb::Slice slKey(&ssKey[0], ssKey.
size());
42 ssValue.reserve(ssValue.GetSerializeSize(value));
44 leveldb::Slice slValue(&ssValue[0], ssValue.size());
46 batch.Put(slKey, slValue);
49 template<
typename K>
void Erase(
const K& key) {
53 leveldb::Slice slKey(&ssKey[0], ssKey.
size());
84 CLevelDBWrapper(
const boost::filesystem::path &path,
size_t nCacheSize,
bool fMemory =
false,
bool fWipe =
false);
91 leveldb::Slice slKey(&ssKey[0], ssKey.
size());
94 leveldb::Status status = pdb->Get(readoptions, slKey, &strValue);
96 if (status.IsNotFound())
98 LogPrintf(
"LevelDB read failure: %s\n", status.ToString().c_str());
102 CDataStream ssValue(strValue.data(), strValue.data() + strValue.size(),
SER_DISK, CLIENT_VERSION);
104 }
catch(std::exception &e) {
110 template<
typename K,
typename V>
bool Write(
const K& key,
const V& value,
bool fSync =
false) throw(
leveldb_error) {
112 batch.
Write(key, value);
120 leveldb::Slice slKey(&ssKey[0], ssKey.
size());
122 std::string strValue;
123 leveldb::Status status = pdb->Get(readoptions, slKey, &strValue);
125 if (status.IsNotFound())
127 LogPrintf(
"LevelDB read failure: %s\n", status.ToString().c_str());
153 return pdb->NewIterator(iteroptions);
157 #endif // ANONCOIN_LEVELDBWRAPPER_H
bool Erase(const K &key, bool fSync=false)
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