<commit_before>// EventManager.h
#if !defined(_EVENTMANAGER_H)
#define _EVENTMANAGER_H

#include "CycException.h"

#include <list>
#include <string>
#include <map>
#include <boost/intrusive_ptr.hpp>
#include <boost/any.hpp>

#define EM EventManager::Instance()

class Event;
class EventManager;
class Model;

typedef boost::intrusive_ptr<Event> event_ptr;
typedef std::map<std::string, boost::any> ValMap;
typedef std::list<event_ptr> EventList;

/// default number of events to collect before flushing to backends.
static unsigned int const kDefaultDumpCount = 10000;

/*!
Indicates that a pre-recorded event of the same name (e.g. the same
table) has one or more inconsistent field-value type pairs.
*/
class CycInvalidSchemaErr: public CycException {
    public: CycInvalidSchemaErr(std::string msg) : CycException(msg) {};
};

/*!
An abstract base class for listeners (e.g. output databases) that want
to receive data generated by the simulation.
*/
class EventBackend {
  public:
    /// Used to pass a list of new/collected events
    virtual void notify(EventList events) = 0;

    /*!
    Used to uniquely identify a backend - particularly if there are more
    than one in a simulation.
    */
    virtual std::string name() = 0;

    /*!
    Used to notify the backend that no more events will be sent (i.e.
    the simulatoin is over).
    */
    virtual void close() = 0;
};

/*!
Collects and manages output data generation for the cyclus core and
agents during a simulation.

Example usage:

@code

EventManager* manager = new EventManager();
CustomBackend* myback = new CustomBackend();
manager->registerBackend(myback);
...
...
manager->newEvent(creator, "CapacityFactor");
       ->addVal("Name", aname)
       ->addVal("Capacity", cap)
       ->record();
...
...
manager->close();

@endcode
*/
class EventManager {
  friend class Event;

  private:
    bool isValidSchema(event_ptr ev);
    void notifyBackends();
    void addEvent(event_ptr ev);

    std::list<event_ptr> events_;
    std::map<std::string, event_ptr> schemas_;
    std::list<EventBackend*> backs_;
    unsigned int dump_count_;

    /// A pointer to singleton EventManager.
    static EventManager* instance_;

  public:

    /// create a new event manager with default dump countuency.
    EventManager();

    /// Return the # events buffered between flushes to backends.
    unsigned int dump_count();

    /*!
    set the EventManager to flush its collected events to registered backends every [count] events.<commit_msg>fixed doc comment typo and added not about singleton hate<commit_after>// EventManager.h
#if !defined(_EVENTMANAGER_H)
#define _EVENTMANAGER_H

#include "CycException.h"

#include <list>
#include <string>
#include <map>
#include <boost/intrusive_ptr.hpp>
#include <boost/any.hpp>

// TODO: Move away from singleton pattern (that is why we kept EventManager constructor public)
#define EM EventManager::Instance()

class Event;
class EventManager;
class Model;

typedef boost::intrusive_ptr<Event> event_ptr;
typedef std::map<std::string, boost::any> ValMap;
typedef std::list<event_ptr> EventList;

/// default number of events to collect before flushing to backends.
static unsigned int const kDefaultDumpCount = 10000;

/*!
Indicates that a pre-recorded event of the same name (e.g. the same
table) has one or more inconsistent field-value type pairs.
*/
class CycInvalidSchemaErr: public CycException {
    public: CycInvalidSchemaErr(std::string msg) : CycException(msg) {};
};

/*!
An abstract base class for listeners (e.g. output databases) that want
to receive data generated by the simulation.
*/
class EventBackend {
  public:
    /// Used to pass a list of new/collected events
    virtual void notify(EventList events) = 0;

    /*!
    Used to uniquely identify a backend - particularly if there are more
    than one in a simulation.
    */
    virtual std::string name() = 0;

    /*!
    Used to notify the backend that no more events will be sent (i.e.
    the simulatoin is over).
    */
    virtual void close() = 0;
};

/*!
Collects and manages output data generation for the cyclus core and
agents during a simulation.

Example usage:

@code

EventManager* manager = new EventManager();
CustomBackend* myback = new CustomBackend();
manager->registerBackend(myback);
...
...
manager->newEvent(creator, "CapacityFactor");
       ->addVal("Name", aname)
       ->addVal("Capacity", cap)
       ->record();
...
...
manager->close();

@endcode
*/
class EventManager {
  friend class Event;

  private:
    bool isValidSchema(event_ptr ev);
    void notifyBackends();
    void addEvent(event_ptr ev);

    std::list<event_ptr> events_;
    std::map<std::string, event_ptr> schemas_;
    std::list<EventBackend*> backs_;
    unsigned int dump_count_;

    /// A pointer to singleton EventManager.
    static EventManager* instance_;

  public:

    /// create a new event manager with default dump frequency.
    EventManager();
    // TODO: Move away from singleton pattern (that is why we kept the constructor public)

    /// Return the dump frequency, # events buffered between flushes to backends.
    unsigned int dump_count();

    /*!
    set the EventManager to flush its collected events to registered backends every [count] events.
{'fraction_non_alphanumeric': 0.10539308773262439, 'fraction_numerical': 0.0030383592859855677, 'mean_word_length': 3.745045045045045, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '340347', 'n_tokens_mistral': 1558, 'n_tokens_neox': 1506, 'n_words': 560}