state machine

anyone know how to setup state machine in class
One member contains the state, which is often an enum. The state machine is a method with a switch statement that switches on the current state:
1
2
3
4
5
6
7
8
9
10
11
switch(state) {
case State_One:
    // do some stuff
    // update state
    break;
case State_Two:
    // do some other stuff
    // uddate state
   break;
....
}


Argh. Use a matrix or a std::multimap. The key is the current state. The value should be a struct/class that stores the condition to traverse said edge and the new state key if said edge is traversed.

Play around with the std::multimap and you won't be disappointed.
Topic archived. No new replies allowed.