 |
PRCYCoin
2.0.0.7rc1
P2P Digital Currency
|
Go to the documentation of this file.
5 #ifndef BITCOIN_DBWRAPPER_H
6 #define BITCOIN_DBWRAPPER_H
16 #include <leveldb/db.h>
17 #include <leveldb/write_batch.h>
48 template <
typename K,
typename V>
54 leveldb::Slice slKey(&ssKey[0], ssKey.
size());
59 leveldb::Slice slValue(&ssValue[0], ssValue.
size());
61 batch.Put(slKey, slValue);
70 leveldb::Slice slKey(&ssKey[0], ssKey.
size());
92 template<
typename K>
void Seek(
const K&
key) {
96 leveldb::Slice slKey(&ssKey[0], ssKey.
size());
103 leveldb::Slice slKey =
piter->key();
107 }
catch(std::exception &e) {
114 return piter->key().size();
118 leveldb::Slice slValue =
piter->value();
120 CDataStream ssValue(slValue.data(), slValue.data() + slValue.size(),
SER_DISK, CLIENT_VERSION);
122 }
catch(std::exception &e) {
129 return piter->value().size();
165 CDBWrapper(
const fs::path& path,
size_t nCacheSize,
bool fMemory =
false,
bool fWipe =
false);
168 template <
typename K,
typename V>
174 leveldb::Slice slKey(&ssKey[0], ssKey.
size());
176 std::string strValue;
179 if (status.IsNotFound())
181 LogPrintf(
"LevelDB read failure: %s\n", status.ToString());
185 CDataStream ssValue(strValue.data(), strValue.data() + strValue.size(),
SER_DISK, CLIENT_VERSION);
187 }
catch (
const std::exception&) {
193 template <
typename K,
typename V>
194 bool Write(
const K&
key,
const V& value,
bool fSync =
false)
201 template <
typename K>
207 leveldb::Slice slKey(&ssKey[0], ssKey.
size());
209 std::string strValue;
212 if (status.IsNotFound())
214 LogPrintf(
"LevelDB read failure: %s\n", status.ToString());
220 template <
typename K>
255 #endif // BITCOIN_DBWRAPPER_H
Batch of changes queued to be written to a CDBWrapper.
bool Read(const K &key, V &value) const
leveldb::ReadOptions readoptions
options used when reading from the database
leveldb::WriteOptions syncoptions
options used when sync writing to the database
CDBIterator(leveldb::Iterator *_piter)
void Write(const K &key, const V &value)
dbwrapper_error(const std::string &msg)
CDBIterator * NewIterator()
unsigned int GetKeySize()
leveldb::ReadOptions iteroptions
options used when iterating over values of the database
leveldb::Env * penv
custom environment this database is using (may be NULL in case of default environment)
leveldb::WriteBatch batch
leveldb::DB * pdb
the database itself
These should be considered an implementation detail of the specific database.
leveldb::Iterator * piter
bool Erase(const K &key, bool fSync=false)
void reserve(size_type n)
leveldb::WriteOptions writeoptions
options used when writing to the database
void HandleError(const leveldb::Status &status)
Handle database error by throwing dbwrapper_error exception.
leveldb::Options options
database options used
unsigned int GetValueSize()
CDBWrapper(const fs::path &path, size_t nCacheSize, bool fMemory=false, bool fWipe=false)
Double ended buffer combining vector and stream-like interfaces.
bool IsEmpty()
Return true if the database managed by this class contains no entries.
bool Write(const K &key, const V &value, bool fSync=false)
bool Exists(const K &key) const
unsigned int GetSerializeSize(const T &obj)
bool WriteBatch(CDBBatch &batch, bool fSync=false)