libdballe  6.8
memdb/station.h
1 /*
2  * memdb/station - In memory representation of stations
3  *
4  * Copyright (C) 2013 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 DBA_MEMDB_STATION_H
23 #define DBA_MEMDB_STATION_H
24 
25 #include <dballe/memdb/valuestorage.h>
26 #include <dballe/memdb/index.h>
27 #include <dballe/core/defs.h>
28 #include <string>
29 #include <cstddef>
30 
31 namespace dballe {
32 struct Record;
33 struct Msg;
34 
35 namespace msg {
36 struct Context;
37 }
38 
39 namespace memdb {
40 template<typename T> struct Results;
41 
43 struct Station
44 {
45  size_t id;
46  Coord coords;
47  bool mobile;
48  std::string ident;
49  std::string report;
50 
51  // Fixed station
52  Station(size_t id, const Coord& coords, const std::string& report)
53  : id(id), coords(coords), mobile(false), report(report) {}
54  Station(size_t id, double lat, double lon, const std::string& report)
55  : id(id), coords(lat, lon), mobile(false), report(report) {}
56 
57  // Mobile station
58  Station(size_t id, const Coord& coords, const std::string& ident, const std::string& report)
59  : id(id), coords(coords), mobile(true), ident(ident), report(report) {}
60  Station(size_t id, double lat, double lon, const std::string& ident, const std::string& report)
61  : id(id), coords(lat, lon), mobile(true), ident(ident), report(report) {}
62 
69  msg::Context& fill_msg(Msg& msg) const;
70 
71  bool operator<(const Station& o) const { return id < o.id; }
72  bool operator>(const Station& o) const { return id > o.id; }
73  bool operator==(const Station& o) const { return id == o.id; }
74  bool operator!=(const Station& o) const { return id != o.id; }
75 };
76 
78 class Stations : public ValueStorage<Station>
79 {
80 protected:
81  Index<int> by_lat;
82  Index<std::string> by_ident;
83 
84 public:
85  Stations();
86 
87  void clear();
88 
90  size_t obtain_fixed(const Coord& coords, const std::string& report, bool create=true);
91 
93  size_t obtain_mobile(const Coord& coords, const std::string& ident, const std::string& report, bool create=true);
94 
96  size_t obtain(const Record& rec, bool create=true);
97 
99  void query(const Record& rec, Results<Station>& res) const;
100 
101  void dump(FILE* out) const;
102 };
103 
104 }
105 }
106 
107 #endif
108 
Store an array of physical data all on the same level.
Definition: msg/context.h:44
Definition: mem/cursor.h:35
size_t obtain_fixed(const Coord &coords, const std::string &report, bool create=true)
Get a fixed Station record.
size_t obtain_mobile(const Coord &coords, const std::string &ident, const std::string &report, bool create=true)
Get a mobile Station record.
Storage for related physical data.
Definition: msg.h:119
msg::Context & fill_msg(Msg &msg) const
Fill lat, lon, report information, message type (from report) and identifier in msg.
void query(const Record &rec, Results< Station > &res) const
Query stations returning the IDs.
Common definitions.
DB-All.E record.
Definition: record.h:102
Definition: cmdline.h:34
size_t obtain(const Record &rec, bool create=true)
Get a fixed or mobile Station record depending on the data in rec.
Station information.
Definition: memdb/station.h:43
Storage and index for station information.
Definition: memdb/station.h:78
Coordinates.
Definition: defs.h:167
Definition: levtr.h:33