Ethereum  PoC-8
The C++ Implementation of Ethereum
db.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 */
22 #pragma once
23 
24 #include "Exceptions.h"
25 #include "dbfwd.h"
26 
27 #include <memory>
28 #include <string>
29 
30 namespace dev
31 {
32 namespace db
33 {
34 // WriteBatchFace implements database write batch for a specific concrete
35 // database implementation.
37 {
38 public:
39  virtual ~WriteBatchFace() = default;
40 
41  virtual void insert(Slice _key, Slice _value) = 0;
42  virtual void kill(Slice _key) = 0;
43 
44 protected:
45  WriteBatchFace() = default;
46  // Noncopyable
47  WriteBatchFace(WriteBatchFace const&) = delete;
49  // Nonmovable
52 };
53 
55 {
56 public:
57  virtual ~DatabaseFace() = default;
58  virtual std::string lookup(Slice _key) const = 0;
59  virtual bool exists(Slice _key) const = 0;
60  virtual void insert(Slice _key, Slice _value) = 0;
61  virtual void kill(Slice _key) = 0;
62 
63  virtual std::unique_ptr<WriteBatchFace> createWriteBatch() const = 0;
64  virtual void commit(std::unique_ptr<WriteBatchFace> _batch) = 0;
65 
66  // A database must implement the `forEach` method that allows the caller
67  // to pass in a function `f`, which will be called with the key and value
68  // of each record in the database. If `f` returns false, the `forEach`
69  // method must return immediately.
70  virtual void forEach(std::function<bool(Slice, Slice)> f) const = 0;
71 };
72 
73 DEV_SIMPLE_EXCEPTION(DatabaseError);
74 
75 enum class DatabaseStatus
76 {
77  Ok,
78  NotFound,
79  Corruption,
82  IOError,
83  Unknown
84 };
85 
86 using errinfo_dbStatusCode = boost::error_info<struct tag_dbStatusCode, DatabaseStatus>;
87 using errinfo_dbStatusString = boost::error_info<struct tag_dbStatusString, std::string>;
88 
89 } // namespace db
90 } // namespace dev
dev::vector_ref
Definition: vector_ref.h:22
dev::db::DatabaseStatus::NotSupported
@ NotSupported
dev::db::errinfo_dbStatusCode
boost::error_info< struct tag_dbStatusCode, DatabaseStatus > errinfo_dbStatusCode
Definition: db.h:86
dev::db::WriteBatchFace::operator=
WriteBatchFace & operator=(WriteBatchFace const &)=delete
dev::db::DatabaseFace::commit
virtual void commit(std::unique_ptr< WriteBatchFace > _batch)=0
dev::db::errinfo_dbStatusString
boost::error_info< struct tag_dbStatusString, std::string > errinfo_dbStatusString
Definition: db.h:87
dev::db::DatabaseStatus::Unknown
@ Unknown
dev::db::WriteBatchFace::WriteBatchFace
WriteBatchFace()=default
Exceptions.h
dev::db::DatabaseStatus::Corruption
@ Corruption
dev::db::WriteBatchFace::kill
virtual void kill(Slice _key)=0
dev::db::WriteBatchFace::~WriteBatchFace
virtual ~WriteBatchFace()=default
dev::db::DatabaseStatus::Ok
@ Ok
dev::db::DatabaseFace::~DatabaseFace
virtual ~DatabaseFace()=default
dev::db::DatabaseStatus::NotFound
@ NotFound
dev::db::DatabaseStatus::IOError
@ IOError
dev::db::DEV_SIMPLE_EXCEPTION
DEV_SIMPLE_EXCEPTION(DatabaseError)
dev::db::DatabaseFace::lookup
virtual std::string lookup(Slice _key) const =0
dev::db::DatabaseFace
Definition: db.h:55
dev::db::DatabaseFace::createWriteBatch
virtual std::unique_ptr< WriteBatchFace > createWriteBatch() const =0
dev::db::DatabaseStatus
DatabaseStatus
Definition: db.h:76
dev::db::DatabaseFace::forEach
virtual void forEach(std::function< bool(Slice, Slice)> f) const =0
dev::db::WriteBatchFace::operator=
WriteBatchFace & operator=(WriteBatchFace &&)=delete
dev::db::WriteBatchFace
Definition: db.h:37
dev
Definition: Address.cpp:21
dev::db::DatabaseFace::insert
virtual void insert(Slice _key, Slice _value)=0
dev::db::DatabaseFace::kill
virtual void kill(Slice _key)=0
dev::db::WriteBatchFace::WriteBatchFace
WriteBatchFace(WriteBatchFace &&)=delete
dev::db::DatabaseFace::exists
virtual bool exists(Slice _key) const =0
dev::db::WriteBatchFace::WriteBatchFace
WriteBatchFace(WriteBatchFace const &)=delete
dev::db::DatabaseStatus::InvalidArgument
@ InvalidArgument
dbfwd.h
dev::db::WriteBatchFace::insert
virtual void insert(Slice _key, Slice _value)=0