Maki
Loading...
Searching...
No Matches
maki::machine_conf< Impl > Class Template Reference

maki::machine configuration More...

#include <maki/machine_conf.hpp>

Public Types

using context_type = typename Impl::context_type
 

Public Member Functions

 machine_conf (const machine_conf &)=delete
 
 machine_conf (machine_conf &&)=delete
 
constexpr machine_conf< IMPLEMENTATION_DETAIL > auto_start (const bool value) const
 Specifies whether the constructor of maki::machine must call maki::machine::start().
 
template<class Callable>
constexpr machine_conf< IMPLEMENTATION_DETAIL > catch_mx (const Callable &callable) const
 Sets up a try/catch(...) block at the top-level of every non-const member function of maki::machine and invokes callable from the catch block.
 
template<class Context>
constexpr machine_conf< IMPLEMENTATION_DETAIL > context_a () const
 Sets the type of the context (see signatures).
 
template<class Context>
constexpr machine_conf< IMPLEMENTATION_DETAIL > context_am () const
 Sets the type of the context (see signatures).
 
machine_confoperator= (const machine_conf &)=delete
 
machine_confoperator= (machine_conf &&)=delete
 
template<class Hook>
constexpr machine_conf< IMPLEMENTATION_DETAIL > post_external_transition_hook_crset (const Hook &hook) const
 Specifies a hook to be called after any external transition.
 
template<class Event, class Action>
constexpr machine_conf< IMPLEMENTATION_DETAIL > post_processing_hook_mep (const Action &action) const
 Adds a hook to be called whenever maki::machine is done processing an event of type Event.
 
template<class EventSetPredicate, class Action>
constexpr machine_conf< IMPLEMENTATION_DETAIL > post_processing_hook_mep (const event_set< EventSetPredicate > &evt_set, const Action &action) const
 Adds a hook to be called whenever maki::machine is done processing an event whose type is part of evt_set.
 
template<class Hook>
constexpr machine_conf< IMPLEMENTATION_DETAIL > pre_external_transition_hook_crset (const Hook &hook) const
 Specifies a hook to be called before any external transition.
 
template<class Event, class Action>
constexpr machine_conf< IMPLEMENTATION_DETAIL > pre_processing_hook_c (const Action &action) const
 Adds a hook (see signatures) to be called whenever maki::machine is about to process an event of type Event.
 
template<class EventSetPredicate, class Action>
constexpr machine_conf< IMPLEMENTATION_DETAIL > pre_processing_hook_c (const event_set< EventSetPredicate > &evt_set, const Action &action) const
 Adds a hook (see signatures) to be called whenever maki::machine is about to process an event whose type is part of evt_set.
 
template<class Event, class Action>
constexpr machine_conf< IMPLEMENTATION_DETAIL > pre_processing_hook_ce (const Action &action) const
 Adds a hook (see signatures) to be called whenever maki::machine is about to process an event of type Event.
 
template<class EventSetPredicate, class Action>
constexpr machine_conf< IMPLEMENTATION_DETAIL > pre_processing_hook_ce (const event_set< EventSetPredicate > &evt_set, const Action &action) const
 Adds a hook (see signatures) to be called whenever maki::machine is about to process an event whose type is part of evt_set.
 
template<class Event, class Action>
constexpr machine_conf< IMPLEMENTATION_DETAIL > pre_processing_hook_cm (const Action &action) const
 Adds a hook (see signatures) to be called whenever maki::machine is about to process an event of type Event.
 
template<class EventSetPredicate, class Action>
constexpr machine_conf< IMPLEMENTATION_DETAIL > pre_processing_hook_cm (const event_set< EventSetPredicate > &evt_set, const Action &action) const
 Adds a hook (see signatures) to be called whenever maki::machine is about to process an event whose type is part of evt_set.
 
template<class Event, class Action>
constexpr machine_conf< IMPLEMENTATION_DETAIL > pre_processing_hook_cme (const Action &action) const
 Adds a hook (see signatures) to be called whenever maki::machine is about to process an event of type Event.
 
template<class EventSetPredicate, class Action>
constexpr machine_conf< IMPLEMENTATION_DETAIL > pre_processing_hook_cme (const event_set< EventSetPredicate > &evt_set, const Action &action) const
 Adds a hook (see signatures) to be called whenever maki::machine is about to process an event whose type is part of evt_set.
 
template<class Event, class Action>
constexpr machine_conf< IMPLEMENTATION_DETAIL > pre_processing_hook_e (const Action &action) const
 Adds a hook (see signatures) to be called whenever maki::machine is about to process an event of type Event.
 
