Module: check_mk
Branch: master
Commit: 3b84d485290bb70344a5d316350f9a3f19e16fb2
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=3b84d485290bb7…
Author: Sven Panne <sp(a)mathias-kettner.de>
Date: Tue Nov 29 10:16:27 2016 +0100
Fetched livestatus from downstream.
---
livestatus/src/Table.cc | 21 +++++++--------------
livestatus/src/Table.h | 5 +++--
livestatus/src/TableEventConsoleReplication.cc | 5 ++++-
3 files changed, 14 insertions(+), 17 deletions(-)
diff --git a/livestatus/src/Table.cc b/livestatus/src/Table.cc
index 801f99a..7621f39 100644
--- a/livestatus/src/Table.cc
+++ b/livestatus/src/Table.cc
@@ -23,6 +23,7 @@
// Boston, MA 02110-1301 USA.
#include "Table.h"
+#include <cassert>
#include <ostream>
#include "Column.h"
#include "DynamicColumn.h"
@@ -30,7 +31,9 @@
#include "StringUtils.h"
using mk::starts_with;
+using std::move;
using std::string;
+using std::unique_ptr;
Table::Table(Logger *logger) : _logger(logger) {}
@@ -38,25 +41,15 @@ Table::~Table() {
for (auto &column : _columns) {
delete column.second;
}
-
- for (auto &dynamic_column : _dynamic_columns) {
- delete dynamic_column.second;
- }
}
void Table::addColumn(Column *col) {
- // Do not insert column if one with that name already exists. Delete that
- // column in that case. (Needed e.g. for TableLog->TableHosts, which both
- // define host_name.)
- if (column(col->name()) != nullptr) {
- delete col;
- } else {
- _columns.emplace(col->name(), col);
- }
+ assert(column(col->name()) == nullptr);
+ _columns.emplace(col->name(), col);
}
-void Table::addDynamicColumn(DynamicColumn *dyncol) {
- _dynamic_columns.emplace(dyncol->name(), dyncol);
+void Table::addDynamicColumn(unique_ptr<DynamicColumn> dyncol) {
+ _dynamic_columns.emplace(dyncol->name(), move(dyncol));
}
Column *Table::column(string colname) {
diff --git a/livestatus/src/Table.h b/livestatus/src/Table.h
index a4af3d1..fc3767f 100644
--- a/livestatus/src/Table.h
+++ b/livestatus/src/Table.h
@@ -27,6 +27,7 @@
#include "config.h" // IWYU pragma: keep
#include <map>
+#include <memory>
#include <string>
#include <utility>
#include "nagios.h" // IWYU pragma: keep
@@ -42,7 +43,7 @@ public:
virtual ~Table();
void addColumn(Column *);
- void addDynamicColumn(DynamicColumn *);
+ void addDynamicColumn(std::unique_ptr<DynamicColumn> col);
template <typename Predicate>
bool any_column(Predicate pred) {
@@ -91,7 +92,7 @@ private:
Column *dynamicColumn(const std::string &name, const std::string &rest);
std::map<std::string, Column *> _columns;
- std::map<std::string, DynamicColumn *> _dynamic_columns;
+ std::map<std::string, std::unique_ptr<DynamicColumn>> _dynamic_columns;
};
#endif // Table_h
diff --git a/livestatus/src/TableEventConsoleReplication.cc
b/livestatus/src/TableEventConsoleReplication.cc
index 78ccfbd..3d2e394 100644
--- a/livestatus/src/TableEventConsoleReplication.cc
+++ b/livestatus/src/TableEventConsoleReplication.cc
@@ -23,15 +23,18 @@
// Boston, MA 02110-1301 USA.
#include "TableEventConsoleReplication.h"
+#include <memory>
+#include "DynamicColumn.h"
#include "DynamicEventConsoleReplicationColumn.h"
#include "MonitoringCore.h"
#include "Query.h"
+using std::make_unique;
using std::string;
TableEventConsoleReplication::TableEventConsoleReplication(MonitoringCore *core)
: Table(core->loggerLivestatus()) {
- addDynamicColumn(new DynamicEventConsoleReplicationColumn(
+ addDynamicColumn(make_unique<DynamicEventConsoleReplicationColumn>(
"value", "The replication value", -1, -1, core));
}