libdballe  6.8
levtr.h
1 /*
2  * memdb/ltr - In memory representation of level-timerange metadata
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_LTR_H
23 #define DBA_MEMDB_LTR_H
24 
25 #include <dballe/memdb/valuestorage.h>
26 #include <dballe/memdb/index.h>
27 #include <dballe/core/defs.h>
28 
29 namespace dballe {
30 struct Record;
31 
32 namespace memdb {
33 template<typename T> struct Results;
34 
36 struct LevTr
37 {
38  Level level;
39  Trange trange;
40 
41  LevTr(const Level& level, const Trange& trange)
42  : level(level), trange(trange) {}
43 
44  bool operator<(const LevTr& o) const { return compare(o) < 0; }
45  bool operator>(const LevTr& o) const { return compare(o) > 0; }
46  bool operator==(const LevTr& o) const { return level == o.level && trange == o.trange; }
47  bool operator!=(const LevTr& o) const { return level != o.level || trange != o.trange; }
48 
55  int compare(const LevTr& o) const
56  {
57  if (int res = level.compare(o.level)) return res;
58  return trange.compare(o.trange);
59  }
60 };
61 
63 class LevTrs : public ValueStorage<LevTr>
64 {
65 protected:
66  Index<Level> by_level;
67  Index<Trange> by_trange;
68 
69 public:
70  LevTrs();
71 
72  void clear();
73 
75  size_t obtain(const Level& level, const Trange& trange);
76 
78  size_t obtain(const Record& rec);
79 
81  void query(const Record& rec, Results<LevTr>& res) const;
82 
83  void dump(FILE* out) const;
84 };
85 
86 }
87 }
88 
89 #endif
90 
Station information.
Definition: levtr.h:36
Definition: mem/cursor.h:35
int compare(const LevTr &o) const
Compare two LevTr strutures, for use in sorting.
Definition: levtr.h:55
Storage and index for station information.
Definition: levtr.h:63
Definition: defs.h:113
Common definitions.
DB-All.E record.
Definition: record.h:102
Definition: cmdline.h:34
Definition: defs.h:54
size_t obtain(const Level &level, const Trange &trange)
Get a LevTr record.
int compare(const Level &l) const
Compare two Level strutures, for use in sorting.
Definition: defs.h:90
int compare(const Trange &t) const
Compare two Trange strutures, for use in sorting.
Definition: defs.h:145
Index element positions based by one value.
Definition: index.h:41
void query(const Record &rec, Results< LevTr > &res) const
Query levtrs returning the IDs.
Definition: levtr.h:33