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

Using event instance with process_event() #487

Open
ladislas opened this issue Jan 25, 2022 · 2 comments
Open

Using event instance with process_event() #487

ladislas opened this issue Jan 25, 2022 · 2 comments

Comments

@ladislas
Copy link

ladislas commented Jan 25, 2022

Expected Behavior

As described in the tutorial section, I'm using event instances to simplify the transition table.

struct start { ... };
auto e_start = sml::event<start>;

struct game_over { ... };
auto e_game_over = sml::event<game_over>;

class StateMachine {
public:
  auto operator()() {
    using namespace sml;
    return make_transition_table(
     *"src_state"_s + e_start = "dst_state"_s,
      "dst_state"_s + e_game_over = X
    );
  }
};

Now, when I try to call sm.process_event() with the instance, it does not work:

sm.process_event(e_start); // not working
sm.process_event(e_start()); // working but is ugly and people will forget to add the ()
sm.process_event(start {}); // working

Actual Behavior

Just calling process_event() with the instance doesn't do anything.

Steps to Reproduce the Problem

n/a

Specifications

  • Version: latest
  • Platform: macOS
  • Subsystem: n/a
@Rijom
Copy link
Contributor

Rijom commented Mar 11, 2022

I always use sm.process_event(start {}); // working.
You create an instance of the event and pass it on to the state machine. To me this seems like the most natural way to do it. Even more so, once you start adding a payload to an event.

I guess one could implement your wish by adding a special overload of process_event that calls operator() on the front::event<T>. But I think this would only increase complexity for the user.

@cppden
Copy link

cppden commented May 22, 2022

sml::event is the marker for the library to distinguish events from states/actions, i.e. it's meant to be used for FSM definition.

once FSM defined you should just use your raw events w/o sml's markers. this is similar case as with a definition of template and its actual use, i.e. you don't write template SOME<int> when you need to instantiate it for particular type.

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

No branches or pull requests

3 participants