libdballe  6.8
value.h
1 /*
2  * memdb/value - In memory representation of a variable with metadata and
3  * attributes
4  *
5  * Copyright (C) 2013--2014 ARPA-SIM <urpsim@smr.arpa.emr.it>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19  *
20  * Author: Enrico Zini <enrico@enricozini.com>
21  */
22 
23 #ifndef DBA_MEMDB_VALUE_H
24 #define DBA_MEMDB_VALUE_H
25 
26 #include <dballe/memdb/valuestorage.h>
27 #include <dballe/memdb/index.h>
28 #include <dballe/memdb/valuebase.h>
29 #include <dballe/core/defs.h>
30 #include <wreport/var.h>
31 #include <memory>
32 #include <iosfwd>
33 
34 namespace dballe {
35 struct Record;
36 
37 namespace memdb {
38 template<typename T> struct Results;
39 struct Station;
40 struct LevTr;
41 
43 struct Value : public ValueBase
44 {
45  const Station& station;
46  const LevTr& levtr;
47  Datetime datetime;
48 
49  Value(const Station& station, const LevTr& levtr, const Datetime& datetime, std::auto_ptr<wreport::Var> var)
50  : ValueBase(var), station(station), levtr(levtr), datetime(datetime) {}
51  ~Value();
52 
53  void dump(FILE* out) const;
54 
55 private:
56  Value(const Value&);
57  Value& operator=(const Value&);
58 };
59 
61 class Values : public ValueStorage<Value>
62 {
63 protected:
64  Index<const Station*> by_station;
65  Index<const LevTr*> by_levtr;
66  Index<Date> by_date;
67 
68 public:
69  void clear();
70 
72  size_t insert(const Station& station, const LevTr& levtr, const Datetime& datetime, std::auto_ptr<wreport::Var> var, bool replace=true);
73 
75  size_t insert(const Station& station, const LevTr& levtr, const Datetime& datetime, const wreport::Var& var, bool replace=true);
76 
82  bool remove(const Station& station, const LevTr& levtr, const Datetime& datetime, wreport::Varcode code);
83 
85  void erase(size_t idx);
86 
88  void query(const Record& rec, Results<Station>& stations, Results<LevTr>& levtrs, Results<Value>& res) const;
89 
90  void dump(FILE* out) const;
91 };
92 
93 }
94 }
95 
96 #endif
void query(const Record &rec, Results< Station > &stations, Results< LevTr > &levtrs, Results< Value > &res) const
Query values returning the IDs.
size_t insert(const Station &station, const LevTr &levtr, const Datetime &datetime, std::auto_ptr< wreport::Var > var, bool replace=true)
Insert a new value, or replace an existing one.
Station information.
Definition: valuebase.h:35
Station information.
Definition: levtr.h:36
void erase(size_t idx)
Removes a value, by index.
Common definitions.
DB-All.E record.
Definition: record.h:102
Definition: cmdline.h:34
Station information.
Definition: value.h:43
Station information.
Definition: memdb/station.h:43
Simple datetime structure.
Definition: defs.h:276
Index element positions based by one value.
Definition: index.h:41
Storage and index for station information.
Definition: value.h:61
Definition: mem/cursor.h:35
Definition: levtr.h:33