From 4d3d0bc5a68d420fcd7bd526d246d318fdfec05e Mon Sep 17 00:00:00 2001 From: Piotr Jarosik Date: Fri, 14 Jan 2022 09:25:18 +0100 Subject: [PATCH] Improved the implementation of Us4R to arrus logging mechanism. Replaced static hashmap with switch clause. --- .../us4r/external/ius4oem/Us4RLoggerWrapper.h | 36 ++++++++++++------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/arrus/core/devices/us4r/external/ius4oem/Us4RLoggerWrapper.h b/arrus/core/devices/us4r/external/ius4oem/Us4RLoggerWrapper.h index 3f20982b8..c076e5e03 100644 --- a/arrus/core/devices/us4r/external/ius4oem/Us4RLoggerWrapper.h +++ b/arrus/core/devices/us4r/external/ius4oem/Us4RLoggerWrapper.h @@ -3,6 +3,7 @@ #include #include +#include // us4r #include @@ -14,30 +15,41 @@ namespace arrus::devices { class Us4RLoggerWrapper : public us4r::Logger { public: - Us4RLoggerWrapper(arrus::Logger::SharedHandle logger) + explicit Us4RLoggerWrapper(arrus::Logger::SharedHandle logger) : logger(std::move(logger)) {} void log(const us4r::LogSeverity severity, const std::string &msg) override { - logger->log(sevMap.at(severity), msg); + switch(severity) { + case us4r::LogSeverity::TRACE: + logger->log(arrus::LogSeverity::TRACE, msg); + break; + case us4r::LogSeverity::DEBUG: + logger->log(arrus::LogSeverity::DEBUG, msg); + break; + case us4r::LogSeverity::INFO: + logger->log(arrus::LogSeverity::INFO, msg); + break; + case us4r::LogSeverity::WARNING: + logger->log(arrus::LogSeverity::WARNING, msg); + break; + case us4r::LogSeverity::ERROR: + logger->log(arrus::LogSeverity::ERROR, msg); + break; + case us4r::LogSeverity::FATAL: + logger->log(arrus::LogSeverity::FATAL, msg); + break; + default: + throw std::runtime_error("Unknown logging level"); + } } void setAttribute(const std::string &key, const std::string &value) override { logger->setAttribute(key, value); } - private: arrus::Logger::SharedHandle logger; - - static const inline std::unordered_map sevMap{ - {us4r::LogSeverity::TRACE, arrus::LogSeverity::TRACE}, - {us4r::LogSeverity::DEBUG, arrus::LogSeverity::DEBUG}, - {us4r::LogSeverity::INFO, arrus::LogSeverity::INFO}, - {us4r::LogSeverity::WARNING, arrus::LogSeverity::WARNING}, - {us4r::LogSeverity::ERROR, arrus::LogSeverity::ERROR}, - {us4r::LogSeverity::FATAL, arrus::LogSeverity::FATAL}, - }; }; }