Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions doc/modules/ROOT/pages/tutorial/backmp11-back-end.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ It offers a significant improvement in runtime and memory usage, as can be seen
| back | 14 | 815 | 68 | 2.8
| back_favor_compile_time | 17 | 775 | 226 | 3.5
| back11 | 37 | 2682 | 84 | 2.8
| backmp11 | 3 | 209 | 29 | 0.7
| backmp11_favor_compile_time | 3 | 193 | 43 | 6.0
| backmp11 | 3 | 209 | 28 | 0.7
| backmp11_favor_compile_time | 3 | 195 | 43 | 6.0
| sml | 5 | 234 | 57 | 0.3
|=======================================================================================================

Expand All @@ -28,9 +28,9 @@ It offers a significant improvement in runtime and memory usage, as can be seen
| | Compile time / sec | Compile RAM / MB | Binary size / kB | Runtime / sec
| back | 49 | 2165 | 230 | 13.2
| back_favor_compile_time | 55 | 1704 | 911 | > 300
| backmp11 | 8 | 351 | 85 | 3.3
| backmp11_favor_compile_time | 5 | 256 | 100 | 20.4
| backmp11_favor_compile_time_multi_cu | 5 | ~863 | 100 | 20.8
| backmp11 | 8 | 348 | 79 | 3.3
| backmp11_favor_compile_time | 5 | 261 | 97 | 20.6
| backmp11_favor_compile_time_multi_cu | 4 | ~863 | 97 | 21.4
| sml | 18 | 543 | 422 | 5.4
|================================================================================================================

Expand Down Expand Up @@ -170,6 +170,10 @@ If the type of the state appears multiple times in a hierarchical state machine,
// - if `start()` is called for a running state machine, the call is ignored
// - if `stop()` is called on a stopped (not running) state machine, the call is ignored

=== Support for simplified functor signatures

Further described in xref:./functor-front-end.adoc#simplified_functor_signatures[the functor front-end documentation].


=== Simplified state machine signature

Expand Down
89 changes: 85 additions & 4 deletions doc/modules/ROOT/pages/tutorial/functor-front-end.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ Row < Paused , stop , Stopped , stop_playback , none
Row < Paused , open_close , Open , stop_and_open , none >
// +---------+------------+-----------+---------------------------+----------------------------+
> {};

----

Transitions are now of type "Row" with exactly 5 template arguments:
Expand All @@ -66,12 +65,12 @@ detected event, the state machine, source and target state:
----
struct store_cd_info
{
template <class Fsm,class Evt,class SourceState,class TargetState>
void operator()(Evt const&, Fsm& fsm, SourceState&,TargetState& )
template <class Event, class Fsm, class SourceState, class TargetState>
void operator()(Event const&, Fsm& fsm, SourceState&, TargetState&)
{
cout << "player::store_cd_info" << endl;
fsm.process_event(play());
}
}
};
----

Expand Down Expand Up @@ -119,6 +118,88 @@ It even starts looking like functional programming. MSM ships with
functors for operators, state machine usage, STL algorithms or container
methods.


== Using lambdas as functors ({cpp}20)

If {cpp}20 is available you can shorten the functor syntax by using lambdas as functors.
The `store_cd_info` functor can be rewritten with a lambda as follows:

[source,cpp]
----
using store_cd_info = msm::front::Lambda<
[](auto const& /*event*/, auto& fsm, auto& /*source*/, auto& /*target*/)
{
cout << "player::store_cd_info" << endl;
fsm.process_event(play());
}>;
----

[[simplified_functor_signatures]]
== Simplified functor signatures (`backmp11` only)

The `backmp11` back-end allows you to use shorter functor signatures, reducing the boilerplate of action and guard functor definitions. It automatically detects how many parameters your functors have and invokes them with the appropriate arguments.

The following three signatures are supported:

**Full signature**

[source,cpp]
----
struct store_cd_info
{
template <class Event, class Fsm, class SourceState, class TargetState>
void operator()(Event const&, Fsm& fsm, SourceState&, TargetState&)
{
cout << "player::store_cd_info" << endl;
fsm.process_event(play());
}
};
----

**Event and FSM only**

[source,cpp]
----
struct store_cd_info
{
template <class Event, class Fsm>
void operator()(Event const&, Fsm& fsm)
{
cout << "player::store_cd_info" << endl;
fsm.process_event(play());
}
};
----

**FSM only**

[source,cpp]
----
struct store_cd_info
{
template <class Fsm>
void operator()(Fsm& fsm)
{
cout << "player::store_cd_info" << endl;
fsm.process_event(play());
}
};
----

Simplified signatures are also supported with lambdas, providing a way to define
functors with minimal boilerplate:

[source,cpp]
----
using store_cd_info = msm::front::Lambda<
[](auto& fsm)
{
cout << "player::store_cd_info" << endl;
fsm.process_event(play());
}>;
----


