Kagome
Polkadot Runtime Engine in C++17
readable.hpp
Go to the documentation of this file.
1 
6 #ifndef KAGOME_READABLE_HPP
7 #define KAGOME_READABLE_HPP
8 
9 #include <outcome/outcome.hpp>
10 
12 
13 namespace kagome::storage::face {
14 
15  template <typename K>
16  struct ReadableBase {
17  using Key = K;
18 
19  virtual ~ReadableBase() = default;
20 
26  virtual outcome::result<bool> contains(const Key &key) const = 0;
27 
31  virtual bool empty() const = 0;
32  };
33 
39  template <typename K, typename V>
40  struct ReadableMap : public ReadableBase<K> {
41  using Key = K;
42  using Value = V;
43  using ValueView = std::reference_wrapper<V>;
44  using ConstValueView = std::reference_wrapper<const V>;
45 
46  virtual ~ReadableMap() = default;
47 
53  virtual outcome::result<ConstValueView> get(const Key &key) const = 0;
54 
60  virtual outcome::result<std::optional<ConstValueView>> tryGet(
61  const Key &key) const = 0;
62  };
63 
64  template <typename K, typename V>
65  struct ReadableStorage : public ReadableBase<K> {
66  using Key = K;
67  using Value = V;
68 
69  virtual ~ReadableStorage() = default;
70 
76  virtual outcome::result<V> load(const Key &key) const = 0;
77 
83  virtual outcome::result<std::optional<V>> tryLoad(const Key &key) const = 0;
84  };
85 
86 } // namespace kagome::storage::face
87 
88 #endif // KAGOME_READABLE_HPP
Class represents arbitrary (including empty) byte buffer.
Definition: buffer.hpp:29
A mixin for read-only map.
Definition: readable.hpp:40
std::reference_wrapper< const Buffer > ConstValueView
Definition: readable.hpp:44
virtual bool empty() const =0
Returns true if the storage is empty.
virtual outcome::result< bool > contains(const Key &key) const =0
Checks if given key-value binding exists in the storage.