If I make a state machine and want to use an interface like this:
AddState ( state1, state2, Key_UP );
AddEvent ( Key_UP );
AddEventFunction ( Key_UP, &UP_Function);
AddStateFunction ( state1, &State1_In_Function, &State1_Out_Function);
AddStateFunction ( state2, &State2_In_Function, &State2_Out_Function);
State1_In_Function ( void ) { printf ( "In #1 \n" ); }
State1_Out_Function ( void ) { printf ( "Out #1 \n" ); }
State2_In_Function ( void ) { printf ( "In #2 \n" ); }
State2_Out_Function ( void ) { printf ( "Out #2 \n" ); }
UP_Function ( void ) { printf ( "Goin UP \n" ); }
That way when I am in state1 and the FSM receives Key_UP the program prints:
Out #1
Goin UP
In #2
The question is how to store the state and transitional information inside the class without the programmer being required to change an array size. I was thinking I could use a 2D array and make it a state table like usual and to make it more portable I would just handle the addition of events and states by using the vector type to resize as needed. The problem with vectors is that not many embedded devices can use the memory allocation calls. My second option is to call a constructor with the state machine and pass it the size the table would require to be but then if I add any new states or events I need to change these values as well...
So how should I store my states, events and function pointers?!