Answer the question
In order to leave comments, you need to log in
state machine
Something I “stuck” thinking about a beautiful and elegant solution for working with a finite state machine (essentially no frills, because for MK :)
switch-case - understandable, but I want a more beautiful one :)
here - I’m thinking about something like this :
www.chipenable.ru/index.php/programming-c/90--state-machine.html
nightmares from templates:
www.rsdn.ru/article/alg/FiniteStateMachine.xml
www.rsdn.ru/article/alg/ Static_Finite_State_Machine.xml
any ideas? :)
Thanks!
Answer the question
In order to leave comments, you need to log in
These articles have all the ways that I saw on the pros (well, there are slightly more perversions with templates).
I think that for a small automaton (<5 states) there is nothing better than switch or goto, if more then I use State / Strategy.
Speaking of goto, there is another way, a hybrid one. Essentially goto + functions per action/event and jump between functions with setjmp/longjmp, but that's more for C than for C++.
Are you looking for something specific? :) It's just not entirely clear what has grown.
macros are often written for convenience.
for example, Alexey Pakhunov has an example on his blog from his colleague.
Just one step further from a simple switch-case in the direction of elegance, in my opinion, is the design of state transitions in the form of a table, like here: stackoverflow.com/a/1647679/1501359 .
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question