[[defining-states-with-entryexit-actions]]

== Defining states with entry/exit actions
Expand Down
21 changes: 13 additions & 8 deletions doc/modules/ROOT/pages/version-history.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,19 @@

== Boost 1.91

* feat(backmp11): Further optimized compilation, with up to 25% faster compile times and less RAM consumption than the 1.90 version
* fix(backmp11): Incorrect FSM type in call on_entry() & on_exit() (https://github.com/boostorg/msm/issues/167[#167])
* feat(backmp11): Merge queued & deferred events into a single event pool (https://github.com/boostorg/msm/issues/168[#168])
* feat(backmp11): Support conditional deferral with the `deferred_events` property (https://github.com/boostorg/msm/issues/155[#155])
* fix(backmp11): Completion events fire too often (https://github.com/boostorg/msm/issues/166[#166])
* feat(backmp11): Small Object Optimization for events in the event pool (https://github.com/boostorg/msm/issues/172[#172])
* feat(backmp11): Improve support for the `deferred_events` property in hierarchical state machines (https://github.com/boostorg/msm/issues/173[#173])
* feat(backmp11): Improve runtime performance with a `flat_fold` dispatch strategy (https://github.com/boostorg/msm/issues/180[#180])
* New features (`backmp11`):
** Improve support for the `deferred_events` property in hierarchical state machines (https://github.com/boostorg/msm/issues/173[#173])
** Support conditional deferral with the `deferred_events` property (https://github.com/boostorg/msm/issues/155[#155])
** Simplified functor signatures (https://github.com/boostorg/msm/issues/175[#175])
** Merge queued and deferred events into a single event pool (https://github.com/boostorg/msm/issues/168[#168])
** Small object optimization for events in the event pool (https://github.com/boostorg/msm/issues/172[#172])
** Improve runtime performance with a `flat_fold` dispatch strategy (https://github.com/boostorg/msm/issues/180[#180])
** Further optimize compilation, with up to 25% faster compile times and lower RAM consumption compared to version 1.90
* Bug fixes (`backmp11`):
** Incorrect `FSM` type in calls to `on_entry(...)` and `on_exit(...)` (https://github.com/boostorg/msm/issues/167[#167])
** Completion events fire too often (https://github.com/boostorg/msm/issues/166[#166])
* **Breaking change (`backmp11`)**: Direct access to the event pool is changed from `public` to `protected`,
because manipulating it outside of the library code can lead to undefined behavior.

== Boost 1.90

Expand Down
17 changes: 7 additions & 10 deletions include/boost/msm/backmp11/common_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)

#ifndef BOOST_MSM_BACKMP11_COMMON_TYPES_H
#define BOOST_MSM_BACKMP11_COMMON_TYPES_H
#ifndef BOOST_MSM_BACKMP11_COMMON_TYPES_HPP
#define BOOST_MSM_BACKMP11_COMMON_TYPES_HPP

#include <any>
#include <cstdint>
#include <optional>

Expand Down Expand Up @@ -61,8 +60,6 @@ namespace boost::msm::backmp11

using process_result = back::HandledEnum;

using any_event = std::any;

// flag handling
struct flag_or {};
struct flag_and {};
Expand Down Expand Up @@ -111,11 +108,11 @@ static constexpr process_result handled_true_or_deferred =
// Event occurrences are placed in an event pool for later processing.
class event_occurrence
{
using process_fnc_t = std::optional<process_result> (*)(
using process_fn_t = std::optional<process_result> (*)(
event_occurrence&, void* /*sm*/, uint16_t /*seq_cnt*/);

public:
event_occurrence(process_fnc_t process_fnc) : m_process_fnc(process_fnc)
event_occurrence(process_fn_t process_fn) : m_process_fn(process_fn)
{
}

Expand All @@ -125,7 +122,7 @@ class event_occurrence
template <typename StateMachine>
std::optional<process_result> try_process(StateMachine& sm, uint16_t seq_cnt)
{
return m_process_fnc(*this, static_cast<void*>(&sm), seq_cnt);
return m_process_fn(*this, static_cast<void*>(&sm), seq_cnt);
}

void mark_for_deletion()
Expand All @@ -139,7 +136,7 @@ class event_occurrence
}

private:
process_fnc_t m_process_fnc{};
process_fn_t m_process_fn{};
// Flag set when this event has been processed and can be erased.
// Deletion is deferred to allow the use of std::deque,
// which provides better cache locality and lower per-element overhead.
Expand Down Expand Up @@ -188,4 +185,4 @@ struct compile_policy_impl;
} // namespace detail
} // namespace boost::msm::backmp11

#endif // BOOST_MSM_BACKMP11_COMMON_TYPES_H
#endif // BOOST_MSM_BACKMP11_COMMON_TYPES_HPP
Loading
Loading