-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added dont_instantiate_statemachine_class policy: when supplied, don'…
…t subclass the transition table type and require a reference to an instance of that type in the constructor of sml::sm and all sub-statemachine types
- Loading branch information
Showing
3 changed files
with
121 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// | ||
// Created by seb on 14.01.24. | ||
// | ||
|
||
#include <boost/sml.hpp> | ||
|
||
namespace sml = boost::sml; | ||
|
||
const auto idle = sml::state<class idle>; | ||
const auto idle2 = sml::state<class idle2>; | ||
const auto s1 = sml::state<class s1>; | ||
const auto s2 = sml::state<class s2>; | ||
|
||
test non_empty_statemachine_class_with_deleted_copy_constructor = []() { | ||
struct non_empty_statemachine_class { | ||
non_empty_statemachine_class() = default; | ||
non_empty_statemachine_class(const non_empty_statemachine_class &) = delete; | ||
|
||
auto operator()() { | ||
using namespace sml; | ||
return make_transition_table(*"start"_s + on_entry<_> / [this]() {}); | ||
} | ||
|
||
int some_variable_to_make_class_not_empty = 0; | ||
}; | ||
|
||
|
||
non_empty_statemachine_class instance; | ||
|
||
boost::sml::sm<non_empty_statemachine_class, sml::dont_instantiate_statemachine_class>{ | ||
instance | ||
}; | ||
}; | ||
|
||
test non_empty_statemachine_class_with_sub_statemachine = []() { | ||
struct sub { | ||
sub() = default; | ||
sub(const sub &) = delete; | ||
|
||
auto operator()() noexcept { | ||
using namespace sml; | ||
|
||
// clang-format off | ||
return make_transition_table( | ||
*"idle"_s + on_entry<_> / [this] { } | ||
); | ||
// clang-format on | ||
} | ||
|
||
int a_in_sub = 0; | ||
}; | ||
|
||
struct StateMachine { | ||
StateMachine() = default; | ||
StateMachine(const StateMachine &) = delete; | ||
|
||
auto operator()() { | ||
using namespace sml; | ||
return make_transition_table(*"start"_s = state<sub>); | ||
} | ||
|
||
int privateMemberVariable = 0; | ||
}; | ||
|
||
StateMachine stateMachineInstance; | ||
sub subInstance; | ||
|
||
sml::sm<StateMachine, sml::dont_instantiate_statemachine_class> sm{stateMachineInstance, subInstance}; | ||
}; |