Added policy that controls if the transition table class is instantiated #608
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Problem:
A non-empty transition table class is always instantiated by boost::sml::sm.
This is because
sm_impl
is a subclass of the transition table class whenever the class is non-empty.When the transition table class has a non default constructor, it is required to supply a reference to an instance of this class in the constructor of
boost::sml::sm
.This leads to confusion, when a reference to the instance of a transition table is supplied as a constructor parameter, which is then modified after the creation of the state machine:
This prints:
It is not apparent that the assignment of
transition_table_class_instance.member_variable
does not change the internal state of the state machine, because the normal user does not know that the class is copied.Solution:
I added a new policy called
dont_instantiate_statemachine_class
(new policy to not break existing implementations).When applied, no transition table class from either the base or sub state machines are instantiated and
sm_impl
is not a subclass of the type (like in the current implementation when the transition table class is considered "empty").Instead, it is required to supply references to instances of these classes as a parameter to
boost::sml::sm
.Effects:
The following code is not able to compile:
This yields the following error message:
The previous code example :
Now prints:
This also enables the state machine to be used in a more object oriented use case like this:
This way, the subclass of the transition table
ClassWithStateMachine
can easily access and modify protected members of the state machine, that should not be accessible to others (information hiding).Issue: #607
Reviewers:
@