summaryrefslogtreecommitdiffstats
path: root/ingen
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2019-03-08 12:38:19 +0100
committerDavid Robillard <d@drobilla.net>2019-03-09 00:43:43 +0100
commit532af2452bac2cdd0e2732ad145fdc2b141a4afc (patch)
tree0b078c37a137ef0da3a1e76bc150e99f65f6d7dc /ingen
parent6bb3c48972d172fec244afae08a905e2246d9cda (diff)
downloadingen-532af2452bac2cdd0e2732ad145fdc2b141a4afc.tar.gz
ingen-532af2452bac2cdd0e2732ad145fdc2b141a4afc.tar.bz2
ingen-532af2452bac2cdd0e2732ad145fdc2b141a4afc.zip
Localise dependency on boost::format and improve logging API
Diffstat (limited to 'ingen')
-rw-r--r--ingen/Log.hpp38
-rw-r--r--ingen/client/SocketClient.hpp4
-rw-r--r--ingen/fmt.hpp38
3 files changed, 71 insertions, 9 deletions
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 <boost/format.hpp>
#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 <cstdarg>
+#include <cstdio>
+#include <functional>
+#include <string>
-typedef boost::basic_format<char> 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 <typename... Args>
+ void error(const char* format, Args&&... args)
+ {
+ error(fmt(format, std::forward<Args>(args)...));
+ }
+
+ template <typename... Args>
+ void info(const char* format, Args&&... args)
+ {
+ info(fmt(format, std::forward<Args>(args)...));
+ }
+
+ template <typename... Args>
+ void warn(const char* format, Args&&... args)
+ {
+ warn(fmt(format, std::forward<Args>(args)...));
+ }
+
+ template <typename... Args>
+ void trace(const char* format, Args&&... args)
+ {
+ trace(fmt(format, std::forward<Args>(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<Raul::Socket> 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<Interface>();
}
return SPtr<Interface>(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 <http://drobilla.net/>
+
+ 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 <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef INGEN_FMT_HPP
+#define INGEN_FMT_HPP
+
+#include <boost/format.hpp>
+
+#include <initializer_list>
+#include <string>
+
+namespace ingen {
+template <typename... Args>
+std::string
+fmt(const char* fmt, Args&&... args)
+{
+ boost::format f(fmt);
+ std::initializer_list<char> l{(static_cast<void>(f % args), char{})...};
+ (void)l;
+ return boost::str(f);
+}
+
+} // namespace ingen
+
+#endif // INGEN_FMT_HPP