Module: check_mk
Branch: master
Commit: 85198f433a71e01112edd272ad3b22af6ea9a010
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=85198f433a71e0…
Author: Sven Panne <sp(a)mathias-kettner.de>
Date: Fri Nov 3 15:35:12 2017 +0100
Simplifications.
Change-Id: I9a80c461111c0194dbad6c606ddc4b7cf238fce8
---
livestatus/src/IntFilter.cc | 84 ++++++++++++++++++--------------------------
livestatus/src/IntFilter.h | 7 ++--
livestatus/src/TimeFilter.cc | 10 ++----
livestatus/src/TimeFilter.h | 5 ++-
4 files changed, 42 insertions(+), 64 deletions(-)
diff --git a/livestatus/src/IntFilter.cc b/livestatus/src/IntFilter.cc
index 8683f18..855c676 100644
--- a/livestatus/src/IntFilter.cc
+++ b/livestatus/src/IntFilter.cc
@@ -25,63 +25,52 @@
#include "IntFilter.h"
#include <cstdlib>
#include <ostream>
-#include <utility>
#include "IntColumn.h"
#include "Logger.h"
#include "Row.h"
IntFilter::IntFilter(const IntColumn &column, RelationalOperator relOp,
- std::string value)
- : _column(column), _relOp(relOp), _ref_string(std::move(value)) {}
+ const std::string &value)
+ : _column(column), _relOp(relOp), _ref_value(atoi(value.c_str())) {}
std::string IntFilter::columnName() const { return _column.name(); }
-// overridden by TimeFilter in order to apply timezone offset from Localtime:
-// header
-bool IntFilter::adjustWithTimezoneOffset() const { return false; }
-
-int32_t IntFilter::convertRefValue(std::chrono::seconds timezone_offset) const {
- return atoi(_ref_string.c_str()) -
- (adjustWithTimezoneOffset() ? timezone_offset.count() : 0);
-}
-
bool IntFilter::accepts(Row row, const contact *auth_user,
- std::chrono::seconds timezone_offset) const {
+ std::chrono::seconds /*timezone_offset*/) const {
// NOTE: IntColumn::getValue() call site
int32_t act_value = _column.getValue(row, auth_user);
- int32_t ref_value = convertRefValue(timezone_offset);
switch (_relOp) {
case RelationalOperator::equal:
- return act_value == ref_value;
+ return act_value == _ref_value;
case RelationalOperator::not_equal:
- return act_value != ref_value;
+ return act_value != _ref_value;
case RelationalOperator::matches: // superset
- return (act_value & ref_value) == ref_value;
+ return (act_value & _ref_value) == _ref_value;
case RelationalOperator::doesnt_match: // not superset
- return (act_value & ref_value) != ref_value;
+ return (act_value & _ref_value) != _ref_value;
case RelationalOperator::equal_icase: // subset
- return (act_value & ref_value) == act_value;
+ return (act_value & _ref_value) == act_value;
case RelationalOperator::not_equal_icase: // not subset
- return (act_value & ref_value) != act_value;
+ return (act_value & _ref_value) != act_value;
case RelationalOperator::matches_icase: // contains any
- return (act_value & ref_value) != 0;
+ return (act_value & _ref_value) != 0;
case RelationalOperator::doesnt_match_icase: // contains none of
- return (act_value & ref_value) == 0;
+ return (act_value & _ref_value) == 0;
case RelationalOperator::less:
- return act_value < ref_value;
+ return act_value < _ref_value;
case RelationalOperator::greater_or_equal:
- return act_value >= ref_value;
+ return act_value >= _ref_value;
case RelationalOperator::greater:
- return act_value > ref_value;
+ return act_value > _ref_value;
case RelationalOperator::less_or_equal:
- return act_value <= ref_value;
+ return act_value <= _ref_value;
}
return false; // unreachable
}
void IntFilter::findIntLimits(const std::string &column_name, int *lower,
int *upper,
- std::chrono::seconds timezone_offset) const {
+ std::chrono::seconds /*timezone_offset*/) const {
if (column_name != columnName()) {
return; // wrong column
}
@@ -89,45 +78,43 @@ void IntFilter::findIntLimits(const std::string &column_name, int
*lower,
return; // already empty interval
}
- int32_t ref_value = convertRefValue(timezone_offset);
-
/* [lower, upper[ is some interval. This filter might restrict that interval
to a smaller interval.
*/
switch (_relOp) {
case RelationalOperator::equal:
- if (ref_value >= *lower && ref_value < *upper) {
- *lower = ref_value;
- *upper = ref_value + 1;
+ if (_ref_value >= *lower && _ref_value < *upper) {
+ *lower = _ref_value;
+ *upper = _ref_value + 1;
} else {
*lower = *upper;
}
return;
case RelationalOperator::not_equal:
- if (ref_value == *lower) {
+ if (_ref_value == *lower) {
*lower = *lower + 1;
- } else if (ref_value == *upper - 1) {
+ } else if (_ref_value == *upper - 1) {
*upper = *upper - 1;
}
return;
case RelationalOperator::less:
- if (ref_value < *upper) {
- *upper = ref_value;
+ if (_ref_value < *upper) {
+ *upper = _ref_value;
}
return;
case RelationalOperator::greater_or_equal:
- if (ref_value > *lower) {
- *lower = ref_value;
+ if (_ref_value > *lower) {
+ *lower = _ref_value;
}
return;
case RelationalOperator::greater:
- if (ref_value >= *lower) {
- *lower = ref_value + 1;
+ if (_ref_value >= *lower) {
+ *lower = _ref_value + 1;
}
return;
case RelationalOperator::less_or_equal:
- if (ref_value < *upper - 1) {
- *upper = ref_value + 1;
+ if (_ref_value < *upper - 1) {
+ *upper = _ref_value + 1;
}
return;
case RelationalOperator::matches:
@@ -143,21 +130,20 @@ void IntFilter::findIntLimits(const std::string &column_name,
int *lower,
}
}
-bool IntFilter::optimizeBitmask(const std::string &column_name, uint32_t *mask,
- std::chrono::seconds timezone_offset) const {
- int32_t ref_value = convertRefValue(timezone_offset);
-
+bool IntFilter::optimizeBitmask(
+ const std::string &column_name, uint32_t *mask,
+ std::chrono::seconds /*timezone_offset*/) const {
if (column_name != columnName()) {
return false; // wrong column
}
- if (ref_value < 0 || ref_value > 31) {
+ if (_ref_value < 0 || _ref_value > 31) {
return true; // not optimizable by 32bit bit mask
}
// Our task is to remove those bits from mask that are deselected by the
// filter.
- uint32_t bit = 1 << ref_value;
+ uint32_t bit = 1 << _ref_value;
switch (_relOp) {
case RelationalOperator::equal:
@@ -176,7 +162,7 @@ bool IntFilter::optimizeBitmask(const std::string &column_name,
uint32_t *mask,
}
return true;
case RelationalOperator::less_or_equal:
- if (ref_value == 31) {
+ if (_ref_value == 31) {
return true;
}
bit <<= 1;
diff --git a/livestatus/src/IntFilter.h b/livestatus/src/IntFilter.h
index 1091d44..5e0173c 100644
--- a/livestatus/src/IntFilter.h
+++ b/livestatus/src/IntFilter.h
@@ -38,7 +38,7 @@ class Row;
class IntFilter : public ColumnFilter {
public:
IntFilter(const IntColumn &column, RelationalOperator relOp,
- std::string value);
+ const std::string &value);
bool accepts(Row row, const contact *auth_user,
std::chrono::seconds timezone_offset) const override;
@@ -54,10 +54,7 @@ public:
private:
const IntColumn &_column;
const RelationalOperator _relOp;
- const std::string _ref_string;
-
- bool adjustWithTimezoneOffset() const;
- int32_t convertRefValue(std::chrono::seconds timezone_offset) const;
+ const int32_t _ref_value;
};
#endif // IntFilter_h
diff --git a/livestatus/src/TimeFilter.cc b/livestatus/src/TimeFilter.cc
index f574df4..c24e693 100644
--- a/livestatus/src/TimeFilter.cc
+++ b/livestatus/src/TimeFilter.cc
@@ -25,23 +25,19 @@
#include "TimeFilter.h"
#include <cstdlib>
#include <ostream>
-#include <utility>
#include "Logger.h"
#include "Row.h"
#include "TimeColumn.h"
TimeFilter::TimeFilter(const TimeColumn &column, RelationalOperator relOp,
- std::string value)
- : _column(column), _relOp(relOp), _ref_string(std::move(value)) {}
+ const std::string &value)
+ : _column(column), _relOp(relOp), _ref_value(atoi(value.c_str())) {}
std::string TimeFilter::columnName() const { return _column.name(); }
-bool TimeFilter::adjustWithTimezoneOffset() const { return true; }
-
int32_t TimeFilter::convertRefValue(
std::chrono::seconds timezone_offset) const {
- return atoi(_ref_string.c_str()) -
- (adjustWithTimezoneOffset() ? timezone_offset.count() : 0);
+ return _ref_value - timezone_offset.count();
}
bool TimeFilter::accepts(Row row, const contact *auth_user,
diff --git a/livestatus/src/TimeFilter.h b/livestatus/src/TimeFilter.h
index 15143dc..551a689 100644
--- a/livestatus/src/TimeFilter.h
+++ b/livestatus/src/TimeFilter.h
@@ -38,7 +38,7 @@ class TimeColumn;
class TimeFilter : public ColumnFilter {
public:
TimeFilter(const TimeColumn &column, RelationalOperator relOp,
- std::string value);
+ const std::string &value);
bool accepts(Row row, const contact *auth_user,
std::chrono::seconds timezone_offset) const override;
@@ -54,9 +54,8 @@ public:
private:
const TimeColumn &_column;
const RelationalOperator _relOp;
- const std::string _ref_string;
+ const int32_t _ref_value;
- bool adjustWithTimezoneOffset() const;
int32_t convertRefValue(std::chrono::seconds timezone_offset) const;
};