summaryrefslogtreecommitdiff
path: root/dwarflint
diff options
context:
space:
mode:
authorPetr Machata <pmachata@redhat.com>2011-04-06 18:42:42 +0200
committerPetr Machata <pmachata@redhat.com>2011-04-06 18:42:42 +0200
commit9e39d260db9b566e19dd5f2df8cc62a8151bc211 (patch)
treea2bc1188c5267946caecd760dacbcdfee9fb2354 /dwarflint
parent50afa439a10b571f951439f325cea13d92e87e29 (diff)
downloadelfutils-9e39d260db9b566e19dd5f2df8cc62a8151bc211.tar.gz
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;
Diffstat (limited to 'dwarflint')
-rw-r--r--dwarflint/messages.cc45
-rw-r--r--dwarflint/messages.hh13
2 files changed, 42 insertions, 16 deletions
diff --git a/dwarflint/messages.cc b/dwarflint/messages.cc
index 04519197..4d63e2e8 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,22 +336,50 @@ 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)
{
return *this << message.c_str ();
diff --git a/dwarflint/messages.hh b/dwarflint/messages.hh
index 0efc9d36..bd945c42 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);