Skip to content

Commit

Permalink
messaget helper to encapsulate if(debug-verbosity) { complex output }
Browse files Browse the repository at this point in the history
  • Loading branch information
tautschnig committed Jun 4, 2018
1 parent e698be9 commit 9717af2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
18 changes: 18 additions & 0 deletions src/util/message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,21 @@ unsigned messaget::eval_verbosity(

return v;
}

/// Generate output to \p mstream using \p output_generator if the configured
/// verbosity is at least as high as that of \p mstream. Use whenever
/// generating output involves additional computational effort that should only
/// be spent when such output will actually be displayed.
/// \param mstream Output message stream
/// \param output_generator Function generating output
void messaget::conditional_output(
mstreamt &mstream,
const std::function<void(mstreamt &)> &output_generator) const
{
if(
message_handler &&
message_handler->get_verbosity() >= mstream.message_level)
{
output_generator(mstream);
}
}
7 changes: 6 additions & 1 deletion src/util/message.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ Author: Daniel Kroening, [email protected]
#ifndef CPROVER_UTIL_MESSAGE_H
#define CPROVER_UTIL_MESSAGE_H

#include <string>
#include <functional>
#include <iosfwd>
#include <sstream>
#include <string>

#include "invariant.h"
#include "json.h"
Expand Down Expand Up @@ -333,6 +334,10 @@ class messaget
return get_mstream(M_DEBUG);
}

void conditional_output(
mstreamt &mstream,
const std::function<void(mstreamt &)> &output_generator) const;

protected:
message_handlert *message_handler;
mutable mstreamt mstream;
Expand Down

0 comments on commit 9717af2

Please sign in to comment.