diff options
author | Adrian Kummerlaender | 2015-12-23 21:43:51 +0100 |
---|---|---|
committer | Adrian Kummerlaender | 2015-12-23 21:43:51 +0100 |
commit | cce63aca270c51fb3ce9790438e3c23864de0a87 (patch) | |
tree | 1dc5fe5357c7620345950189692130bd415bfd63 /src/utility.h | |
parent | b02091f847b94e94db465469e723fcf2aee81a01 (diff) | |
download | change-cce63aca270c51fb3ce9790438e3c23864de0a87.tar change-cce63aca270c51fb3ce9790438e3c23864de0a87.tar.gz change-cce63aca270c51fb3ce9790438e3c23864de0a87.tar.bz2 change-cce63aca270c51fb3ce9790438e3c23864de0a87.tar.lz change-cce63aca270c51fb3ce9790438e3c23864de0a87.tar.xz change-cce63aca270c51fb3ce9790438e3c23864de0a87.tar.zst change-cce63aca270c51fb3ce9790438e3c23864de0a87.zip |
Implement file change tracking using `diff`
The newly introduced `ChangeTracker` class is now keeping track of all tracked file in addition to spawning and managing a corresponding `diff` instance that enables printing pretty _patch-style_ change summaries to the logging target.
This commit introduces `boost-process` and `diff` as dependencies of this library.
Diffstat (limited to 'src/utility.h')
-rw-r--r-- | src/utility.h | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/src/utility.h b/src/utility.h index 96ee15c..1dc44ed 100644 --- a/src/utility.h +++ b/src/utility.h @@ -3,6 +3,8 @@ #include <ext/stdio_filebuf.h> +#include <boost/process.hpp> + #include <iostream> namespace utility { @@ -10,16 +12,30 @@ namespace utility { class Logger { public: Logger(const int target_fd): - buffer(target_fd, std::ios::out), - stream(&this->buffer) { } + buffer_(target_fd, std::ios::out), + stream_(&this->buffer) { } void append(const std::string& msg) { - this->stream << msg << std::endl; + this->stream_ << msg << std::endl; + } + + // 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) { + this->stream << std::string( + (std::istreambuf_iterator<char>(stream)), + (std::istreambuf_iterator<char>()) + ); } private: - __gnu_cxx::stdio_filebuf<char> buffer; - std::ostream stream; + __gnu_cxx::stdio_filebuf<char> buffer_; + std::ostream stream_; }; |