Реферат: Эффективное использование STL и шаблонов
enum Events { letter = 0, digit = 1 };
int main( int argc, char ** argv )
{
#define FSMStateType string
#define FSMEventType Events
SFiniteStateMachine< StateType,
EventType,
SEmptyFunctor<StateType,EventType>,
SThrowStrategy<EventType>
>
MyMachine(
FSMBEGIN( "empty" )
FSMSTATES "empty" << "number" << "identifier" << "unknown"
FSMEVENT(letter) "identifier" << "unknown" << "identifier" << "unknown"
FSMEVENT(digit) "number" << "number" << "identifier" << "unknown"
FSMEND
);
#undef FSMStateType
#undef FSMEventType
cout << "StartState is: " << MyMachine << endl;
MyMachine << digit << digit << letter;
cout << "The 'unknown' state is expected. Current state is: " << MyMachine << endl;
// Внимание: круглые скобки в следующей строке обязательны. Они обеспечат
// правильный порядок выполнения операторов
cout << "Reset the machine. Current state is: " << (MyMachine << ResetMachine) << endl;
MyMachine << letter << digit << letter;
cout << "The 'identifier' state is expected. Current state is: " << MyMachine << endl;
return 0;
}