aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Kummerlaender2016-02-10 21:38:10 +0100
committerAdrian Kummerlaender2016-02-10 21:38:10 +0100
commit801ddda073b04c9751bc9e4f935bd102d7741c7b (patch)
treeba89c22d5ac7d1a6ea6367fab17376acf3f7b3b7
parent77ca603e933af25088057dc5e26cfda84bde7147 (diff)
downloadchange-801ddda073b04c9751bc9e4f935bd102d7741c7b.tar
change-801ddda073b04c9751bc9e4f935bd102d7741c7b.tar.gz
change-801ddda073b04c9751bc9e4f935bd102d7741c7b.tar.bz2
change-801ddda073b04c9751bc9e4f935bd102d7741c7b.tar.lz
change-801ddda073b04c9751bc9e4f935bd102d7741c7b.tar.xz
change-801ddda073b04c9751bc9e4f935bd102d7741c7b.tar.zst
change-801ddda073b04c9751bc9e4f935bd102d7741c7b.zip
Replace macro argument expansion with more idiomatic recursive template
-rw-r--r--CMakeLists.txt1
-rw-r--r--src/utility/logger.cc21
-rw-r--r--src/utility/logger.h33
3 files changed, 31 insertions, 24 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index f61200c..eef9ff4 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -14,6 +14,7 @@ add_library(
ChangeLog
SHARED
src/change_log.cc
+ src/utility/logger.cc
src/tracking/change_tracker.cc
)
diff --git a/src/utility/logger.cc b/src/utility/logger.cc
new file mode 100644
index 0000000..cb5c79a
--- /dev/null
+++ b/src/utility/logger.cc
@@ -0,0 +1,21 @@
+#include "logger.h"
+
+namespace utility {
+
+// Forward the contents of a given standard output stream to the log target
+//
+// While `this->stream_ << stream.rdbuf()` would be more effective it sadly
+// does not work with `boost::process::pistream` due to a broken pipe error
+// in conjunction with the required `boost::process::capture_stream` context
+// flag.
+//
+void Logger::forward(boost::process::pistream& stream) {
+ std::lock_guard<std::mutex> guard(this->write_mutex_);
+
+ this->stream_ << std::string(
+ (std::istreambuf_iterator<char>(stream)),
+ (std::istreambuf_iterator<char>())
+ );
+}
+
+}
diff --git a/src/utility/logger.h b/src/utility/logger.h
index 6fd6613..49b7cc1 100644
--- a/src/utility/logger.h
+++ b/src/utility/logger.h
@@ -10,45 +10,30 @@
namespace utility {
class Logger {
- #define FOR_EACH_ARGUMENT(...)\
- auto&& tmp = { (__VA_ARGS__, 0)... }; (void) tmp;
-
public:
Logger(const int target_fd):
buffer_(target_fd, std::ios::out),
stream_(&this->buffer_) { }
- template <typename... Args>
- void append(const Args&... args) {
- std::lock_guard<std::mutex> guard(this->write_mutex_);
+ template <typename Head>
+ inline void append(Head&& head) {
+ this->stream_ << head << std::endl;
+ }
- FOR_EACH_ARGUMENT(this->stream_ << args);
+ template <typename Head, typename... Tail>
+ inline void append(Head&& head, Tail&&... tail) {
+ this->stream_ << head;
- this->stream_ << std::endl;
+ this->append(std::forward<Tail>(tail)...);
}
- // Forward the contents of a given standard output stream to the log target
- //
- // While `this->stream_ << stream.rdbuf()` would be more effective it sadly
- // does not work with `boost::process::pistream` due to a broken pipe error
- // in conjunction with the required `boost::process::capture_stream` context
- // flag.
- //
- void forward(boost::process::pistream& stream) {
- std::lock_guard<std::mutex> guard(this->write_mutex_);
-
- this->stream_ << std::string(
- (std::istreambuf_iterator<char>(stream)),
- (std::istreambuf_iterator<char>())
- );
- }
+ void forward(boost::process::pistream&);
private:
__gnu_cxx::stdio_filebuf<char> buffer_;
std::ostream stream_;
std::mutex write_mutex_;
- #undef FOR_EACH_ARGUMENT
};
}