rbpf/common/Store.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <stdint.h>
4 
5 namespace rBPF
6 {
7 class Store
8 {
9 public:
10  using Key = uint32_t;
11  using Value = uint32_t;
12 
13  class Entry
14  {
15  public:
16  explicit operator bool() const
17  {
18  return valid;
19  }
20 
22  {
23  valid = store.update(key, value);
24  return *this;
25  }
26 
27  operator Value() const
28  {
29  return store.get(key);
30  }
31 
32  private:
33  friend Store;
34 
35  Entry(Store& store, Key key) : store(store), key(key)
36  {
37  }
38 
39  Store& store;
40  Key key;
41  bool valid;
42  };
43 
50  virtual bool update(Key key, Value value) = 0;
51 
60  virtual bool fetch(Key key, Value& value) = 0;
61 
67  {
68  Value res;
69  fetch(key, res);
70  return res;
71  }
72 
74  {
75  return Entry(*this, key);
76  }
77 };
78 
79 } // namespace rBPF
void size_t const void * key
Definition: blake2s.h:33
Definition: rbpf/common/Store.h:14
Entry & operator=(Value value)
Definition: rbpf/common/Store.h:21
Definition: rbpf/common/Store.h:8
virtual bool update(Key key, Value value)=0
Update value in store.
uint32_t Key
Definition: rbpf/common/Store.h:10
virtual bool fetch(Key key, Value &value)=0
Fetch value from store.
Entry operator[](Key key)
Definition: rbpf/common/Store.h:73
uint32_t Value
Definition: rbpf/common/Store.h:11
Value get(Key key)
Fetch value from store.
Definition: rbpf/common/Store.h:66
Definition: bpf/rbpf/Store.h:7