// ========================================================= //
//                                                           //
//   File      : arb_msg_nospam.h                            //
//   Purpose   : provide suppression for repeated warnings   //
//                                                           //
//   Coded by Ralf Westram (coder@reallysoft.de) in Oct 22   //
//   http://www.arb-home.de/                                 //
//                                                           //
// ========================================================= //

#ifndef ARB_MSG_NOSPAM_H
#define ARB_MSG_NOSPAM_H

#ifndef ARBTOOLS_H
#include <arbtools.h>
#endif
#ifndef _GLIBCXX_STRING
#include <string>
#endif

class MessageSpamFilter : virtual Noncopyable {
    // When instantiated -> suppresses messages sent via GB_warning(),
    // if more than 'acceptedMessages' get shown while instance exists.
    //
    // * should be installed by all callers that might cause dozens or hundreds of warnings!
    // * warnings will still be logged into logfile via console.

    MessageSpamFilter    *previous_spamfilter;
    std::string  what_is_filtered;

    // message counters:
    int shown;
    int suppressed;
    int accepted;

    static MessageSpamFilter *current_spamfilter;

    void filter_warning(const char *message);
    bool is_spam();

public:
    MessageSpamFilter(std::string what_is_filtered_, int acceptedMessages = 5);
    ~MessageSpamFilter();

    // same as arb_handlers inferface:
    static void show_warning(const char *message);
};


#else
#error arb_msg_nospam.h included twice
#endif // ARB_MSG_NOSPAM_H

