libdballe 9.6
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
10namespace dballe {
11namespace db {
12namespace v7 {
13
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
37std::ostream& operator<<(std::ostream&, const LevTrEntry&);
38
39struct 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
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;
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
Vertical level or layer.
Definition: types.h:625
Information on how a value has been sampled or computed with regards to time.
Definition: types.h:687
Definition: cache.h:47
Definition: cache.h:15
Trange trange
Time range.
Definition: cache.h:23
Level level
Vertical level or layer.
Definition: cache.h:20
Definition: cache.h:40
Common base types used by most of DB-All.e code.