template<class EventSetPredicate, class Action>
constexpr machine_conf< IMPLEMENTATION_DETAIL > pre_processing_hook_e (const event_set< EventSetPredicate > &evt_set, const Action &action) const
 Adds a hook (see signatures) to be called whenever maki::machine is about to process an event whose type is part of evt_set.
 
template<class Event, class Action>
constexpr machine_conf< IMPLEMENTATION_DETAIL > pre_processing_hook_m (const Action &action) const
 Adds a hook (see signatures) to be called whenever maki::machine is about to process an event of type Event.
 
template<class EventSetPredicate, class Action>
constexpr machine_conf< IMPLEMENTATION_DETAIL > pre_processing_hook_m (const event_set< EventSetPredicate > &evt_set, const Action &action) const
 Adds a hook (see signatures) to be called whenever maki::machine is about to process an event whose type is part of evt_set.
 
template<class Event, class Action>
constexpr machine_conf< IMPLEMENTATION_DETAIL > pre_processing_hook_me (const Action &action) const
 Adds a hook (see signatures) to be called whenever maki::machine is about to process an event of type Event.
 
template<class EventSetPredicate, class Action>
constexpr machine_conf< IMPLEMENTATION_DETAIL > pre_processing_hook_me (const event_set< EventSetPredicate > &evt_set, const Action &action) const
 Adds a hook (see signatures) to be called whenever maki::machine is about to process an event whose type is part of evt_set.
 
template<class Event, class Action>
constexpr machine_conf< IMPLEMENTATION_DETAIL > pre_processing_hook_v (const Action &action) const
 Adds a hook (see signatures) to be called whenever maki::machine is about to process an event of type Event.
 
template<class EventSetPredicate, class Action>
constexpr machine_conf< IMPLEMENTATION_DETAIL > pre_processing_hook_v (const event_set< EventSetPredicate > &evt_set, const Action &action) const
 Adds a hook (see signatures) to be called whenever maki::machine is about to process an event whose type is part of evt_set.
 
constexpr machine_conf< IMPLEMENTATION_DETAIL > process_event_now_enabled (const bool value) const
 Specifies whether the unsafe function maki::machine::process_event_now() can be called.
 
constexpr machine_conf< IMPLEMENTATION_DETAIL > run_to_completion (const bool value) const
 Specifies whether run-to-completion is enabled.
 
constexpr machine_conf< IMPLEMENTATION_DETAIL > small_event_max_align (const std::size_t value) const
 Specifies the maximum object alignment requirement for the run-to-completion event queue to enable small object optimization (and thus avoid an extra memory allocation).
 
constexpr machine_conf< IMPLEMENTATION_DETAIL > small_event_max_size (const std::size_t value) const
 Specifies the maximum object size for the run-to-completion event queue to enable small object optimization (and thus avoid an extra memory allocation).
 
constexpr machine_conf< IMPLEMENTATION_DETAIL > thread_safe (const bool) const
 Currently doesn't do anything. Once thread safety is implemented, will specify whether thread safety is enabled.
 
template<class... TransitionTables>
constexpr machine_conf< IMPLEMENTATION_DETAIL > transition_tables (const TransitionTables &... tables) const
 Specifies the list of transition tables. One region per transition table is created.
 

Detailed Description

template<class Impl>
class maki::machine_conf< Impl >

maki::machine configuration

Template Parameters
Implimplementation detail

Member Function Documentation

◆ catch_mx()

template<class Impl>
template<class Callable>
machine_conf< IMPLEMENTATION_DETAIL > maki::machine_conf< Impl >::catch_mx ( const Callable & callable) const
nodiscardconstexpr

Sets up a try/catch(...) block at the top-level of every non-const member function of maki::machine and invokes callable from the catch block.

As the suffix of the function suggests, callable must take references to:

  • the machine;
  • the exception pointer.

Example:

.catch_mx([](auto& mach, const std::exception_ptr& eptr)
{
//...
})

If this action isn't set, maki::machine doesn't catch any exception.

◆ post_external_transition_hook_crset()

template<class Impl>
template<class Hook>
machine_conf< IMPLEMENTATION_DETAIL > maki::machine_conf< Impl >::post_external_transition_hook_crset ( const Hook & hook) const
nodiscardconstexpr

Specifies a hook to be called after any external transition.

Hook must have the following form:

template
<
class RegionImpl,
class SourceStateImpl,
class Event,
class TargetStateImpl
>
void hook
(
context& ctx,
const maki::region<RegionImpl>& region,
const maki::state<SourceStateImpl>& source_state,
const Event& event,
const maki::state<TargetStateImpl>& target_state
);

