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