Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to query the current state of the State Machine? #19

Open
Ricodan opened this issue May 24, 2019 · 4 comments
Open

Is it possible to query the current state of the State Machine? #19

Ricodan opened this issue May 24, 2019 · 4 comments
Labels

Comments

@Ricodan
Copy link

Ricodan commented May 24, 2019

I'm, not too savvy with C++ templates and would like some help with this topic.
I would like to print a stribg for example with the state of my SM.

@digint
Copy link
Owner

digint commented May 25, 2019

You can print the address of the current state:

std::cout << MyFsm::current_state_ptr << std::endl;

The address of the states can be printed like this:

std::cout << &MyFsm::state<StateA>() << std::endl;
std::cout << &MyFsm::state<StateB>() << std::endl;
[...]

@einoj
Copy link

einoj commented Jun 26, 2020

How would you print the addresses of the states if they are classes instead, like in the elevator example?

@einoj
Copy link

einoj commented Jul 10, 2020

I figured out how to do it, at least for the first class in fsm_list. If you move the state class declaration to the header file you can do it like this:

  std::cout << fsm_list::fsmtype::current_state_ptr << std::endl;
  std::cout << &fsm_list::fsmtype::state<Up>() << std::endl;

@lFatality
Copy link

You can also check if the state machine is in a certain state using the is_in_state function:

bool in_state_a = MyFsm::is_in_state<StateA>();
bool in_state_b = MyFsm::is_in_state<StateB>();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants