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.
25 #include "IntFilter.h"
28 #include "IntColumn.h"
31 IntFilter::IntFilter(Kind kind
, const IntColumn
&column
,
32 RelationalOperator relOp
, const std::string
&value
)
33 : ColumnFilter(kind
, column
, relOp
, value
)
35 , _ref_value(atoi(value
.c_str())) {}
38 bool eval(int32_t x
, RelationalOperator op
, int32_t y
) {
40 case RelationalOperator::equal
:
42 case RelationalOperator::not_equal
:
44 case RelationalOperator::matches
: // superset
46 case RelationalOperator::doesnt_match
: // not superset
48 case RelationalOperator::equal_icase
: // subset
50 case RelationalOperator::not_equal_icase
: // not subset
52 case RelationalOperator::matches_icase
: // contains any
54 case RelationalOperator::doesnt_match_icase
: // contains none of
56 case RelationalOperator::less
:
58 case RelationalOperator::greater_or_equal
:
60 case RelationalOperator::greater
:
62 case RelationalOperator::less_or_equal
:
69 bool IntFilter::accepts(Row row
, const contact
*auth_user
,
70 std::chrono::seconds
/*timezone_offset*/) const {
71 return eval(_column
.getValue(row
, auth_user
), oper(), _ref_value
);
74 std::optional
<int32_t> IntFilter::greatestLowerBoundFor(
75 const std::string
&column_name
,
76 std::chrono::seconds
/* timezone_offset */) const {
77 if (column_name
!= columnName()) {
78 return {}; // wrong column
81 case RelationalOperator::equal
:
82 case RelationalOperator::greater_or_equal
:
84 case RelationalOperator::greater
:
85 return {_ref_value
+ 1};
86 case RelationalOperator::not_equal
:
87 case RelationalOperator::matches
: // superset
88 case RelationalOperator::doesnt_match
: // not superset
89 case RelationalOperator::equal_icase
: // subset
90 case RelationalOperator::not_equal_icase
: // not subset
91 case RelationalOperator::matches_icase
: // contains any
92 case RelationalOperator::doesnt_match_icase
: // contains none of
93 case RelationalOperator::less
:
94 case RelationalOperator::less_or_equal
:
95 // NOTE: If we use the equivalent 'return {}' here and the other
96 // std::nullopt occurences below, we run into g++/libstdc++ bug
97 // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86465. :-/
100 return std::nullopt
; // unreachable
103 std::optional
<int32_t> IntFilter::leastUpperBoundFor(
104 const std::string
&column_name
,
105 std::chrono::seconds
/* timezone_offset */) const {
106 if (column_name
!= columnName()) {
107 return {}; // wrong column
110 case RelationalOperator::equal
:
111 case RelationalOperator::less_or_equal
:
113 case RelationalOperator::less
:
114 return {_ref_value
- 1};
115 case RelationalOperator::not_equal
:
116 case RelationalOperator::matches
: // superset
117 case RelationalOperator::doesnt_match
: // not superset
118 case RelationalOperator::equal_icase
: // subset
119 case RelationalOperator::not_equal_icase
: // not subset
120 case RelationalOperator::matches_icase
: // contains any
121 case RelationalOperator::doesnt_match_icase
: // contains none of
122 case RelationalOperator::greater_or_equal
:
123 case RelationalOperator::greater
:
126 return std::nullopt
; // unreachable
129 std::optional
<std::bitset
<32>> IntFilter::valueSetLeastUpperBoundFor(
130 const std::string
&column_name
,
131 std::chrono::seconds
/* timezone_offset */) const {
132 if (column_name
!= columnName()) {
133 return {}; // wrong column
135 std::bitset
<32> result
;
136 for (int32_t bit
= 0; bit
< 32; ++bit
) {
137 result
[bit
] = eval(bit
, oper(), _ref_value
);
142 std::unique_ptr
<Filter
> IntFilter::copy() const {
143 return std::make_unique
<IntFilter
>(*this);
146 std::unique_ptr
<Filter
> IntFilter::negate() const {
147 return std::make_unique
<IntFilter
>(
148 kind(), _column
, negateRelationalOperator(oper()), value());