this my prototype. Thanks for help
FSM in C++
// definition of user-defined action routine. Action routines are called by function Fsm::fire() with
// two pieces of information: (1) a reference to the machine and (2) the input that caused the
// transition.
typedef int Fsm_action(Fsm& f, unsigned inp);
An Fsm is constructed by giving (1) the total number of states N (2) an optional initial state (which defaults to 0) and (3) an optional programmer-defined default action routine (which defaults to the null action).
The resulting default machine has N states implicitly numbered 0,...,N-1 and occupies the specified initial state. For every (state, input) combination, the transitions of the default machine are defined as follows: first call the default action routine and then go to state 0. To redefine any one of these transitions, the client must specify a 4-tuple (start state, input, target state, action routine).
class Fsm{
public:
// Constructors, destructor
// n – number of states, init – initial state, act – default action
Fsm (unsigned n, unsigned init=0, Fsm_action* act=0);
~Fsm();
// Copy and assign
Fsm(const Fsm& f); // copy constructor
// Specify transitions
// Defines a single transition as follows: action(s1,inp) is set to act and
// target(s1,inp) is set to s2.
// Preconditions: s1 and s2 must be legal state numbers; inp must be a
// legal input;
// if act is a new action, then fewer than 256 unique action routines
// have already been specified.
void trans( unsigned s1, unsigned inp, unsigned s2, Fsm_action* act=0 );
// Examine the machine
unsigned nstates()const; // returns the number of states
unsigned nactions()const; // returns the number of actions
unsigned state()const; // returns the current state
unsigned initial_state()const; // returns the initial state
// Returns a pointer to the action routine associated with the transition from
// state state on input inp.
// Preconditions: state must be a legal state number;
// inp must be a legal input.
Fsm_action* action(unsigned state, unsigned inp) const;
// Returns the action number of the action routine associated with the
// transition from state state on input inp.
// Action numbers are assigned as follows: the default action defined by the
// constructor is assigned action number 0; each unique action routine
// subsequently encountered by the machine is assigned an action number
// one greater than the previously highest-assigned action number.
// Preconditions: state must be a legal state number;
// inp must be a legal input.
unsigned action_number(unsigned state, unsigned inp)const;
// Returns the target state associated with the transition from state state
// on input inp.
// Preconditions: state must be a legal state number;
// inp must be a legal input.
unsigned target(unsigned state, unsigned inp)const;
// Change the state of the machine
// Effects the transition associated with input inp in the current state.
// That is, calls action(state(), inp) and then goes to state
// target(state(),inp).
// If the action routine should invoke either fire(), reset(), go(), or abort(),
// the machine will not make a state change upon return from the action
// routine.
// The return value is the return value of the action routine, or zero if the
// null action was specified for this transition.
// Preconditions: inp must be a legal input.
int fire(unsigned inp);
// Forces the machine into state state.
// Preconditions: state must be a legal state number.
void go(unsigned state);
void reset(); //Forces the machine into state initial_state().
// Equivalent to go(state()). This function only has an effect when called
// from within an action routine, in which case it cancels any pending
// state change.
void abort();
};