libdballe  9.11
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, const dballe::DatetimeRange& dtrange, size_t count) override;
50  void commit() override;
51 
52  bool iter(std::function<bool(const Station&, const summary::VarDesc&, const DatetimeRange&, size_t)>) const override;
53  bool iter_filtered(const dballe::Query& query, std::function<bool(const Station&, const summary::VarDesc&, const DatetimeRange&, size_t)>) const override;
54 
56  void to_json(core::JSONWriter& writer) const override;
57 
58  DBALLE_TEST_ONLY void dump(FILE* out) const override;
59 };
60 
65 
70 
71 extern template class BaseSummaryXapian<dballe::Station>;
72 extern template class BaseSummaryXapian<dballe::DBStation>;
73 
74 }
75 }
76 
77 #endif
bool iter(std::function< bool(const Station &, const summary::VarDesc &, const DatetimeRange &, size_t)>) const override
Iterate the contents of this summary. There is no guarantee on sorting order.
Station information.
Definition: types.h:793
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:686
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. There is no guarantee on sorting order.
uint16_t Varcode
Range of datetimes.
Definition: types.h:294
High level objects for working with DB-All.e DB summaries.
Definition: summary.h:44
Date and time.
Definition: types.h:164
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:14
High level objects for working with DB-All.e DB summaries.
Definition: summary_xapian.h:29