diff --git a/Demos/src/DrawMapDirectX.cpp b/Demos/src/DrawMapDirectX.cpp index a329f0ce7..9fb5a2b0b 100644 --- a/Demos/src/DrawMapDirectX.cpp +++ b/Demos/src/DrawMapDirectX.cpp @@ -38,6 +38,7 @@ src/DrawMapDirectX ../maps/nordrhein-westfalen ../stylesheets/standard.oss 51.51 #include #include +#include #include diff --git a/Demos/src/DrawMapGDI.cpp b/Demos/src/DrawMapGDI.cpp index 65ce9a958..e6bbfbcc5 100644 --- a/Demos/src/DrawMapGDI.cpp +++ b/Demos/src/DrawMapGDI.cpp @@ -25,6 +25,7 @@ src/DrawMapGDI ../maps/nordrhein-westfalen ../stylesheets/standard.oss 51.51241 */ #include +#include #include diff --git a/Demos/src/Routing.cpp b/Demos/src/Routing.cpp index b3a1b9d97..a7d138216 100644 --- a/Demos/src/Routing.cpp +++ b/Demos/src/Routing.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include diff --git a/Tests/src/PerformanceTest.cpp b/Tests/src/PerformanceTest.cpp index 84491c9f7..85949f68e 100644 --- a/Tests/src/PerformanceTest.cpp +++ b/Tests/src/PerformanceTest.cpp @@ -19,6 +19,7 @@ #include #include +#include #include #include diff --git a/libosmscout-client-qt/src/osmscoutclientqt/ElevationChartWidget.cpp b/libosmscout-client-qt/src/osmscoutclientqt/ElevationChartWidget.cpp index 22fa1f3b6..d575cbe4c 100644 --- a/libosmscout-client-qt/src/osmscoutclientqt/ElevationChartWidget.cpp +++ b/libosmscout-client-qt/src/osmscoutclientqt/ElevationChartWidget.cpp @@ -18,11 +18,16 @@ */ #include -#include -#include #include +#include +#include + +#include + +#include + namespace osmscout { ElevationChartWidget::ElevationChartWidget(QQuickItem* parent): diff --git a/libosmscout-gpx/src/osmscoutgpx/Export.cpp b/libosmscout-gpx/src/osmscoutgpx/Export.cpp index a91c4ac8c..a77e5a4da 100644 --- a/libosmscout-gpx/src/osmscoutgpx/Export.cpp +++ b/libosmscout-gpx/src/osmscoutgpx/Export.cpp @@ -26,6 +26,7 @@ #include #include #include +#include using namespace osmscout; using namespace osmscout::gpx; diff --git a/libosmscout-map/src/osmscoutmap/MapPainter.cpp b/libosmscout-map/src/osmscoutmap/MapPainter.cpp index 0d6e4d7ab..5b624f2a6 100644 --- a/libosmscout-map/src/osmscoutmap/MapPainter.cpp +++ b/libosmscout-map/src/osmscoutmap/MapPainter.cpp @@ -19,10 +19,9 @@ #include -#include - #include #include +#include #include diff --git a/libosmscout/CMakeLists.txt b/libosmscout/CMakeLists.txt index 314f0cc07..7dfd7fdd4 100644 --- a/libosmscout/CMakeLists.txt +++ b/libosmscout/CMakeLists.txt @@ -163,6 +163,7 @@ set(HEADER_FILES_UTIL include/osmscout/util/GeoBox.h include/osmscout/util/Geometry.h include/osmscout/util/Logger.h + include/osmscout/util/LoggerImpl.h include/osmscout/util/Magnification.h include/osmscout/util/MemoryMonitor.h include/osmscout/util/NodeUseMap.h @@ -273,6 +274,7 @@ set(SOURCE_FILES src/osmscout/util/GeoBox.cpp src/osmscout/util/Geometry.cpp src/osmscout/util/Logger.cpp + src/osmscout/util/LoggerImpl.cpp src/osmscout/util/Magnification.cpp src/osmscout/util/MemoryMonitor.cpp src/osmscout/util/NodeUseMap.cpp diff --git a/libosmscout/include/meson.build b/libosmscout/include/meson.build index fdadeced9..aff701d76 100644 --- a/libosmscout/include/meson.build +++ b/libosmscout/include/meson.build @@ -89,6 +89,7 @@ osmscoutHeader = [ 'osmscout/util/GeoBox.h', 'osmscout/util/Geometry.h', 'osmscout/util/Logger.h', + 'osmscout/util/LoggerImpl.h', 'osmscout/util/Magnification.h', 'osmscout/util/MemoryMonitor.h', 'osmscout/util/NodeUseMap.h', diff --git a/libosmscout/include/osmscout/util/Logger.h b/libosmscout/include/osmscout/util/Logger.h index 333fe11cd..cc4adf2ec 100644 --- a/libosmscout/include/osmscout/util/Logger.h +++ b/libosmscout/include/osmscout/util/Logger.h @@ -20,15 +20,14 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include + #include #include -#include -#include - -#include #include +#include // Since we have a DEBUG enumeration member #ifdef DEBUG @@ -345,65 +344,6 @@ namespace osmscout { } }; - /** - * \ingroup Logging - * The StreamLogger allows to direct logging output to a standard library std::ostream. - * IT allows to assign one stream for DEBUG and INFO logging and a different stream - * for WARN and ERROR log output. - */ - class OSMSCOUT_API StreamLogger : public Logger - { - private: - /** - * \ingroup Logging - * Special Destination implementation that delegates printing to the assigned - * std::ostream. - */ - class OSMSCOUT_API StreamDestination : public Destination - { - private: - std::ostream& stream; - - public: - explicit StreamDestination(std::ostream& stream); - - void Print(const std::string& value) override; - void Print(const std::string_view& value) override; - void Print(const char* value) override; - void Print(bool value) override; - void Print(short value) override; - void Print(unsigned short value) override; - void Print(int value) override; - void Print(unsigned int value) override; - void Print(long value) override; - void Print(unsigned long value) override; - void Print(long long value) override; - void Print(unsigned long long value) override; - void PrintLn() override; - }; - - private: - StreamDestination infoDestination; - StreamDestination errorDestination; - - public: - StreamLogger(std::ostream& infoStream, - std::ostream& errorStream); - - Line Log(Level level) override; - }; - - /** - * \ingroup Logging - * The console logger extends the StreamLogger by assigning std::cout for normal - * loging output and std::cerr for error output. - */ - class OSMSCOUT_API ConsoleLogger : public StreamLogger - { - public: - ConsoleLogger(); - }; - /** * \ingroup Logging * Simple logging proxy object that encapsulates one exchangeable global diff --git a/libosmscout/include/osmscout/util/LoggerImpl.h b/libosmscout/include/osmscout/util/LoggerImpl.h new file mode 100644 index 000000000..acee74816 --- /dev/null +++ b/libosmscout/include/osmscout/util/LoggerImpl.h @@ -0,0 +1,113 @@ +#ifndef OSMSCOUT_UTIL_LOGGER_IMPL_H +#define OSMSCOUT_UTIL_LOGGER_IMPL_H + +/* + This source is part of the libosmscout library + Copyright (C) 2015 Tim Teulings + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#include + +#include + +#include + +namespace osmscout { + + /** + * \ingroup Logging + * The StreamLogger allows to direct logging output to a standard library std::ostream. + * IT allows to assign one stream for DEBUG and INFO logging and a different stream + * for WARN and ERROR log output. + */ + class OSMSCOUT_API StreamLogger : public Logger + { + private: + /** + * \ingroup Logging + * Special Destination implementation that delegates printing to the assigned + * std::ostream. + */ + class OSMSCOUT_API StreamDestination : public Destination + { + private: + std::ostream& stream; + + public: + explicit StreamDestination(std::ostream& stream); + + void Print(const std::string& value) override; + void Print(const std::string_view& value) override; + void Print(const char* value) override; + void Print(bool value) override; + void Print(short value) override; + void Print(unsigned short value) override; + void Print(int value) override; + void Print(unsigned int value) override; + void Print(long value) override; + void Print(unsigned long value) override; + void Print(long long value) override; + void Print(unsigned long long value) override; + void PrintLn() override; + }; + + private: + StreamDestination infoDestination; + StreamDestination errorDestination; + + public: + StreamLogger(std::ostream& infoStream, + std::ostream& errorStream); + + Line Log(Level level) override; + }; + + /** + * \ingroup Logging + * The console logger extends the StreamLogger by assigning std::cout for normal + * loging output and std::cerr for error output. + */ + class OSMSCOUT_API ConsoleLogger : public StreamLogger + { + public: + ConsoleLogger(); + }; + + /** + * \ingroup Logging + * The one an donly global instance of the logger that should get used + * for all logging output. + */ + extern OSMSCOUT_API Log log; +} + +/** + * \defgroup Logging + * + * A logger is a special output stream, that is used by the library. + * + * The logger has a uniform interface independent of the actual + * data sink the information is stored to. + * + * This allows the application developer (and library user) to + * redirect logging output either to the console, to some special + * OS information sink, to "nowhere", to a file or any other location. + * + * The actual logger used can get exchanged by using Log::SetLogger. + */ + +#endif diff --git a/libosmscout/src/meson.build b/libosmscout/src/meson.build index 9284cc831..4074704ab 100644 --- a/libosmscout/src/meson.build +++ b/libosmscout/src/meson.build @@ -79,6 +79,7 @@ osmscoutSrc = [ 'src/osmscout/util/GeoBox.cpp', 'src/osmscout/util/Geometry.cpp', 'src/osmscout/util/Logger.cpp', + 'src/osmscout/util/LoggerImpl.cpp', 'src/osmscout/util/Magnification.cpp', 'src/osmscout/util/MemoryMonitor.cpp', 'src/osmscout/util/NodeUseMap.cpp', diff --git a/libosmscout/src/osmscout/util/HTMLWriter.cpp b/libosmscout/src/osmscout/util/HTMLWriter.cpp index 4f6479080..4fadf7776 100644 --- a/libosmscout/src/osmscout/util/HTMLWriter.cpp +++ b/libosmscout/src/osmscout/util/HTMLWriter.cpp @@ -19,9 +19,11 @@ #include +#include +#include + #include #include -#include namespace osmscout { diff --git a/libosmscout/src/osmscout/util/Logger.cpp b/libosmscout/src/osmscout/util/Logger.cpp index 38328f68a..5c6797caf 100644 --- a/libosmscout/src/osmscout/util/Logger.cpp +++ b/libosmscout/src/osmscout/util/Logger.cpp @@ -19,8 +19,7 @@ #include -#include -#include +#include #include @@ -97,100 +96,6 @@ namespace osmscout { return Log(ERROR); } - StreamLogger::StreamDestination::StreamDestination(std::ostream& stream) - : stream(stream) - { - // no code - } - - void StreamLogger::StreamDestination::Print(const std::string& value) - { - stream << value; - } - - void StreamLogger::StreamDestination::Print(const std::string_view& value) - { - stream << value; - } - - void StreamLogger::StreamDestination::Print(const char* value) - { - stream << value; - } - - void StreamLogger::StreamDestination::Print(bool value) - { - stream << (value ? "true" : "false"); - } - - void StreamLogger::StreamDestination::Print(short value) - { - stream << value; - } - - void StreamLogger::StreamDestination::Print(unsigned short value) - { - stream << value; - } - - void StreamLogger::StreamDestination::Print(int value) - { - stream << value; - } - - void StreamLogger::StreamDestination::Print(unsigned int value) - { - stream << value; - } - - void StreamLogger::StreamDestination::Print(long value) - { - stream << value; - } - - void StreamLogger::StreamDestination::Print(unsigned long value) - { - stream << value; - } - - void StreamLogger::StreamDestination::Print(long long value) - { - stream << value; - } - - void StreamLogger::StreamDestination::Print(unsigned long long value) - { - stream << value; - } - - void StreamLogger::StreamDestination::PrintLn() - { - stream << std::endl; - } - - StreamLogger::StreamLogger(std::ostream& infoStream, - std::ostream& errorStream) - : infoDestination(infoStream), - errorDestination(errorStream) - { - // no code - } - - Logger::Line StreamLogger::Log(Level level) - { - if (level==DEBUG || level==INFO) { - return Line(infoDestination); - } - - return Line(errorDestination); - } - - ConsoleLogger::ConsoleLogger() - : StreamLogger(std::cout,std::cerr) - { - // no code - } - Log::Log() : logger(new ConsoleLogger()) { diff --git a/libosmscout/src/osmscout/util/LoggerImpl.cpp b/libosmscout/src/osmscout/util/LoggerImpl.cpp new file mode 100644 index 000000000..c8aef9c4a --- /dev/null +++ b/libosmscout/src/osmscout/util/LoggerImpl.cpp @@ -0,0 +1,120 @@ +/* + This source is part of the libosmscout library + Copyright (C) 2015 Tim Teulings + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#include + +#include + +namespace osmscout { + + StreamLogger::StreamDestination::StreamDestination(std::ostream& stream) + : stream(stream) + { + // no code + } + + void StreamLogger::StreamDestination::Print(const std::string& value) + { + stream << value; + } + + void StreamLogger::StreamDestination::Print(const std::string_view& value) + { + stream << value; + } + + void StreamLogger::StreamDestination::Print(const char* value) + { + stream << value; + } + + void StreamLogger::StreamDestination::Print(bool value) + { + stream << (value ? "true" : "false"); + } + + void StreamLogger::StreamDestination::Print(short value) + { + stream << value; + } + + void StreamLogger::StreamDestination::Print(unsigned short value) + { + stream << value; + } + + void StreamLogger::StreamDestination::Print(int value) + { + stream << value; + } + + void StreamLogger::StreamDestination::Print(unsigned int value) + { + stream << value; + } + + void StreamLogger::StreamDestination::Print(long value) + { + stream << value; + } + + void StreamLogger::StreamDestination::Print(unsigned long value) + { + stream << value; + } + + void StreamLogger::StreamDestination::Print(long long value) + { + stream << value; + } + + void StreamLogger::StreamDestination::Print(unsigned long long value) + { + stream << value; + } + + void StreamLogger::StreamDestination::PrintLn() + { + stream << std::endl; + } + + StreamLogger::StreamLogger(std::ostream& infoStream, + std::ostream& errorStream) + : infoDestination(infoStream), + errorDestination(errorStream) + { + // no code + } + + Logger::Line StreamLogger::Log(Level level) + { + if (level==DEBUG || level==INFO) { + return Line(infoDestination); + } + + return Line(errorDestination); + } + + ConsoleLogger::ConsoleLogger() + : StreamLogger(std::cout,std::cerr) + { + // no code + } +} +