Cleanup config.nodes_of
[check_mk.git] / livestatus / src / Filter.h
blob88f3f6667ce4a8da4adc06748c20be2044e02762
1 // +------------------------------------------------------------------+
2 // | ____ _ _ __ __ _ __ |
3 // | / ___| |__ ___ ___| | __ | \/ | |/ / |
4 // | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
5 // | | |___| | | | __/ (__| < | | | | . \ |
6 // | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
7 // | |
8 // | Copyright Mathias Kettner 2014 mk@mathias-kettner.de |
9 // +------------------------------------------------------------------+
11 // This file is part of Check_MK.
12 // The official homepage is at http://mathias-kettner.de/check_mk.
14 // check_mk is free software; you can redistribute it and/or modify it
15 // under the terms of the GNU General Public License as published by
16 // the Free Software Foundation in version 2. check_mk is distributed
17 // in the hope that it will be useful, but WITHOUT ANY WARRANTY; with-
18 // out even the implied warranty of MERCHANTABILITY or FITNESS FOR A
19 // PARTICULAR PURPOSE. See the GNU General Public License for more de-
20 // tails. You should have received a copy of the GNU General Public
21 // License along with GNU Make; see the file COPYING. If not, write
22 // to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
23 // Boston, MA 02110-1301 USA.
25 #ifndef Filter_h
26 #define Filter_h
28 #include "config.h" // IWYU pragma: keep
29 #include <bitset>
30 #include <chrono>
31 #include <cstdint>
32 #include <functional>
33 #include <iosfwd>
34 #include <memory>
35 #include <optional>
36 #include <string>
37 #include <vector>
38 #include "contact_fwd.h"
39 class Column;
40 class Filter;
41 class Row;
43 using Filters = std::vector<std::unique_ptr<Filter>>;
45 /// A propositional formula over column value relations, kept in negation normal
46 /// form.
47 class Filter {
48 public:
49 enum Kind { row, stats, wait_condition };
51 explicit Filter(Kind kind) : _kind(kind) {}
52 virtual ~Filter();
53 Kind kind() const { return _kind; }
54 virtual bool accepts(Row row, const contact *auth_user,
55 std::chrono::seconds timezone_offset) const = 0;
56 virtual std::unique_ptr<Filter> partialFilter(
57 std::function<bool(const Column &)> predicate) const = 0;
59 // TODO(sp) We might be able to unify all the methods below if we make the
60 // underlying lattice structure explicit, i.e. provide a set type and
61 // corresponding meet/join operations. Perhaps we can even get rid of the
62 // std::optional by making the lattice bounded, i.e. by providing bottom/top
63 // values.
64 virtual std::optional<std::string> stringValueRestrictionFor(
65 const std::string &column_name) const;
66 virtual std::optional<int32_t> greatestLowerBoundFor(
67 const std::string &column_name,
68 std::chrono::seconds timezone_offset) const;
69 virtual std::optional<int32_t> leastUpperBoundFor(
70 const std::string &column_name,
71 std::chrono::seconds timezone_offset) const;
72 virtual std::optional<std::bitset<32>> valueSetLeastUpperBoundFor(
73 const std::string &column_name,
74 std::chrono::seconds timezone_offset) const;
76 virtual std::unique_ptr<Filter> copy() const = 0;
77 virtual std::unique_ptr<Filter> negate() const = 0;
79 /// Checks for a *syntactic* tautology.
80 virtual bool is_tautology() const = 0;
82 /// Checks for a *syntactic* contradiction.
83 virtual bool is_contradiction() const = 0;
85 /// Combining the returned filters with *or* yields a filter equivalent to
86 /// the current one.
87 virtual Filters disjuncts() const = 0;
89 /// Combining the returned filters with *and* yields a filter equivalent to
90 /// the current one.
91 virtual Filters conjuncts() const = 0;
93 friend std::ostream &operator<<(std::ostream &os, const Filter &filter) {
94 return filter.print(os);
97 private:
98 const Kind _kind;
99 virtual std::ostream &print(std::ostream &os) const = 0;
102 #endif // Filter_h