libdballe  6.8
stationvalue.h
1 /*
2  * memdb/stationvalue - In memory representation of station values
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_STATIONVALUE_H
23 #define DBA_MEMDB_STATIONVALUE_H
24 
25 #include <dballe/memdb/valuestorage.h>
26 #include <dballe/memdb/index.h>
27 #include <dballe/memdb/valuebase.h>
28 #include <wreport/var.h>
29 #include <memory>
30 
31 namespace dballe {
32 struct Record;
33 
34 namespace msg {
35 struct Context;
36 }
37 
38 namespace memdb {
39 template<typename T> struct Results;
40 
41 struct Station;
42 
44 struct StationValue : public ValueBase
45 {
46  const Station& station;
47 
48  StationValue(const Station& station, std::auto_ptr<wreport::Var> var)
49  : ValueBase(var), station(station) {}
50  ~StationValue();
51 
52 private:
53  StationValue(const StationValue&);
54  StationValue& operator=(const StationValue&);
55 };
56 
58 class StationValues : public ValueStorage<StationValue>
59 {
60 protected:
61  Index<const Station*> by_station;
62 
63 public:
64  void clear();
65 
66  bool has_variables_for(const Station& station) const
67  {
68  return by_station.find(&station) != by_station.end();
69  }
70 
71  const StationValue* get(const Station& station, wreport::Varcode code) const;
72 
74  size_t insert(const Station& station, std::auto_ptr<wreport::Var> var, bool replace=true);
75 
77  size_t insert(const Station& station, const wreport::Var& var, bool replace=true);
78 
84  bool remove(const Station& station, wreport::Varcode code);
85 
87  void fill_record(const Station& station, Record& rec) const;
88 
90  void fill_msg(const Station& station, msg::Context& ctx) const;
91 
93  void query(const Record& rec, Results<Station>& stations, Results<StationValue>& res) const;
94 
95  void dump(FILE* out) const;
96 };
97 
98 }
99 }
100 
101 #endif
102 
103 
Store an array of physical data all on the same level.
Definition: msg/context.h:44
Station information.
Definition: valuebase.h:35
void fill_msg(const Station &station, msg::Context &ctx) const
Fill a message context with all the variables for this station.
void fill_record(const Station &station, Record &rec) const
Fill a record with all the variables for this station.
Storage and index for station information.
Definition: stationvalue.h:58
size_t insert(const Station &station, std::auto_ptr< wreport::Var > var, bool replace=true)
Insert a new value, or replace an existing one for the same station.
DB-All.E record.
Definition: record.h:102
Definition: cmdline.h:34
Station information.
Definition: memdb/station.h:43
Station information.
Definition: stationvalue.h:44
Index element positions based by one value.
Definition: index.h:41
void query(const Record &rec, Results< Station > &stations, Results< StationValue > &res) const
Query values for the given stations.
Definition: mem/cursor.h:35
Definition: levtr.h:33