EventLib.hpp

This file maintains information about events available in virtual hardware.

This file is largely based on InstLib.h.

template<typename HARDWARE_T>
class EventLib
#include <EventLib.hpp>

Public Types

using hardware_t = HARDWARE_T
using event_t = typename hardware_t::event_t
using fun_t = std::function<void(hardware_t&, const event_t&)>
using properties_t = std::unordered_set<std::string>
using fun_set_t = FunctionSet<void(hardware_t&, const event_t&)>

Public Functions

inline EventLib()
EventLib(const EventLib&) = default
inline ~EventLib()
EventLib &operator=(const EventLib&) = default
EventLib &operator=(EventLib&&) = default
inline const std::string &GetName(size_t id) const

Get the string name of the specified event definition.

inline const fun_t &GetHandler(size_t id) const

Get the handler function of the specified event definition.

inline const fun_set_t &GetDispatchFuns(size_t id) const

Get the dispatch function set of the specified event definition.

inline const std::string &GetDesc(size_t id) const

Get the string description of the specified event definition.

inline const properties_t &GetProperties(size_t id) const

Get a const reference to an event definition’s properties.

inline bool HasProperty(size_t id, std::string property) const

Does the event definition specified by id have the property specified.

inline size_t GetSize() const

Get the number of events registered to this event library.

inline size_t GetID(const std::string &name) const

Get the event ID of the event given by string name.

inline void AddEvent(const std::string &name, const fun_t &handler_fun, const std::string &desc = "", const properties_t &event_properties = properties_t())

Add a new event to the event library.

inline void RegisterDispatchFun(size_t id, fun_t dispatch_fun)

Register a dispatch function for the event specified by id.

inline void RegisterDispatchFun(const std::string &name, fun_t dispatch_fun)

Register a dispatch function for the event specified by name.

inline void TriggerEvent(hardware_t &hw, const event_t &event) const

Trigger event.

inline void HandleEvent(hardware_t &hw, const event_t &event) const

Handle event.

Protected Attributes

vector<EventDef> event_lib
std::map<std::string, size_t> name_map
struct EventDef
#include <EventLib.hpp>

Event definition structure. Maintains information about a type of event.

Public Functions

inline EventDef(const std::string &_n, fun_t _handler, const std::string &_d, const properties_t &_properties)
EventDef(const EventDef&) = default

Public Members

std::string name
fun_t handler
std::string desc
properties_t properties
fun_set_t dispatch_funs