Module: check_mk
Branch: master
Commit: 6ed69338bdc2321b88628c7e62a26554f984e4b5
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=6ed69338bdc232…
Author: Sven Panne <sp(a)mathias-kettner.de>
Date: Fri Jun 10 16:11:27 2016 +0200
Fetched Livestatus from downstream.
---
livestatus/src/OffsetStringMacroColumn.cc | 7 +++++--
livestatus/src/Query.cc | 21 +++++++--------------
livestatus/src/Query.h | 9 +++++----
livestatus/src/VariadicFilter.cc | 28 +++++++++++++++++++---------
livestatus/src/VariadicFilter.h | 5 ++++-
5 files changed, 40 insertions(+), 30 deletions(-)
diff --git a/livestatus/src/OffsetStringMacroColumn.cc
b/livestatus/src/OffsetStringMacroColumn.cc
index f295cd9..47dd7e7 100644
--- a/livestatus/src/OffsetStringMacroColumn.cc
+++ b/livestatus/src/OffsetStringMacroColumn.cc
@@ -25,8 +25,9 @@
#include "OffsetStringMacroColumn.h"
#include <stdlib.h>
#include <string.h>
-#include "AndingFilter.h"
+#include <memory>
#include "Query.h"
+#include "VariadicFilter.h"
#include "logger.h"
class Filter;
@@ -76,7 +77,9 @@ void OffsetStringMacroColumn::output(void *data, Query *query) {
Filter *OffsetStringMacroColumn::createFilter(RelationalOperator /*unused */,
const string & /*unused*/) {
logger(LG_INFO, "Sorry. No filtering on macro columns implemented yet");
- return new AndingFilter(); // always true
+ // TODO(sp) Use unique_ptr
+ return VariadicFilter::make(LogicalOperator::and_)
+ .release(); // always true
}
const char *OffsetStringMacroColumn::expandMacro(const char *macroname,
diff --git a/livestatus/src/Query.cc b/livestatus/src/Query.cc
index d5d560d..c5fc65c 100644
--- a/livestatus/src/Query.cc
+++ b/livestatus/src/Query.cc
@@ -28,17 +28,16 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <memory>
#include <ostream>
#include <utility>
#include <vector>
#include "Aggregator.h"
-#include "AndingFilter.h"
#include "Column.h"
#include "Filter.h"
#include "Logger.h"
#include "NegatingFilter.h"
#include "NullColumn.h"
-#include "OringFilter.h"
#include "OutputBuffer.h"
#include "StatsColumn.h"
#include "Table.h"
@@ -273,7 +272,7 @@ Filter *Query::createFilter(Column *column, RelationalOperator relOp,
}
void Query::parseAndOrLine(char *line, LogicalOperator andor,
- AndingFilter &filter, string header) {
+ VariadicFilter &filter, string header) {
char *value = next_field(&line);
if (value == nullptr) {
setError(
@@ -293,7 +292,7 @@ void Query::parseAndOrLine(char *line, LogicalOperator andor,
filter.combineFilters(number, andor);
}
-void Query::parseNegateLine(char *line, AndingFilter &filter, string header) {
+void Query::parseNegateLine(char *line, VariadicFilter &filter, string header) {
if (next_field(&line) != nullptr) {
setError(OutputBuffer::ResponseCode::invalid_header,
header + ": does not take any arguments");
@@ -329,18 +328,12 @@ void Query::parseStatsAndOrLine(char *line, LogicalOperator andor)
{
}
// The last 'number' StatsColumns must be of type StatsOperation::count
- VariadicFilter *variadic;
- if (andor == LogicalOperator::or_) {
- variadic = new OringFilter();
- } else {
- variadic = new AndingFilter();
- }
+ auto variadic = VariadicFilter::make(andor);
while (number > 0) {
if (_stats_columns.empty()) {
setError(OutputBuffer::ResponseCode::invalid_header,
"Invalid count for " + kind +
": too few Stats: headers available");
- delete variadic;
return;
}
@@ -349,7 +342,6 @@ void Query::parseStatsAndOrLine(char *line, LogicalOperator andor) {
setError(
OutputBuffer::ResponseCode::invalid_header,
"Can use " + kind + " only on Stats: headers of filter
type");
- delete variadic;
return;
}
variadic->addSubfilter(col->stealFilter());
@@ -357,8 +349,9 @@ void Query::parseStatsAndOrLine(char *line, LogicalOperator andor) {
_stats_columns.pop_back();
number--;
}
+ // TODO(sp) Use unique_ptr in StatsColumn.
_stats_columns.push_back(
- new StatsColumn(nullptr, variadic, StatsOperation::count));
+ new StatsColumn(nullptr, variadic.release(), StatsOperation::count));
}
void Query::parseStatsNegateLine(char *line) {
@@ -470,7 +463,7 @@ void Query::parseStatsLine(char *line) {
_show_column_headers = false;
}
-void Query::parseFilterLine(char *line, AndingFilter &filter) {
+void Query::parseFilterLine(char *line, VariadicFilter &filter) {
char *column_name = next_field(&line);
if (column_name == nullptr) {
setError(OutputBuffer::ResponseCode::invalid_header,
diff --git a/livestatus/src/Query.h b/livestatus/src/Query.h
index 0ad6e2f..0392e42 100644
--- a/livestatus/src/Query.h
+++ b/livestatus/src/Query.h
@@ -143,12 +143,13 @@ private:
void computeStatsGroupSpec(_stats_group_spec_t &groupspec, void *data);
Filter *createFilter(Column *column, RelationalOperator relOp,
const std::string &value);
- void parseFilterLine(char *line, AndingFilter &filter);
+ void parseFilterLine(char *line, VariadicFilter &filter);
void parseStatsLine(char *line);
void parseStatsGroupLine(char *line);
- void parseAndOrLine(char *line, LogicalOperator andor, AndingFilter &filter,
- std::string header);
- void parseNegateLine(char *line, AndingFilter &filter, std::string header);
+ void parseAndOrLine(char *line, LogicalOperator andor,
+ VariadicFilter &filter, std::string header);
+ void parseNegateLine(char *line, VariadicFilter &filter,
+ std::string header);
void parseStatsAndOrLine(char *line, LogicalOperator andor);
void parseStatsNegateLine(char *line);
void parseColumnsLine(char *line);
diff --git a/livestatus/src/VariadicFilter.cc b/livestatus/src/VariadicFilter.cc
index 97852d3..5abe276 100644
--- a/livestatus/src/VariadicFilter.cc
+++ b/livestatus/src/VariadicFilter.cc
@@ -29,7 +29,22 @@
#include "OringFilter.h"
#include "logger.h"
+using std::make_unique;
using std::string;
+using std::unique_ptr;
+
+// static
+unique_ptr<VariadicFilter> VariadicFilter::make(LogicalOperator logicOp) {
+ switch (logicOp) {
+ case LogicalOperator::and_:
+ return make_unique<AndingFilter>();
+ case LogicalOperator::or_:
+ return make_unique<OringFilter>();
+ }
+ return nullptr; // unreachable
+}
+
+VariadicFilter::VariadicFilter() {}
VariadicFilter::~VariadicFilter() {
for (auto &subfilter : _subfilters) {
@@ -74,16 +89,11 @@ void VariadicFilter::combineFilters(int count, LogicalOperator andor)
{
return;
}
- VariadicFilter
- *andorfilter; // OringFilter is subclassed from VariadicFilter
- if (andor == LogicalOperator::and_) {
- andorfilter = new AndingFilter();
- } else {
- andorfilter = new OringFilter();
- }
+ auto variadic = VariadicFilter::make(andor);
while ((count--) != 0) {
- andorfilter->addSubfilter(_subfilters.back());
+ variadic->addSubfilter(_subfilters.back());
_subfilters.pop_back();
}
- addSubfilter(andorfilter);
+ // TODO(sp) Use unique_ptr in addSubfilter.
+ addSubfilter(variadic.release());
}
diff --git a/livestatus/src/VariadicFilter.h b/livestatus/src/VariadicFilter.h
index d770e5e..93754ee 100644
--- a/livestatus/src/VariadicFilter.h
+++ b/livestatus/src/VariadicFilter.h
@@ -27,6 +27,7 @@
#include "config.h" // IWYU pragma: keep
#include <deque>
+#include <memory>
#include <string>
#include "Filter.h"
@@ -36,8 +37,9 @@ class VariadicFilter : public Filter {
public:
typedef std::deque<Filter *> _subfilters_t;
- VariadicFilter() {}
+ static std::unique_ptr<VariadicFilter> make(LogicalOperator logicOp);
virtual ~VariadicFilter();
+
bool isVariadicFilter() override { return true; }
void addSubfilter(Filter *);
Filter *stealLastSubfiler();
@@ -50,6 +52,7 @@ public:
int *upper) override;
protected:
+ VariadicFilter();
_subfilters_t _subfilters;
};