Boost logo

Boost :

From: Alexander Nasonov (alnsn_at_[hidden])
Date: 2004-09-12 11:39:01


After playing with my overloads library and trying to apply it to FSM
I realized that some metaprogramming can be replaced with natural
overload resolution rules. After realizing it, I come to conclusion that
simple FSM can be implemented as a set of call operators and a list of
states. Each call operator represents a transition and follows this
pattern:
  NewState operator()(State,Event) const;

Transition functions are generated in process_event function on first
call (in a constructor of static variable, for example). Each function
extracts current state from StatesAsVariant (boost::variant of all
states):

template<class StatesAsVariant, class State, class Event>
void transition(FSM& fsm, StatesAsVariant states, Event event)
{
    states = fsm( get<State>(states), event); // select best transition
                                              // according to overload
                                              // resolution rules
    
}

The only metaprogramming algorithm is for_each<States> to initialize
transition table for the event.

Comments?

-- 
Alexander Nasonov

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk