How can I access the payload from the control? #117
-
Hello, first of all, thank you very much for your time working on this awesome library. We have enjoyed using it so far. I'm trying to understand how to access a payload from the control, but I cannot figure it out. How can it be done? Thanks, and have a nice day, Alon |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
Hi, Currently, the way to access payloads is via transition history introspection: The API is optional, needs
This gives a custom (range for friendly) array of transitions. There's a usage example in test_internal_payloads.cpp |
Beta Was this translation helpful? Give feedback.
-
Now, I have to say, I would rather prefer something simpler, e.g.: The challenge comes from the fact that in a hierarchy, one transition request may activate multiple states, so matching a request to state type isn't trivial. |
Beta Was this translation helpful? Give feedback.
Hi,
Thank you, glad you like it!
Currently, the way to access payloads is via transition history introspection:
The API is optional, needs
#define HFSM2_ENABLE_TRANSITION_HISTORY
.const auto& pendingTransitions = control.pendingTransitions();
const auto& currentTransitions = control.currentTransitions();
This gives a custom (range for friendly) array of transitions.
The payload for each transition can be accessed via
const Payload* Transition::payload() const
method.There's a usage example in test_internal_payloads.cpp