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

Can we have multiple instances of the same Fsm? #3

Open
heLomaN opened this issue Oct 25, 2017 · 7 comments
Open

Can we have multiple instances of the same Fsm? #3

heLomaN opened this issue Oct 25, 2017 · 7 comments
Labels

Comments

@heLomaN
Copy link

heLomaN commented Oct 25, 2017

Since declare typedef F const * state_ptr_const_t; in class Fsm, we cannot get more than one instance for a specific Fsm. Is there any way to avoid this?

@digint
Copy link
Owner

digint commented Oct 25, 2017

As you state correctly, Fsm and states are all static instances of template types. This means that it's not possible to have more than one instance for as specific Fsm.

It might be possible with some template metaprogramming magic, and I remember doing some experiments with this, but it became pretty complicated, so I dropped it (as one main goal of tinyfsm is to keep it simple).

@digint
Copy link
Owner

digint commented Apr 27, 2018

Here's how you can have multiple state machines of the same type, declaring a template state machine: examples/api/multiple_switch.cpp.

@pgruenbacher
Copy link

I was going to use this library for doing fsm for like thousands of AI bots... this no longer seems viable if I there's not a way to instantiate a Fsm object for each bot. (Novice c++ learner so not positive if there's a workaround).

@pgruenbacher
Copy link

hm nvermind i'll just be using https://www.boost.org/doc/libs/1_64_0/libs/msm since it matches more closely what I was needing in terms of functionality.

@01e9
Copy link

01e9 commented Sep 28, 2018

Same problem. I wanted to use this library for a websocket server - websockets as state machines.
I came across Boost.SML.

@digint digint changed the title Can we have multi instance of the same Fsm? Can we have multiple instances of the same Fsm? Jul 4, 2022
@martinerk0
Copy link

@digint Can I ask why is it this way, instead of FSM being class that you can create multiple instances of?

@ekigwana
Copy link

Man this bit me this week. I need multiple instances of the same machine. There really needs to be an example of how to do that. Even for the basic case it took me a second to figure out that I have to use namespaces to avoid issues due to unreleated FSMs. Now I want n FSMs of type B and I just get crashes. Fun

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

6 participants