libdballe  9.11
cache.h
1 #ifndef DBALLE_DB_V7_CACHE_H
2 #define DBALLE_DB_V7_CACHE_H
3 
4 #include <dballe/types.h>
5 #include <unordered_map>
6 #include <memory>
7 #include <vector>
8 #include <iosfwd>
9 
10 namespace dballe {
11 namespace db {
12 namespace v7 {
13 
14 struct LevTrEntry
15 {
16  // Database ID
17  int id = MISSING_INT;
18 
21 
24 
25  LevTrEntry() = default;
26  LevTrEntry(int id, const Level& level, const Trange& trange) : id(id), level(level), trange(trange) {}
27  LevTrEntry(const Level& level, const Trange& trange) : level(level), trange(trange) {}
28  LevTrEntry(const LevTrEntry&) = default;
29  LevTrEntry(LevTrEntry&&) = default;
30  LevTrEntry& operator=(const LevTrEntry&) = default;
31  LevTrEntry& operator=(LevTrEntry&&) = default;
32 
33  bool operator==(const LevTrEntry& o) const;
34  bool operator!=(const LevTrEntry& o) const;
35 };
36 
37 std::ostream& operator<<(std::ostream&, const LevTrEntry&);
38 
39 struct LevTrReverseIndex : public std::unordered_map<Level, std::vector<const LevTrEntry*>>
40 {
41  int find_id(const LevTrEntry& st) const;
42  void add(const LevTrEntry* st);
43 };
44 
45 
46 struct LevTrCache
47 {
48  std::unordered_map<int, LevTrEntry*> by_id;
49  LevTrReverseIndex reverse;
50 
51  LevTrCache() = default;
52  LevTrCache(const LevTrCache&) = delete;
53  LevTrCache(LevTrCache&&) = delete;
54  LevTrCache& operator=(const LevTrCache&) = delete;
55  LevTrCache& operator=(LevTrCache&&) = delete;
56  ~LevTrCache();
57 
58  const LevTrEntry* find_entry(int id) const;
59 
60  const LevTrEntry* insert(const LevTrEntry& e);
61  const LevTrEntry* insert(const LevTrEntry& e, int id);
62  const LevTrEntry* insert(std::unique_ptr<LevTrEntry> e);
63 
64  int find_id(const LevTrEntry& e) const;
65 
66  void clear();
67 };
68 
69 }
70 }
71 }
72 
73 #endif
Common base types used by most of DB-All.e code.
Definition: cache.h:39
Information on how a value has been sampled or computed with regards to time.
Definition: types.h:686
Definition: cmdline.h:18
Trange trange
Time range.
Definition: cache.h:23
Definition: cache.h:46
Vertical level or layer.
Definition: types.h:624
Definition: cache.h:14
Level level
Vertical level or layer.
Definition: cache.h:20