From 532af2452bac2cdd0e2732ad145fdc2b141a4afc Mon Sep 17 00:00:00 2001 From: David Robillard Date: Fri, 8 Mar 2019 12:38:19 +0100 Subject: Localise dependency on boost::format and improve logging API --- ingen/Log.hpp | 38 +++++++++++++++++++++++++++++++------- ingen/client/SocketClient.hpp | 4 ++-- ingen/fmt.hpp | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+), 9 deletions(-) create mode 100644 ingen/fmt.hpp (limited to 'ingen') diff --git a/ingen/Log.hpp b/ingen/Log.hpp index 4d1bd1ee..000afcbe 100644 --- a/ingen/Log.hpp +++ b/ingen/Log.hpp @@ -25,14 +25,18 @@ #include #include "ingen/LV2Features.hpp" +#include "ingen/fmt.hpp" #include "ingen/ingen.h" #include "lv2/core/lv2.h" #include "lv2/log/log.h" #include "lv2/urid/urid.h" -namespace ingen { +#include +#include +#include +#include -typedef boost::basic_format fmt; +namespace ingen { class Node; class URIs; @@ -63,11 +67,31 @@ public: void warn(const std::string& msg); void trace(const std::string& msg); - inline void error(const fmt& fmt) { error(fmt.str()); } - inline void info(const fmt& fmt) { info(fmt.str()); } - inline void warn(const fmt& fmt) { warn(fmt.str()); } - - int vtprintf(LV2_URID type, const char* fmt, va_list args); + template + void error(const char* format, Args&&... args) + { + error(fmt(format, std::forward(args)...)); + } + + template + void info(const char* format, Args&&... args) + { + info(fmt(format, std::forward(args)...)); + } + + template + void warn(const char* format, Args&&... args) + { + warn(fmt(format, std::forward(args)...)); + } + + template + void trace(const char* format, Args&&... args) + { + trace(fmt(format, std::forward(args)...)); + } + + int vtprintf(LV2_URID type, const char* format, va_list args); void set_flush(bool f) { _flush = f; } void set_trace(bool f) { _trace = f; } diff --git a/ingen/client/SocketClient.hpp b/ingen/client/SocketClient.hpp index bce5ab38..092ef9d2 100644 --- a/ingen/client/SocketClient.hpp +++ b/ingen/client/SocketClient.hpp @@ -57,8 +57,8 @@ public: SPtr sock(new Raul::Socket(type)); if (!sock->connect(uri)) { - world.log().error(fmt("Failed to connect <%1%> (%2%)\n") - % sock->uri() % strerror(errno)); + world.log().error("Failed to connect <%1%> (%2%)\n", + sock->uri(), strerror(errno)); return SPtr(); } return SPtr(new SocketClient(world, uri, sock, respondee)); diff --git a/ingen/fmt.hpp b/ingen/fmt.hpp new file mode 100644 index 00000000..3c792d3d --- /dev/null +++ b/ingen/fmt.hpp @@ -0,0 +1,38 @@ +/* + This file is part of Ingen. + Copyright 2007-2016 David Robillard + + Ingen is free software: you can redistribute it and/or modify it under the + terms of the GNU Affero General Public License as published by the Free + Software Foundation, either version 3 of the License, or any later version. + + Ingen 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 Affero General Public License for details. + + You should have received a copy of the GNU Affero General Public License + along with Ingen. If not, see . +*/ + +#ifndef INGEN_FMT_HPP +#define INGEN_FMT_HPP + +#include + +#include +#include + +namespace ingen { +template +std::string +fmt(const char* fmt, Args&&... args) +{ + boost::format f(fmt); + std::initializer_list l{(static_cast(f % args), char{})...}; + (void)l; + return boost::str(f); +} + +} // namespace ingen + +#endif // INGEN_FMT_HPP -- cgit v1.2.1