From 6b6c098529668e5f6da03075718b8616867f0404 Mon Sep 17 00:00:00 2001 From: uvos Date: Wed, 16 Jun 2021 09:41:52 +0200 Subject: [PATCH] Split log into h and cpp --- CMakeLists.txt | 2 +- src/log.cpp | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/log.h | 46 +++++------------------------------- 3 files changed, 71 insertions(+), 41 deletions(-) create mode 100644 src/log.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 595cbfe..b74e663 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.0) project(uvosunwrap) -set(SRC_FILES_LIB src/unwrap.cpp src/drawing.cpp src/matutils.cpp src/bgremoval.cpp src/charuco.cpp src/harris.cpp) +set(SRC_FILES_LIB src/unwrap.cpp src/drawing.cpp src/matutils.cpp src/bgremoval.cpp src/charuco.cpp src/harris.cpp src/log.cpp) set(SRC_FILES_APP src/main.cpp) diff --git a/src/log.cpp b/src/log.cpp new file mode 100644 index 0000000..8d42351 --- /dev/null +++ b/src/log.cpp @@ -0,0 +1,64 @@ +/** +* Lubricant Detecter +* Copyright (C) 2021 Carl Klemm +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* version 3 as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the +* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +* Boston, MA 02110-1301, USA. +*/ + +#include "log.h" + +Log::Log(Level type) +{ + msglevel = type; + if(headers) + { + operator << ("["+getLabel(type)+"]"); + } +} + +Log::~Log() +{ + if(opened && endline) + { + std::cout<<'\n'; + } + opened = false; +} + + +std::string Log::getLabel(Level level) +{ + std::string label; + switch(level) + { + case DEBUG: + label = "DEBUG"; + break; + case INFO: + label = "INFO "; + break; + case WARN: + label = "WARN "; + break; + case ERROR: + label = "ERROR"; + break; + } + return label; +} + +bool Log::headers = false; +Log::Level Log::level = WARN; +bool Log::endline = false; diff --git a/src/log.h b/src/log.h index 5052a26..6d6e271 100644 --- a/src/log.h +++ b/src/log.h @@ -37,51 +37,17 @@ private: bool opened = false; Level msglevel = DEBUG; - inline std::string getLabel(Level level) - { - std::string label; - switch(level) - { - case DEBUG: - label = "DEBUG"; - break; - case INFO: - label = "INFO "; - break; - case WARN: - label = "WARN "; - break; - case ERROR: - label = "ERROR"; - break; - } - return label; - } + std::string getLabel(Level level); public: - - inline static bool headers = false; - inline static Level level = WARN; + static bool headers; + static Level level; + static bool endline; Log() {} - Log(Level type) - { - msglevel = type; - if(headers) - { - operator << ("["+getLabel(type)+"]"); - } - } - - ~Log() - { - if(opened) - { - std::cout<<'\n'; - } - opened = false; - } + Log(Level type); + ~Log(); template Log &operator<<(const T &msg) {