hyperledger/iroha
Iroha - A simple, decentralized ledger http://iroha.tech
flat_file.hpp
Go to the documentation of this file.
1 
6 #ifndef IROHA_FLAT_FILE_HPP
7 #define IROHA_FLAT_FILE_HPP
8 
10 
11 #include <memory>
12 #include <set>
13 
14 #include "logger/logger_fwd.hpp"
15 
16 namespace iroha {
17  namespace ametsuchi {
18 
22  class FlatFile : public KeyValueStorage {
27  struct private_tag {};
28 
29  public:
30  // ----------| public API |----------
31 
32  using BlockIdCollectionType = std::set<Identifier>;
33 
34  static const uint32_t DIGIT_CAPACITY = 16;
35 
48  static std::string id_to_name(Identifier id);
49 
55  static boost::optional<Identifier> name_to_id(const std::string &name);
56 
63  static boost::optional<std::unique_ptr<FlatFile>> create(
64  const std::string &path, logger::LoggerPtr log);
65 
66  bool add(Identifier id, const Bytes &blob) override;
67 
68  boost::optional<Bytes> get(Identifier id) const override;
69 
70  std::string directory() const override;
71 
72  Identifier last_id() const override;
73 
74  void dropAll() override;
75 
80 
81  // ----------| modify operations |----------
82 
83  FlatFile(const FlatFile &rhs) = delete;
84 
85  FlatFile(FlatFile &&rhs) = delete;
86 
87  FlatFile &operator=(const FlatFile &rhs) = delete;
88 
89  FlatFile &operator=(FlatFile &&rhs) = delete;
90 
91  // ----------| private API |----------
92 
99  FlatFile(std::string path,
100  BlockIdCollectionType existing_files,
101  FlatFile::private_tag,
102  logger::LoggerPtr log);
103 
104  private:
108  const std::string dump_dir_;
109 
110  BlockIdCollectionType available_blocks_;
111 
112  logger::LoggerPtr log_;
113 
114  public:
115  ~FlatFile() = default;
116  };
117  } // namespace ametsuchi
118 } // namespace iroha
119 #endif // IROHA_FLAT_FILE_HPP
FlatFile(const FlatFile &rhs)=delete
static std::string id_to_name(Identifier id)
Definition: flat_file.cpp:25
Identifier last_id() const override
Definition: flat_file.cpp:118
uint32_t Identifier
Definition: key_value_storage.hpp:25
std::set< Identifier > BlockIdCollectionType
Definition: flat_file.hpp:32
Definition: flat_file.hpp:22
std::shared_ptr< Logger > LoggerPtr
Definition: logger_fwd.hpp:22
std::vector< uint8_t > Bytes
Definition: key_value_storage.hpp:26
const BlockIdCollectionType & blockIdentifiers() const
Definition: flat_file.cpp:127
Definition: block_query.hpp:16
FlatFile & operator=(const FlatFile &rhs)=delete
std::string directory() const override
Definition: flat_file.cpp:114
static boost::optional< Identifier > name_to_id(const std::string &name)
Definition: flat_file.cpp:31
static boost::optional< std::unique_ptr< FlatFile > > create(const std::string &path, logger::LoggerPtr log)
Definition: flat_file.cpp:43
bool add(Identifier id, const Bytes &blob) override
Definition: flat_file.cpp:67
static const uint32_t DIGIT_CAPACITY
Definition: flat_file.hpp:34
void dropAll() override
Definition: flat_file.cpp:122
Definition: key_value_storage.hpp:20