libdballe  9.14
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 #include <filesystem>
8 
9 namespace dballe {
10 namespace db {
11 
15 template <typename Station>
16 class BaseSummaryMemory : public BaseSummary<Station>
17 {
18 protected:
19  // Summary of items for the currently active filter
21 
22  std::filesystem::path path;
23 
28  mutable dballe::DatetimeRange dtrange;
29  mutable size_t count = 0;
30 
31  mutable bool dirty = false;
32 
33  void recompute_summaries() const;
34 
35 public:
37  explicit BaseSummaryMemory(const std::filesystem::path& path);
38 
39  const summary::StationEntries<Station>& _entries() const
40  {
41  if (dirty)
42  recompute_summaries();
43  return entries.sorted();
44  }
45 
46  bool stations(std::function<bool(const Station&)>) const override;
47  bool reports(std::function<bool(const std::string&)>) const override;
48  bool levels(std::function<bool(const Level&)>) const override;
49  bool tranges(std::function<bool(const Trange&)>) const override;
50  bool varcodes(std::function<bool(const wreport::Varcode&)>) const override;
51 
52  Datetime datetime_min() const override
53  {
54  if (dirty)
55  recompute_summaries();
56  return dtrange.min;
57  }
58  Datetime datetime_max() const override
59  {
60  if (dirty)
61  recompute_summaries();
62  return dtrange.max;
63  }
64  unsigned data_count() const override
65  {
66  if (dirty)
67  recompute_summaries();
68  return count;
69  }
70 
81  std::shared_ptr<dballe::CursorSummary>
82  query_summary(const Query& query) const override;
83 
84  bool iter(std::function<bool(const Station&, const summary::VarDesc&,
85  const DatetimeRange&, size_t)>) const override;
86  bool iter_filtered(
87  const dballe::Query& query,
88  std::function<bool(const Station&, const summary::VarDesc&,
89  const DatetimeRange&, size_t)>) const override;
90 
91  void clear() override;
92 
94  void add(const Station& station, const summary::VarDesc& vd,
95  const dballe::DatetimeRange& dtrange, size_t count) override;
96 
98  void add_summary(const BaseSummary<dballe::Station>& summary) override;
99 
101  void add_summary(const BaseSummary<dballe::DBStation>& summary) override;
102 
104  void add_filtered(const BaseSummary<Station>& summary,
105  const dballe::Query& query) override;
106 
107  void commit() override;
108 
110  void to_json(core::JSONWriter& writer) const override;
111 
113  void load_json(core::json::Stream& in) override;
114 
115  DBALLE_TEST_ONLY void dump(FILE* out) const override;
116 };
117 
121 typedef BaseSummaryMemory<dballe::Station> SummaryMemory;
122 
126 typedef BaseSummaryMemory<dballe::DBStation> DBSummaryMemory;
127 
128 extern template class BaseSummaryMemory<dballe::Station>;
129 extern template class BaseSummaryMemory<dballe::DBStation>;
130 
131 } // namespace db
132 } // namespace dballe
133 
134 #endif
Station information.
Definition: types.h:878
bool iter(std::function< bool(const Station &, const summary::VarDesc &, const DatetimeRange &, size_t)>) const override
Iterate the contents of this summary.
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.
High level objects for working with DB-All.e DB summaries.
Definition: summary_memory.h:16
void load_json(core::json::Stream &in) override
Load contents from JSON, merging with the current contents.
Information on how a value has been sampled or computed with regards to time.
Definition: types.h:688
Definition: cmdline.h:18
void add_summary(const BaseSummary< dballe::Station > &summary) override
Merge the copy of another summary into this one.
Vertical level or layer.
Definition: types.h:624
Range of datetimes.
Definition: types.h:296
void add(const Station &station, const summary::VarDesc &vd, const dballe::DatetimeRange &dtrange, size_t count) override
Add an entry to the summary.
Datetime max
Upper bound of the range.
Definition: types.h:301
Datetime datetime_min() const override
Recompute reports, levels, tranges, and varcodes.
Definition: summary_memory.h:52
Datetime min
Lower bound of the range.
Definition: types.h:299
void to_json(core::JSONWriter &writer) const override
Serialize to JSON.
High level objects for working with DB-All.e DB summaries.
Definition: summary.h:70
Date and time.
Definition: types.h:163
std::shared_ptr< dballe::CursorSummary > query_summary(const Query &query) const override
Query the contents of the summary.
void commit() override
Write changes to disk.
Index of all stations known to a summary.
Definition: summary_utils.h:149
void clear() override
Completely empty the summary.
Query used to filter DB-All.e data.
Definition: query.h:16
void add_filtered(const BaseSummary< Station > &summary, const dballe::Query &query) override
Merge the copy of another summary into this one.