1 // +------------------------------------------------------------------+
2 // | ____ _ _ __ __ _ __ |
3 // | / ___| |__ ___ ___| | __ | \/ | |/ / |
4 // | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
5 // | | |___| | | | __/ (__| < | | | | . \ |
6 // | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
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.
28 #include "config.h" // IWYU pragma: keep
38 #include "contact_fwd.h"
43 using Filters
= std::vector
<std::unique_ptr
<Filter
>>;
45 /// A propositional formula over column value relations, kept in negation normal
49 enum Kind
{ row
, stats
, wait_condition
};
51 explicit Filter(Kind kind
) : _kind(kind
) {}
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
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
87 virtual Filters
disjuncts() const = 0;
89 /// Combining the returned filters with *and* yields a filter equivalent to
91 virtual Filters
conjuncts() const = 0;
93 friend std::ostream
&operator<<(std::ostream
&os
, const Filter
&filter
) {
94 return filter
.print(os
);
99 virtual std::ostream
&print(std::ostream
&os
) const = 0;