libdballe  7.6
db/sql/levtr.h
1 /*
2  * db/levtr - level-timerange table implementation
3  *
4  * Copyright (C) 2005--2015 ARPA-SIM <urpsim@smr.arpa.emr.it>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18  *
19  * Author: Enrico Zini <enrico@enricozini.com>
20  */
21 
22 #ifndef DBALLE_DB_SQL_LEVTR_H
23 #define DBALLE_DB_SQL_LEVTR_H
24 
25 #include <dballe/core/defs.h>
26 #include <memory>
27 #include <cstdio>
28 
29 namespace dballe {
30 struct Record;
31 struct Msg;
32 
33 namespace msg {
34 struct Context;
35 }
36 
37 namespace db {
38 struct Connection;
39 struct Statement;
40 
41 namespace sql {
42 
46 struct LevTr
47 {
48  struct DBRow
49  {
51  int id;
53  int ltype1;
55  int l1;
57  int ltype2;
59  int l2;
61  int pind;
63  int p1;
65  int p2;
66  };
67 
68  virtual ~LevTr();
69 
74  virtual int obtain_id(const Level& lev, const Trange& tr) = 0;
75 
77  virtual const DBRow* read(int id) = 0;
78 
80  virtual void read_all(std::function<void(const DBRow&)> dest) = 0;
81 
83  virtual void dump(FILE* out) = 0;
84 };
85 
86 struct LevTrCache
87 {
88  virtual ~LevTrCache();
89 
95  virtual bool to_rec(int id, Record& rec) = 0;
96 
98  virtual Level to_level(int id) const = 0;
99 
101  virtual Trange to_trange(int id) const = 0;
102 
108  virtual msg::Context* to_msg(int id, Msg& msg) = 0;
109 
111  virtual void invalidate() = 0;
112 
114  virtual void dump(FILE* out) const = 0;
115 
117  static std::unique_ptr<LevTrCache> create(LevTr& levtr);
118 };
119 
120 }
121 }
122 }
123 
124 #endif
125 
Store an array of physical data all on the same level.
Definition: context.h:44
int pind
Time range type SQL parameter.
Definition: db/sql/levtr.h:61
Definition: db/sql/levtr.h:48
static std::unique_ptr< LevTrCache > create(LevTr &levtr)
Create a new LevTrCache for this LevTr.
Storage for related physical data.
Definition: msg.h:133
int ltype1
First level type SQL parameter.
Definition: db/sql/levtr.h:53
virtual void invalidate()=0
Invalidate the cache.
virtual void dump(FILE *out) const =0
Dump cache contents to an output stream.
Information on how a value has been sampled or computed with regards to time.
Definition: types.h:565
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...
Key/value store where keys are strings and values are wreport variables.
Definition: record.h:16
int ltype2
Second level type SQL parameter.
Definition: db/sql/levtr.h:57
Copyright (C) 2008–2010 ARPA-SIM urpsim@smr.arpa.emr.it
Definition: cmdline.h:17
int p2
Time range P2 SQL parameter.
Definition: db/sql/levtr.h:65
virtual const DBRow * read(int id)=0
Read the LevTr data for an id, returns nullptr if not found.
int l1
Level L1 SQL parameter.
Definition: db/sql/levtr.h:55
Vertical level or layer.
Definition: types.h:515
virtual msg::Context * to_msg(int id, Msg &msg)=0
Get/create a Context in the Msg for this level/timerange.
Definition: db/sql/levtr.h:86
virtual Level to_level(int id) const =0
Return a Level for this ID.
int id
lev_tr ID SQL parameter
Definition: db/sql/levtr.h:51
virtual void dump(FILE *out)=0
Dump the entire contents of the table to an output stream.
virtual Trange to_trange(int id) const =0
Return a Trange for this ID.
int p1
Time range P1 SQL parameter.
Definition: db/sql/levtr.h:63
Common definitions.
virtual void read_all(std::function< void(const DBRow &)> dest)=0
Read the contents of the LevTr table.
int l2
Level L2 SQL parameter.
Definition: db/sql/levtr.h:59
Precompiled queries to manipulate the lev_tr table.
Definition: db/sql/levtr.h:46
virtual bool to_rec(int id, Record &rec)=0
Fill a record with level/timerange info with this id.