libdballe  7.7
db/mysql/station.h
Go to the documentation of this file.
1 /*
2  * db/mysql/station - station table management
3  *
4  * Copyright (C) 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_MYSQL_STATION_H
23 #define DBALLE_DB_MYSQL_STATION_H
24 
31 #include <dballe/db/sql/station.h>
32 #include <functional>
33 #include <memory>
34 
35 namespace wreport {
36 struct Var;
37 }
38 
39 namespace dballe {
40 namespace db {
41 struct MySQLConnection;
42 
43 namespace mysql {
44 
49 {
50 protected:
55 
57  bool maybe_get_id(int lat, int lon, const char* ident, int* id);
58 
60  void read_station_vars(const std::string& query, std::function<void(std::unique_ptr<wreport::Var>)> dest);
61 
62 public:
65  MySQLStationBase(const MySQLStationBase&) = delete;
66  MySQLStationBase(const MySQLStationBase&&) = delete;
67  MySQLStationBase& operator=(const MySQLStationBase&) = delete;
68 
77  int get_id(int lat, int lon, const char* ident=nullptr) override;
78 
87  int obtain_id(int lat, int lon, const char* ident=nullptr, bool* inserted=NULL) override;
88 
89  void get_station_vars(int id_station, int id_report, std::function<void(std::unique_ptr<wreport::Var>)> dest) override;
90  void add_station_vars(int id_station, Record& rec) override;
91 
95  void dump(FILE* out) override;
96 };
97 
99 {
100 public:
102 };
103 
104 }
105 
106 }
107 }
108 #endif
Database connection.
Definition: mysql/internals.h:145
void dump(FILE *out) override
Dump the entire contents of the table to an output stream.
void read_station_vars(const std::string &query, std::function< void(std::unique_ptr< wreport::Var >)> dest)
Run stm, read its output and generate variables to send to dest.
int get_id(int lat, int lon, const char *ident=nullptr) override
Get the station ID given latitude, longitude and mobile identifier.
Key/value store where keys are strings and values are wreport variables.
Definition: record.h:16
int obtain_id(int lat, int lon, const char *ident=nullptr, bool *inserted=NULL) override
Get the station ID given latitude, longitude and mobile identifier.
Copyright (C) 2008–2010 ARPA-SIM urpsim@smr.arpa.emr.it
Definition: cmdline.h:17
Definition: db/mysql/station.h:98
void get_station_vars(int id_station, int id_report, std::function< void(std::unique_ptr< wreport::Var >)> dest) override
Export station variables.
bool maybe_get_id(int lat, int lon, const char *ident, int *id)
Lookup the ID of a station, returning true if it was found, false if not.
Station table management used by the db module.
MySQLConnection & conn
DB connection.
Definition: db/mysql/station.h:54
Definition: db/sql/station.h:46
Definition: conversion.h:6
Precompiled queries to manipulate the station table.
Definition: db/mysql/station.h:48
void add_station_vars(int id_station, Record &rec) override
Add all station variables (without attributes) to rec.