This hook can be useful for logging external transitions, for example:

.post_external_transition_hook_crset
(
[](context& /*ctx*/, const auto& region, const auto& source_state, const auto& /*event*/, const auto& target_state)
{
std::cout
<< "End of transition in FSM/"
<< region.path().to_string()
<< ": "
<< source_state.pretty_name()
<< " -> "
<< target_state.pretty_name()
<< "\n";
}
)

◆ post_processing_hook_mep() [1/2]

template<class Impl>
template<class Event, class Action>
machine_conf< IMPLEMENTATION_DETAIL > maki::machine_conf< Impl >::post_processing_hook_mep ( const Action & action) const
nodiscardconstexpr

Adds a hook to be called whenever maki::machine is done processing an event of type Event.

Hook must have the following form:

template<class Machine, class Event>
void hook(Machine& mach, const Event& event, bool processed);

The processed parameter indicates whether a state transition or any kind of action invocation (note: a hook isn't an action) occurred during the processing of the event.

Users typically add a hook for every event of interest.

Example:

constexpr auto conf = maki::machine_conf{}
//...
.post_processing_hook_mep<some_event_type>([](auto& mach, const some_event_type& event, const bool processed)
{
//...
})
.post_processing_hook_mep<some_other_event_type>([](auto& mach, const some_other_event_type& event, const bool processed)
{
//...
})
;
maki::machine configuration
Definition machine_conf.hpp:42
constexpr machine_conf< IMPLEMENTATION_DETAIL > post_processing_hook_mep(const event_set< EventSetPredicate > &evt_set, const Action &action) const
Adds a hook to be called whenever maki::machine is done processing an event whose type is part of evt...
Definition machine_conf.hpp:272

◆ post_processing_hook_mep() [2/2]

template<class Impl>
template<class EventSetPredicate, class Action>
machine_conf< IMPLEMENTATION_DETAIL > maki::machine_conf< Impl >::post_processing_hook_mep ( const event_set< EventSetPredicate > & evt_set,
const Action & action ) const
nodiscardconstexpr

Adds a hook to be called whenever maki::machine is done processing an event whose type is part of evt_set.

Hook must have the following form:

template<class Machine, class Event>
void hook(Machine& mach, const Event& event, bool processed);

The processed parameter indicates whether a state transition or any kind of action invocation (note: a hook isn't an action) occurred during the processing of the event.

Users typically add a hook for every event of interest.

Example:

constexpr auto conf = maki::machine_conf{}
//...
.post_processing_hook_mep<some_event_type>([](auto& mach, const some_event_type& event, const bool processed)
{
//...
})
.post_processing_hook_mep<some_other_event_type>([](auto& mach, const some_other_event_type& event, const bool processed)
{
//...
})
;

◆ pre_external_transition_hook_crset()

template<class Impl>
template<class Hook>
machine_conf< IMPLEMENTATION_DETAIL > maki::machine_conf< Impl >::pre_external_transition_hook_crset ( const Hook & hook) const
nodiscardconstexpr

Specifies a hook to be called before any external transition.

Hook must have the following form:

template
<
class RegionImpl,
class SourceStateImpl,
class Event,
class TargetStateImpl
>
void hook
(
context& ctx,
const maki::region<RegionImpl>& region,
const maki::state<SourceStateImpl>& source_state,
const Event& event,
const maki::state<TargetStateImpl>& target_state
);

This hook can be useful for logging external transitions, for example:

.pre_external_transition_hook_crset
(
[](context& /*ctx*/, const auto& region, const auto& source_state, const auto& /*event*/, const auto& target_state)
{
std::cout
<< "Beginning of transition in FSM/"
<< region.path().to_string()
<< ": "
<< source_state.pretty_name()
<< " -> "
<< target_state.pretty_name()
<< "\n";
}
)

◆ run_to_completion()

template<class Impl>
machine_conf< IMPLEMENTATION_DETAIL > maki::machine_conf< Impl >::run_to_completion ( const bool value) const
nodiscardconstexpr

Specifies whether run-to-completion is enabled.

Disabling run-to-completion makes the state machine much faster, but you have to make sure you never call maki::machine::process_event() recursively.

Disable it at your own risk!

◆ thread_safe()

template<class Impl>
machine_conf< IMPLEMENTATION_DETAIL > maki::machine_conf< Impl >::thread_safe ( const bool ) const
nodiscardconstexpr

Currently doesn't do anything. Once thread safety is implemented, will specify whether thread safety is enabled.

Being a safety option, it will be enabled by default.