1#ifndef DBALLE_FORTRAN_COMMONAPI_H
2#define DBALLE_FORTRAN_COMMONAPI_H
7#include <dballe/core/cursor.h>
8#include <dballe/core/data.h>
9#include <dballe/core/enq.h>
10#include <dballe/core/query.h>
23 Values::const_iterator current;
48 virtual void set_varcode(wreport::Varcode varcode);
49 virtual void query_attributes(
Attributes& dest) = 0;
50 virtual void insert_attributes(
Values& qcinput) = 0;
51 virtual void remove_attributes() = 0;
52 virtual bool next_station();
53 virtual wreport::Varcode next_data();
55 virtual int enqi(
const char* param)
const = 0;
56 virtual signed char enqb(
const char* param)
const;
57 virtual float enqr(
const char* param)
const;
58 virtual double enqd(
const char* param)
const = 0;
59 virtual bool enqc(
const char* param,
char* res,
unsigned res_len)
const = 0;
60 virtual void enqlevel(
int& ltype1,
int& l1,
int& ltype2,
int& l2)
const = 0;
61 virtual void enqtimerange(
int& ptype,
int& p1,
int& p2)
const = 0;
62 virtual void enqdate(
int& year,
int& month,
int& day,
int& hour,
int& min,
70inline Level cursor_get_level(
const CursorData& c) {
return c.get_level(); }
71inline Level cursor_get_level(
const CursorSummary& c) {
return c.get_level(); }
72inline Trange cursor_get_trange(
const CursorStation& c) {
return Trange(); }
73inline Trange cursor_get_trange(
const CursorStationData& c) {
return Trange(); }
74inline Trange cursor_get_trange(
const CursorData& c) {
return c.get_trange(); }
75inline Trange cursor_get_trange(
const CursorSummary& c)
77 return c.get_trange();
79inline Datetime cursor_get_datetime(
const CursorStation& c)
83inline Datetime cursor_get_datetime(
const CursorSummary& c)
87inline Datetime cursor_get_datetime(
const CursorStationData& c)
91inline Datetime cursor_get_datetime(
const CursorData& c)
93 return c.get_datetime();
100 std::shared_ptr<Cursor> cursor;
108 int enqi(
const char* param)
const override
112 "enqi called before running a query");
117 return API::missing_int;
120 double enqd(
const char* param)
const override
124 "enqd called before running a query");
128 return API::missing_double;
131 bool enqc(
const char* param,
char* res,
unsigned res_len)
const override
135 "enqc called before running a query");
136 Enqc enq(param, strlen(param), res, res_len);
140 void enqlevel(
int& ltype1,
int& l1,
int& ltype2,
int& l2)
const override
142 Level lev = cursor_get_level(*cursor);
143 ltype1 = lev.
ltype1 != MISSING_INT ? lev.
ltype1 : API::missing_int;
144 l1 = lev.
l1 != MISSING_INT ? lev.
l1 : API::missing_int;
145 ltype2 = lev.
ltype2 != MISSING_INT ? lev.
ltype2 : API::missing_int;
146 l2 = lev.
l2 != MISSING_INT ? lev.
l2 : API::missing_int;
148 void enqtimerange(
int& ptype,
int& p1,
int& p2)
const override
150 Trange tr = cursor_get_trange(*cursor);
151 ptype = tr.
pind != MISSING_INT ? tr.
pind : API::missing_int;
152 p1 = tr.
p1 != MISSING_INT ? tr.
p1 : API::missing_int;
153 p2 = tr.
p2 != MISSING_INT ? tr.
p2 : API::missing_int;
155 void enqdate(
int& year,
int& month,
int& day,
int& hour,
int& min,
156 int& sec)
const override
158 Datetime dt = cursor_get_datetime(*cursor);
159 year = dt.year != 0xffff ? dt.year : API::missing_int;
160 month = dt.month != 0xff ? dt.month : API::missing_int;
161 day = dt.day != 0xff ? dt.day : API::missing_int;
162 hour = dt.hour != 0xff ? dt.hour : API::missing_int;
163 min = dt.minute != 0xff ? dt.minute : API::missing_int;
164 sec = dt.second != 0xff ? dt.second : API::missing_int;
172class CommonAPIImplementation :
public API
176 PERM_ANA_RO = (1 << 0),
177 PERM_ANA_WRITE = (1 << 1),
178 PERM_DATA_RO = (1 << 2),
179 PERM_DATA_ADD = (1 << 3),
180 PERM_DATA_WRITE = (1 << 4),
181 PERM_ATTR_RO = (1 << 5),
182 PERM_ATTR_WRITE = (1 << 6)
189 const char* dataflag,
190 const char* attrflag);
205 wreport::Varcode input_query_var = 0;
206 std::set<wreport::Varcode> input_query_varlist;
211 bool station_context =
false;
216 Operation* operation =
nullptr;
220 std::string cached_spiega;
222 bool _seti(
const char* key,
unsigned len,
int val);
223 bool _setd(
const char* key,
unsigned len,
double val);
224 bool _setc(
const char* key,
unsigned len,
const char* val);
225 bool _unset(
const char* key,
unsigned len);
226 void validate_input_query();
229 CommonAPIImplementation();
230 CommonAPIImplementation(
const CommonAPIImplementation&) =
delete;
231 CommonAPIImplementation(CommonAPIImplementation&&) =
delete;
232 virtual ~CommonAPIImplementation();
233 CommonAPIImplementation& operator=(
const CommonAPIImplementation&) =
delete;
234 CommonAPIImplementation& operator=(CommonAPIImplementation&&) =
delete;
236 template <
typename Operation>
237 auto reset_operation(Operation* op) ->
decltype(op->run())
241 qcoutput.invalidate();
245 void reset_operation()
252 int enqi(
const char* param)
override;
253 signed char enqb(
const char* param)
override;
254 float enqr(
const char* param)
override;
255 double enqd(
const char* param)
override;
256 bool enqc(
const char* param,
char* res,
unsigned res_len)
override;
257 void seti(
const char* param,
int value)
override;
258 void setb(
const char* param,
signed char value)
override;
259 void setr(
const char* param,
float value)
override;
260 void setd(
const char* param,
double value)
override;
261 void setc(
const char* param,
const char* value)
override;
262 void set_station_context()
override;
263 void enqlevel(
int& ltype1,
int& l1,
int& ltype2,
int& l2)
override;
264 void setlevel(
int ltype1,
int l1,
int ltype2,
int l2)
override;
265 void enqtimerange(
int& ptype,
int& p1,
int& p2)
override;
266 void settimerange(
int ptype,
int p1,
int p2)
override;
267 void enqdate(
int& year,
int& month,
int& day,
int& hour,
int& min,
269 void setdate(
int year,
int month,
int day,
int hour,
int min,
271 void setdatemin(
int year,
int month,
int day,
int hour,
int min,
273 void setdatemax(
int year,
int month,
int day,
int hour,
int min,
275 void unset(
const char* param)
override;
276 void unsetall()
override;
277 void unsetb()
override;
278 const char* describe_level(
int ltype1,
int l1,
int ltype2,
int l2)
override;
279 const char* describe_timerange(
int ptype,
int p1,
int p2)
override;
280 const char* describe_var(
const char* varcode,
const char* value)
override;
281 void next_station()
override;
282 wreport::Varcode next_data()
override;
283 int query_attributes()
override;
284 const char* next_attribute()
override;
285 void insert_attributes()
override;
286 void remove_attributes()
override;
287 void commit()
override;
289 const Operation* test_get_operation()
const {
return operation; }
291 const core::Query& test_get_input_query()
const {
return input_query; }
292 const core::Data& test_get_input_data()
const {
return input_data; }
293 const Values& test_get_qcinput()
const {
return qcinput; }
295 friend class Operation;
Cursor iterating over station data values.
Definition cursor.h:68
Cursor iterating over stations.
Definition cursor.h:58
Holds data for database I/O.
Definition core/data.h:18
static unsigned compute_permissions(const char *anaflag, const char *dataflag, const char *attrflag)
Set the permission bits, parsing the flags and doing consistency checks.
std::vector< wreport::Varcode > selected_attr_codes
Selected attribute varcodes (*varlist)
Definition commonapi.h:210
Operation-specific behaviour for the API.
Definition commonapi.h:45
Date and time.
Definition types.h:164
Vertical level or layer.
Definition types.h:625
int l1
L1 value of the level or the first layer.
Definition types.h:629
int l2
L2 value of the second layer.
Definition types.h:633
int ltype1
Type of the level or the first layer.
Definition types.h:627
int ltype2
Type of the the second layer.
Definition types.h:631
Information on how a value has been sampled or computed with regards to time.
Definition types.h:689
int p1
Time range P1 indicator.
Definition types.h:693
int pind
Time range type indicator.
Definition types.h:691
int p2
Time range P2 indicator.
Definition types.h:695
Collection of Value objects, indexed by wreport::Varcode.
Definition values.h:216
Standard dballe::Query implementation.
Definition core/query.h:36
C++ implementation for the Fortran API.
Definition api.h:16
Storage for currently queried attributes.
Definition commonapi.h:21
void has_new_values()
Mark that there is a new set of values in values.
wreport::Varcode next()
Return the next attribute in the result set.
void invalidate()
Mark the result set as invalid.
Definition commonapi.h:99
Definition fortran/enq.h:11
Definition core/enq.h:227
Definition core/enq.h:177
Structures used as input to database insert functions.