From 9f90ce8de8865bd111191bf6fd7434ef6d3b75ab Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 27 Oct 2022 09:49:13 +0200 Subject: Add ability to use custom writer when flushing diag_record --- libbutl/diagnostics.cxx | 10 +++++----- libbutl/diagnostics.hxx | 11 ++++++++--- 2 files changed, 13 insertions(+), 8 deletions(-) (limited to 'libbutl') diff --git a/libbutl/diagnostics.cxx b/libbutl/diagnostics.cxx index f574fd6..3254e27 100644 --- a/libbutl/diagnostics.cxx +++ b/libbutl/diagnostics.cxx @@ -157,14 +157,14 @@ namespace butl void (*diag_record::writer) (const diag_record&) = &default_writer; void diag_record:: - flush () const + flush (void (*w) (const diag_record&)) const { if (!empty_) { if (epilogue_ == nullptr) { - if (writer != nullptr) - writer (*this); + if (w != nullptr || (w = writer) != nullptr) + w (*this); empty_ = true; } @@ -174,8 +174,8 @@ namespace butl // auto e (epilogue_); epilogue_ = nullptr; - e (*this); // Can throw. - flush (); // Call ourselves to write the data in case it returns. + e (*this); // Can throw. @@ TODO: pass writer. + flush (w); // Call ourselves to write the data in case it returns. } } } diff --git a/libbutl/diagnostics.hxx b/libbutl/diagnostics.hxx index 23aa14f..574695c 100644 --- a/libbutl/diagnostics.hxx +++ b/libbutl/diagnostics.hxx @@ -27,8 +27,11 @@ namespace butl LIBBUTL_SYMEXPORT extern std::ostream* diag_stream; // Acquire the diagnostics exclusive access mutex in ctor, release in dtor. - // An object of the type must be created prior to writing to diag_stream (see - // above). + // An object of the type must be created prior to writing to diag_stream + // (see above). + // + // Note that this class also manages the interaction with the progress + // printing (see below). // struct LIBBUTL_SYMEXPORT diag_stream_lock { @@ -128,8 +131,10 @@ namespace butl bool full () const {return !empty_;} + // Note that currently the passed writer is not passed to the epilogue. + // void - flush () const; + flush (void (*writer) (const diag_record&) = nullptr) const; void append (const char* indent, diag_epilogue* e) const -- cgit v1.1