libdballe  9.14
summary_xapian.h
1 #ifndef DBALLE_DB_SUMMARY_XAPIAN_H
2 #define DBALLE_DB_SUMMARY_XAPIAN_H
3 
4 #include <dballe/core/fwd.h>
5 #include <dballe/db/summary.h>
6 #include <xapian.h>
7 
8 namespace dballe {
9 namespace db {
10 
15 struct XapianDB
16 {
17  virtual ~XapianDB() {}
18 
19  virtual Xapian::Database& reader() = 0;
20  virtual Xapian::WritableDatabase& writer() = 0;
21  virtual void commit() = 0;
22  virtual void clear() = 0;
23 };
24 
28 template <typename Station>
29 class BaseSummaryXapian : public BaseSummary<Station>
30 {
31  std::unique_ptr<XapianDB> db;
32 
33 public:
35  BaseSummaryXapian(const std::string& pathname);
37 
38  bool stations(std::function<bool(const Station&)>) const override;
39  bool reports(std::function<bool(const std::string&)>) const override;
40  bool levels(std::function<bool(const Level&)>) const override;
41  bool tranges(std::function<bool(const Trange&)>) const override;
42  bool varcodes(std::function<bool(const wreport::Varcode&)>) const override;
43 
44  Datetime datetime_min() const override;
45  Datetime datetime_max() const override;
46  unsigned data_count() const override;
47 
48  void clear() override;
49  void add(const Station& station, const summary::VarDesc& vd,
50  const dballe::DatetimeRange& dtrange, size_t count) override;
51  void commit() override;
52 
53  bool iter(std::function<bool(const Station&, const summary::VarDesc&,
54  const DatetimeRange&, size_t)>) const override;
55  bool iter_filtered(
56  const dballe::Query& query,
57  std::function<bool(const Station&, const summary::VarDesc&,
58  const DatetimeRange&, size_t)>) const override;
59 
61  void to_json(core::JSONWriter& writer) const override;
62 
63  DBALLE_TEST_ONLY void dump(FILE* out) const override;
64 };
65 
70 
75 
76 extern template class BaseSummaryXapian<dballe::Station>;
77 extern template class BaseSummaryXapian<dballe::DBStation>;
78 
79 } // namespace db
80 } // namespace dballe
81 
82 #endif
bool iter(std::function< bool(const Station &, const summary::VarDesc &, const DatetimeRange &, size_t)>) const override
Iterate the contents of this summary.
Station information.
Definition: types.h:878
void add(const Station &station, const summary::VarDesc &vd, const dballe::DatetimeRange &dtrange, size_t count) override
Add an entry to the summary.
Description of a variable, independent of where and when it was measured.
Definition: summary.h:17
void clear() override
Completely empty the summary.
Information on how a value has been sampled or computed with regards to time.
Definition: types.h:688
Definition: cmdline.h:18
Vertical level or layer.
Definition: types.h:624
void to_json(core::JSONWriter &writer) const override
Serialize to JSON.
Abstract interface for accessing Xapian databases, with read locking only when needed.
Definition: summary_xapian.h:15
bool iter_filtered(const dballe::Query &query, std::function< bool(const Station &, const summary::VarDesc &, const DatetimeRange &, size_t)>) const override
Iterate the contents of this summary.
Range of datetimes.
Definition: types.h:296
High level objects for working with DB-All.e DB summaries.
Definition: summary.h:70
Date and time.
Definition: types.h:163
JSON serializer.
Definition: json.h:29
Datetime datetime_min() const override
Recompute reports, levels, tranges, and varcodes.
void commit() override
Write changes to disk.
Query used to filter DB-All.e data.
Definition: query.h:16
High level objects for working with DB-All.e DB summaries.
Definition: summary_xapian.h:29