Ethereum  PoC-8
The C++ Implementation of Ethereum
LevelDB.h
Go to the documentation of this file.
1 /*
2  This file is part of cpp-ethereum.
3 
4  cpp-ethereum is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  cpp-ethereum is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
16 */
17 
18 #pragma once
19 
20 #include "db.h"
21 
22 #include <boost/filesystem.hpp>
23 #include <leveldb/db.h>
24 #include <leveldb/write_batch.h>
25 
26 namespace dev
27 {
28 namespace db
29 {
30 class LevelDB : public DatabaseFace
31 {
32 public:
33  static leveldb::ReadOptions defaultReadOptions();
34  static leveldb::WriteOptions defaultWriteOptions();
35  static leveldb::Options defaultDBOptions();
36 
37  explicit LevelDB(boost::filesystem::path const& _path,
38  leveldb::ReadOptions _readOptions = defaultReadOptions(),
39  leveldb::WriteOptions _writeOptions = defaultWriteOptions(),
40  leveldb::Options _dbOptions = defaultDBOptions());
41 
42  std::string lookup(Slice _key) const override;
43  bool exists(Slice _key) const override;
44  void insert(Slice _key, Slice _value) override;
45  void kill(Slice _key) override;
46 
47  std::unique_ptr<WriteBatchFace> createWriteBatch() const override;
48  void commit(std::unique_ptr<WriteBatchFace> _batch) override;
49 
50  void forEach(std::function<bool(Slice, Slice)> _f) const override;
51 
52 private:
53  std::unique_ptr<leveldb::DB> m_db;
54  leveldb::ReadOptions const m_readOptions;
55  leveldb::WriteOptions const m_writeOptions;
56 };
57 
58 } // namespace db
59 } // namespace dev
Definition: Address.cpp:20
static leveldb::Options defaultDBOptions()
Definition: LevelDB.cpp:95
void insert(Slice _key, Slice _value) override
Definition: LevelDB.cpp:139
LevelDB(boost::filesystem::path const &_path, leveldb::ReadOptions _readOptions=defaultReadOptions(), leveldb::WriteOptions _writeOptions=defaultWriteOptions(), leveldb::Options _dbOptions=defaultDBOptions())
Definition: LevelDB.cpp:103
bool exists(Slice _key) const override
Definition: LevelDB.cpp:127
static leveldb::ReadOptions defaultReadOptions()
Definition: LevelDB.cpp:85
void kill(Slice _key) override
Definition: LevelDB.cpp:147
void commit(std::unique_ptr< WriteBatchFace > _batch) override
Definition: LevelDB.cpp:159
std::string lookup(Slice _key) const override
Definition: LevelDB.cpp:115
std::unique_ptr< WriteBatchFace > createWriteBatch() const override
Definition: LevelDB.cpp:154
void forEach(std::function< bool(Slice, Slice)> _f) const override
Definition: LevelDB.cpp:175
static leveldb::WriteOptions defaultWriteOptions()
Definition: LevelDB.cpp:90