libdballe  7.7
memdb/station.h
1 #ifndef DBA_MEMDB_STATION_H
2 #define DBA_MEMDB_STATION_H
3 
4 #include <dballe/memdb/valuestorage.h>
5 #include <dballe/memdb/index.h>
6 #include <dballe/core/defs.h>
7 #include <string>
8 #include <cstddef>
9 
10 namespace dballe {
11 struct Record;
12 struct Msg;
13 struct Station;
14 
15 namespace core {
16 struct Query;
17 }
18 
19 namespace msg {
20 struct Context;
21 }
22 
23 namespace memdb {
24 template<typename T> struct Results;
25 
27 struct Station
28 {
29  size_t id;
30  Coords coords;
31  bool mobile;
32  std::string ident;
33  std::string report;
34 
35  // Fixed station
36  Station(size_t id, const Coords& coords, const std::string& report)
37  : id(id), coords(coords), mobile(false), report(report) {}
38  Station(size_t id, double lat, double lon, const std::string& report)
39  : id(id), coords(lat, lon), mobile(false), report(report) {}
40 
41  // Mobile station
42  Station(size_t id, const Coords& coords, const std::string& ident, const std::string& report)
43  : id(id), coords(coords), mobile(true), ident(ident), report(report) {}
44  Station(size_t id, double lat, double lon, const std::string& ident, const std::string& report)
45  : id(id), coords(lat, lon), mobile(true), ident(ident), report(report) {}
46 
53  msg::Context& fill_msg(Msg& msg) const;
54 
55  bool operator<(const Station& o) const { return id < o.id; }
56  bool operator>(const Station& o) const { return id > o.id; }
57  bool operator==(const Station& o) const { return id == o.id; }
58  bool operator!=(const Station& o) const { return id != o.id; }
59 };
60 
62 class Stations : public ValueStorage<Station>
63 {
64 protected:
65  Index<int> by_lat;
66  Index<std::string> by_ident;
67 
68 public:
69  Stations();
70 
71  void clear();
72 
74  size_t obtain_fixed(const Coords& coords, const std::string& report, bool create=true);
75 
77  size_t obtain_mobile(const Coords& coords, const std::string& ident, const std::string& report, bool create=true);
78 
80  size_t obtain(const Record& rec, bool create=true);
81 
83  size_t obtain(const dballe::Station& st, bool create=true);
84 
86  void query(const core::Query& q, Results<Station>& res) const;
87 
88  void dump(FILE* out) const;
89 };
90 
91 }
92 }
93 
94 #endif
95 
Store an array of physical data all on the same level.
Definition: context.h:44
Definition: mem/cursor.h:14
Definition: values.h:12
Storage for related physical data.
Definition: msg.h:133
msg::Context & fill_msg(Msg &msg) const
Fill lat, lon, report information, message type (from report) and identifier in msg.
Coordinates.
Definition: types.h:320
Key/value store where keys are strings and values are wreport variables.
Definition: record.h:16
Standard dballe::Query implementation.
Definition: core/query.h:29
size_t obtain_mobile(const Coords &coords, const std::string &ident, const std::string &report, bool create=true)
Get a mobile Station record.
Copyright (C) 2008–2010 ARPA-SIM urpsim@smr.arpa.emr.it
Definition: cmdline.h:17
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:27
Storage and index for station information.
Definition: memdb/station.h:62
size_t obtain_fixed(const Coords &coords, const std::string &report, bool create=true)
Get a fixed Station record.
void query(const core::Query &q, Results< Station > &res) const
Query stations returning the IDs.
Common definitions.
Definition: memdb/levtr.h:16