AttributeListColumn
Message-ID: <59fc4c68.bwKEkFIyOiz9cDEf%sp(a)mathias-kettner.de>
User-Agent: Heirloom mailx 12.5 6/20/10
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Module: check_mk
Branch: master
Commit: 861513218d043fe0a14a1c74c6b2b15b138ec7fd
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=861513218d043f…
Author: Sven Panne <sp(a)mathias-kettner.de>
Date: Fri Nov 3 11:36:15 2017 +0100
Yet another fix for the column class hierarchy, this time: AttributeListColumn
As its name and output behaviour implies, it derives from ListColumn now.
Filtering is done via via delegation to an int-based view.
The bit fiddling stuff is not yet in the right place, but this will be fixed
in another commit.
Change-Id: Ia45ae0c608812b24d1d6433c643b73da74d52728
---
livestatus/src/AttributeListColumn.cc | 24 +++++++-----------------
livestatus/src/AttributeListColumn.h | 27 ++++++++++++++-------------
2 files changed, 21 insertions(+), 30 deletions(-)
diff --git a/livestatus/src/AttributeListColumn.cc
b/livestatus/src/AttributeListColumn.cc
index 69de926..30494a9 100644
--- a/livestatus/src/AttributeListColumn.cc
+++ b/livestatus/src/AttributeListColumn.cc
@@ -31,9 +31,7 @@
#include <utility>
#include <vector>
#include "Filter.h"
-#include "IntFilter.h"
#include "Logger.h"
-#include "Renderer.h"
#include "Row.h"
#include "strutil.h"
@@ -53,30 +51,22 @@ std::map<std::string, unsigned long> known_attributes = {
using modified_atttibutes = std::bitset<32>;
} // namespace
-int32_t AttributeListColumn::getValue(Row row,
- const contact * /*unused*/) const {
- if (auto p = columnData<unsigned long>(row)) {
- return static_cast<int32_t>(*p);
- }
- return 0;
-}
-
-void AttributeListColumn::output(
- Row row, RowRenderer &r, const contact * /*auth_user*/,
+std::vector<std::string> AttributeListColumn::getValue(
+ Row row, const contact *auth_user,
std::chrono::seconds /*timezone_offset*/) const {
- ListRenderer l(r);
- modified_atttibutes values(getValue(row, nullptr));
+ modified_atttibutes values(_int_view_column.getValue(row, auth_user));
+ std::vector<std::string> attributes;
for (const auto &entry : known_attributes) {
if (values[entry.second]) {
- l.output(entry.first);
+ attributes.push_back(entry.first);
}
}
+ return attributes;
}
std::unique_ptr<Filter> AttributeListColumn::createFilter(
RelationalOperator relOp, const std::string &value) const {
- return std::make_unique<IntFilter>(*this, relOp,
- refValueFor(value, logger()));
+ return _int_view_column.createFilter(relOp, value);
}
// static
diff --git a/livestatus/src/AttributeListColumn.h b/livestatus/src/AttributeListColumn.h
index a07e288..984900b 100644
--- a/livestatus/src/AttributeListColumn.h
+++ b/livestatus/src/AttributeListColumn.h
@@ -27,37 +27,38 @@
#include "config.h" // IWYU pragma: keep
#include <chrono>
-#include <cstdint>
#include <memory>
#include <string>
-#include "Column.h"
-#include "IntColumn.h"
+#include <vector>
+#include "AttributeListAsIntColumn.h"
+#include "ListColumn.h"
#include "contact_fwd.h"
#include "opids.h"
class Filter;
class Logger;
class Row;
-class RowRenderer;
-class AttributeListColumn : public IntColumn {
+class AttributeListColumn : public ListColumn {
public:
AttributeListColumn(const std::string &name, const std::string &description,
int indirect_offset, int extra_offset,
int extra_extra_offset, int offset)
- : IntColumn(name, description, indirect_offset, extra_offset,
- extra_extra_offset, offset) {}
+ : ListColumn(name, description, indirect_offset, extra_offset,
+ extra_extra_offset, offset)
+ , _int_view_column(name, description, indirect_offset, extra_offset,
+ extra_extra_offset, offset) {}
- // API of Column
- ColumnType type() const override { return ColumnType::list; }
- void output(Row row, RowRenderer &r, const contact *auth_user,
- std::chrono::seconds timezone_offset) const override;
std::unique_ptr<Filter> createFilter(
RelationalOperator relOp, const std::string &value) const override;
- // API of IntColumn
- int32_t getValue(Row row, const contact *auth_user) const override;
+ std::vector<std::string> getValue(
+ Row row, const contact *auth_user,
+ std::chrono::seconds timezone_offset) const override;
static std::string refValueFor(const std::string &value, Logger *logger);
+
+private:
+ AttributeListAsIntColumn _int_view_column;
};
#endif // AttributeListColumn_h