Maki
Loading...
Searching...
No Matches
Event Type Sets

Definition

An event type set expresses a constraint that defines whether it contains any given event type.

Note
Here, the word "set" is used in its mathematical sense, not in its std::set sense.

An event type set can be "any event type", "no event type at all", or everything in between.

Maki exposes the maki::event_set class template to represent event type sets. Internally, it's nothing more than a predicate, i.e. a function taking a maki::event_t and returning a bool.

The most common way of instantiating a maki::event_set is by composing maki::event_t objects with boolean operators, such as:

struct on_button_press{};
struct off_button_press{};
constexpr auto power_button_press =
maki::event<on_button_press> ||
maki::event<off_button_press>
;

When to Use Event Type Sets

In Transition Tables

You can use event type sets in transition tables to factorize transitions:

constexpr auto transition_table = maki::transition_table{}
//source, target, event
(maki::init, off)
(off, running, maki::event<on_button_press>)
(running, sleeping, maki::event<inactivity>)
(sleeping, running, power_button_press) // <-- Here
(running, off, maki::event<off_button_press>)
;

As Filters for Actions and Hooks

You can use an event type set to define all the event types that can trigger an action:

constexpr auto busy = maki::state_builder{}
(
maki::event<beep_request> || maki::event<boop_request> || maki::event<bap_request>,
[]
{
std::cout << "Command unavailable\n";
}
)
;