From 9e39d260db9b566e19dd5f2df8cc62a8151bc211 Mon Sep 17 00:00:00 2001 From: Petr Machata Date: Wed, 6 Apr 2011 18:42:42 +0200 Subject: [PATCH] dwarflint: Support composed messages - This should be used like this: bool whether = false; wr_message (where, cat).id (this, whether) << stuff stuff; wr_message (where2, cat2).when (whether) << stuffy stuff; --- dwarflint/messages.cc | 45 +++++++++++++++++++++++++++++-------------- dwarflint/messages.hh | 13 +++++++++++-- 2 files changed, 42 insertions(+), 16 deletions(-) diff --git a/dwarflint/messages.cc b/dwarflint/messages.cc index 04519197c..4d63e2e88 100644 --- a/dwarflint/messages.cc +++ b/dwarflint/messages.cc @@ -328,17 +328,6 @@ message_count_filter::should_emit (void const *key) return 1; } -std::ostream & -message_context::emit (char const *str) -{ - ++error_count; - std::ostream &ret = get_stream (); - ret << _m_prefix; - if (_m_where) - ret << *_m_where << ": "; - return ret << str; -} - message_context::message_context (message_count_filter *filter, where const *where, char const *prefix) : _m_filter (filter) @@ -347,21 +336,49 @@ message_context::message_context (message_count_filter *filter, {} std::ostream & -message_context::operator << (char const *message) +message_context::when (bool whether) +{ + if (whether) + return get_stream (); + else + return nostream; +} + +std::ostream & +message_context::id (void const *key, bool &whether) { if (_m_filter == NULL) return nostream; - else if (int status = _m_filter->should_emit (message)) + else if (int status = _m_filter->should_emit (key)) { + ++error_count; if (status == -1) get_stream () << "(threshold reached for the following message)" << std::endl; - return emit (message); + whether = true; + return get_stream (); } else return nostream; } +std::ostream & +message_context::id (void const *key) +{ + bool whether; + return id (key, whether); +} + +std::ostream & +message_context::operator << (char const *message) +{ + std::ostream &ret = id (message); + ret << _m_prefix; + if (_m_where) + ret << *_m_where << ": "; + return ret << message; +} + std::ostream & message_context::operator << (std::string const &message) { diff --git a/dwarflint/messages.hh b/dwarflint/messages.hh index 0efc9d360..bd945c424 100644 --- a/dwarflint/messages.hh +++ b/dwarflint/messages.hh @@ -187,8 +187,6 @@ class message_context friend message_context wr_message (where const &wh, message_category cat); friend message_context wr_message (message_category cat); - std::ostream &emit (char const *str); - message_context (message_count_filter *filter, where const *where, char const *prefix); @@ -207,6 +205,17 @@ public: ss << t; return (*this) << ss.str (); } + + // Use KEY for count filtering. + std::ostream &id (void const *key); + + // Use KEY for count filtering. WHETHER is true if the message will + // be emitted. It doesn't touch that value otherwise, so WHETHER + // must be pre-initialized to false. + std::ostream &id (void const *key, bool &whether); + + // Return either the full stream, or a sink, depending on WHETHER. + std::ostream &when (bool whether); }; std::ostream &wr_error (where const &wh); -- 2.47.3