libdballe 9.6
summary_memory.h
1#ifndef DBALLE_DB_SUMMARY_MEMORY_H
2#define DBALLE_DB_SUMMARY_MEMORY_H
3
4#include <dballe/core/fwd.h>
5#include <dballe/db/summary.h>
6#include <dballe/db/summary_utils.h>
7
8namespace dballe {
9namespace db {
10
14template<typename Station>
15class BaseSummaryMemory : public BaseSummary<Station>
16{
17protected:
18 // Summary of items for the currently active filter
20
21 std::string pathname;
22
27 mutable dballe::DatetimeRange dtrange;
28 mutable size_t count = 0;
29
30 mutable bool dirty = false;
31
32 void recompute_summaries() const;
33
34public:
36 BaseSummaryMemory(const std::string& pathname);
37
38 const summary::StationEntries<Station>& _entries() const { if (dirty) recompute_summaries(); return entries.sorted(); }
39
40 bool stations(std::function<bool(const Station&)>) const override;
41 bool reports(std::function<bool(const std::string&)>) const override;
42 bool levels(std::function<bool(const Level&)>) const override;
43 bool tranges(std::function<bool(const Trange&)>) const override;
44 bool varcodes(std::function<bool(const wreport::Varcode&)>) const override;
45
46 Datetime datetime_min() const override { if (dirty) recompute_summaries(); return dtrange.min; }
47 Datetime datetime_max() const override { if (dirty) recompute_summaries(); return dtrange.max; }
48 unsigned data_count() const override { if (dirty) recompute_summaries(); return count; }
49
60 std::shared_ptr<dballe::CursorSummary> query_summary(const Query& query) const override;
61
62 bool iter(std::function<bool(const Station&, const summary::VarDesc&, const DatetimeRange&, size_t)>) const override;
63 bool iter_filtered(const dballe::Query& query, std::function<bool(const Station&, const summary::VarDesc&, const DatetimeRange&, size_t)>) const override;
64
65 void clear() override;
66
68 void add(const Station& station, const summary::VarDesc& vd, const dballe::DatetimeRange& dtrange, size_t count) override;
69
71 void add_summary(const BaseSummary<dballe::Station>& summary) override;
72
74 void add_summary(const BaseSummary<dballe::DBStation>& summary) override;
75
77 void add_filtered(const BaseSummary<Station>& summary, const dballe::Query& query) override;
78
79 void commit() override;
80
82 void to_json(core::JSONWriter& writer) const override;
83
85 void load_json(core::json::Stream& in) override;
86
87 DBALLE_TEST_ONLY void dump(FILE* out) const override;
88};
89
94
99
100extern template class BaseSummaryMemory<dballe::Station>;
101extern template class BaseSummaryMemory<dballe::DBStation>;
102
103}
104}
105
106#endif
Query used to filter DB-All.e data.
Definition: query.h:15
JSON serializer.
Definition: json.h:30
High level objects for working with DB-All.e DB summaries.
Definition: summary_memory.h:16
void to_json(core::JSONWriter &writer) const override
Serialize to JSON.
void clear() override
Completely empty the summary.
void add(const Station &station, const summary::VarDesc &vd, const dballe::DatetimeRange &dtrange, size_t count) override
Add an entry to the summary.
Datetime datetime_min() const override
Recompute reports, levels, tranges, and varcodes.
Definition: summary_memory.h:46
void add_filtered(const BaseSummary< Station > &summary, const dballe::Query &query) override
Merge the copy of another summary into this one.
void load_json(core::json::Stream &in) override
Load contents from JSON, merging with the current contents.
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.
void add_summary(const BaseSummary< dballe::Station > &summary) override
Merge the copy of another summary into this one.
std::shared_ptr< dballe::CursorSummary > query_summary(const Query &query) const override
Query the contents of the summary.
void add_summary(const BaseSummary< dballe::DBStation > &summary) override
Merge the copy of another summary into this one.
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.
void commit() override
Write changes to disk.
High level objects for working with DB-All.e DB summaries.
Definition: summary.h:45
uint16_t Varcode
Range of datetimes.
Definition: types.h:295
Datetime min
Lower bound of the range.
Definition: types.h:297
Datetime max
Upper bound of the range.
Definition: types.h:299
Date and time.
Definition: types.h:165
Vertical level or layer.
Definition: types.h:625
Station information.
Definition: types.h:794
Information on how a value has been sampled or computed with regards to time.
Definition: types.h:687
Definition: smallset.h:196
Definition: json.h:166
Index of all stations known to a summary.
Definition: summary_utils.h:123
Description of a variable, independent of where and when it was measured.
Definition: summary.h:18