libdballe  7.29
v6/levtr.h
1 #ifndef DBALLE_DB_V6_LEVTR_H
2 #define DBALLE_DB_V6_LEVTR_H
3 
4 #include <dballe/core/defs.h>
5 #include <memory>
6 #include <cstdio>
7 #include <functional>
8 
9 namespace dballe {
10 struct Record;
11 struct Msg;
12 
13 namespace msg {
14 struct Context;
15 }
16 
17 namespace db {
18 namespace v6 {
19 
23 struct LevTr
24 {
25  struct DBRow
26  {
28  int id;
30  int ltype1;
32  int l1;
34  int ltype2;
36  int l2;
38  int pind;
40  int p1;
42  int p2;
43  };
44 
45  virtual ~LevTr();
46 
51  virtual int obtain_id(const Level& lev, const Trange& tr) = 0;
52 
54  virtual const DBRow* read(int id) = 0;
55 
57  virtual void read_all(std::function<void(const DBRow&)> dest) = 0;
58 
60  virtual void dump(FILE* out) = 0;
61 };
62 
63 struct LevTrCache
64 {
65  virtual ~LevTrCache();
66 
72  virtual bool to_rec(int id, Record& rec) = 0;
73 
75  virtual Level to_level(int id) const = 0;
76 
78  virtual Trange to_trange(int id) const = 0;
79 
85  virtual msg::Context* to_msg(int id, Msg& msg) = 0;
86 
88  virtual void invalidate() = 0;
89 
91  virtual void dump(FILE* out) const = 0;
92 
94  static std::unique_ptr<LevTrCache> create(LevTr& levtr);
95 };
96 
97 }
98 }
99 }
100 
101 #endif
102 
Store an array of physical data all on the same level.
Definition: context.h:44
int l1
Level L1 SQL parameter.
Definition: v6/levtr.h:32
Storage for related physical data.
Definition: msg.h:70
virtual void dump(FILE *out)=0
Dump the entire contents of the table to an output stream.
virtual msg::Context * to_msg(int id, Msg &msg)=0
Get/create a Context in the Msg for this level/timerange.
int p1
Time range P1 SQL parameter.
Definition: v6/levtr.h:40
Information on how a value has been sampled or computed with regards to time.
Definition: types.h:587
virtual const DBRow * read(int id)=0
Read the LevTr data for an id, returns nullptr if not found.
Key/value store where keys are strings and values are wreport variables.
Definition: record.h:17
virtual bool to_rec(int id, Record &rec)=0
Fill a record with level/timerange info with this id.
int id
lev_tr ID SQL parameter
Definition: v6/levtr.h:28
int l2
Level L2 SQL parameter.
Definition: v6/levtr.h:36
int ltype2
Second level type SQL parameter.
Definition: v6/levtr.h:34
virtual Level to_level(int id) const =0
Return a Level for this ID.
Definition: v6/levtr.h:63
Vertical level or layer.
Definition: types.h:532
virtual void dump(FILE *out) const =0
Dump cache contents to an output stream.
Definition: v6/levtr.h:25
virtual void read_all(std::function< void(const DBRow &)> dest)=0
Read the contents of the LevTr table.
Precompiled queries to manipulate the lev_tr table.
Definition: v6/levtr.h:23
int pind
Time range type SQL parameter.
Definition: v6/levtr.h:38
static std::unique_ptr< LevTrCache > create(LevTr &levtr)
Create a new LevTrCache for this LevTr.
virtual Trange to_trange(int id) const =0
Return a Trange for this ID.
virtual void invalidate()=0
Invalidate the cache.
int p2
Time range P2 SQL parameter.
Definition: v6/levtr.h:42
int ltype1
First level type SQL parameter.
Definition: v6/levtr.h:30
Common definitions.
virtual int obtain_id(const Level &lev, const Trange &tr)=0
Return the ID for the given Level and Trange, adding it to the database if it does not already exist...