Main Page | File List | File Members

simple.cpp

Go to the documentation of this file.
00001 
00005 //
00006 // Date:      23 January  2003
00007 //            08 August   2005   Refine
00008 //
00009 // Copyright (c) Sergey Satskiy 2003 - 2005
00010 //               <sergesatsky@yahoo.com>
00011 //
00012 // Permission to copy, use, modify, sell and distribute this software 
00013 // is granted provided this copyright notice appears in all copies. 
00014 // This software is provided "as is" without express or implied
00015 // warranty, and with no claim as to its suitability for any purpose.
00016 //
00017 
00018 
00019 #include <iostream>
00020 #include <string>
00021 using namespace std;
00022 
00023 #include "fsm.h"
00024 using namespace FSM;
00025 
00026 
00028 enum  Events 
00029 { 
00030     letter = 0,         
00031     digit  = 1          
00032 };
00033 
00034 
00035 
00036 
00037 int main( int argc, char ** argv )
00038 {
00039 
00040         // Help defines of state and event types
00041 
00042     #define FSMStateType   string
00043     #define FSMEventType   Events
00044 
00045     SStateMachine< FSMStateType,
00046                    FSMEventType,
00047                    SEmptyFunctor< FSMStateType, FSMEventType >,
00048                    SThrowStrategy< FSMEventType >
00049                  >
00050     MyMachine(
00051 
00052         FSM_BEGIN( "empty" )
00053 
00054         FSM_STATES           "empty"      << "number"  << "identifier" << "unknown"
00055 
00056         FSM_EVENT(letter)    "identifier" << "unknown" << "identifier" << "unknown"
00057         FSM_EVENT(digit)     "number"     << "number"  << "identifier" << "unknown"
00058 
00059         FSM_END
00060 
00061              );
00062 
00063     #undef FSMStateType
00064     #undef FSMEventType
00065 
00066 
00067 
00068     cout << "StartState is: " << MyMachine << endl;
00069 
00070     MyMachine << digit << digit << letter;
00071     cout << "The 'unknown' state is expected. Current state is: " << MyMachine << endl;
00072 
00073 
00074         // Note: brackets are important below. They provide the right sequence 
00075         //       of operations
00076     cout << "Reset the machine. Current state is: " << (MyMachine << ResetMachine) << endl;
00077 
00078     MyMachine << letter << digit << letter;
00079     cout << "The 'identifier' state is expected. Current state is: " << MyMachine << endl;
00080 
00081     return 0;
00082 }
00083 

Generated on Fri Aug 12 06:13:17 2005 for Simple example of FSM template usage by  doxygen 1.4.4