1 #ifndef __FASTJET_LIMITEDWARNING_HH__
2 #define __FASTJET_LIMITEDWARNING_HH__
35 #include "fastjet/internal/base.hh"
40 #include "fastjet/config.h"
41 #ifdef FASTJET_HAVE_LIMITED_THREAD_SAFETY
45 #include "fastjet/internal/thread_safety_helpers.hh"
47 FASTJET_BEGIN_NAMESPACE
61 LimitedWarning(
int max_warn_in) : _max_warn(max_warn_in), _this_warning_summary(0) {}
63 #ifdef FASTJET_HAVE_LIMITED_THREAD_SAFETY
66 : _max_warn(other._max_warn), _this_warning_summary{other._this_warning_summary.load()} {}
71 void warn(
const char * warning) {
warn(warning, _default_ostr);}
75 void warn(
const std::string & warning) {
warn(warning.c_str(), _default_ostr);}
78 void warn(
const char * warning, std::ostream * ostr);
81 void warn(
const std::string & warning, std::ostream * ostr) {
warn(warning.c_str(), ostr);}
89 #ifdef FASTJET_HAVE_LIMITED_THREAD_SAFETY
94 static void set_default_stream_and_mutex(std::ostream * ostr,
95 std::mutex * warnings_mutex) {
97 _stream_mutex = warnings_mutex;
104 _max_warn_default = max_warn;
113 int n_warn_so_far()
const;
117 static std::string summary();
122 typedef std::pair<std::string, thread_safety_helpers::AtomicCounter<unsigned int> > Summary;
123 #ifdef FASTJET_HAVE_LIMITED_THREAD_SAFETY
124 static std::atomic<int> _max_warn_default;
125 static std::atomic<std::ostream *> _default_ostr;
126 static std::atomic<std::mutex *> _stream_mutex;
127 static std::mutex _global_warnings_summary_mutex;
128 std::atomic<Summary*> _this_warning_summary;
130 static int _max_warn_default;
131 static std::ostream * _default_ostr;
132 Summary* _this_warning_summary;
138 static std::list< Summary > _global_warnings_summary;
142 FASTJET_END_NAMESPACE
class to provide facilities for giving warnings up to some maximum number of times and to provide glo...
void warn(const std::string &warning)
outputs a warning to standard error (or the user's default warning stream if set)
static void set_default_stream(std::ostream *ostr)
sets the default output stream for all warnings (by default cerr; passing a null pointer prevents war...
static void set_default_max_warn(int max_warn)
sets the default maximum number of warnings of a given kind before warning messages are silenced.
void warn(const char *warning)
outputs a warning to standard error (or the user's default warning stream if set)
LimitedWarning()
constructor that provides a default maximum number of warnings
void warn(const std::string &warning, std::ostream *ostr)
outputs a warning to the specified stream
int max_warn() const
the maximum number of warning messages that will be printed by this instance of the class
LimitedWarning(int max_warn_in)
constructor that provides a user-set max number of warnings