Advertisement
Guest User

uMinded_FSM_1

a guest
Jul 22nd, 2011
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.36 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. struct StateImpl
  4. {
  5.   StateImpl(char const* n): name(n)
  6.     { printf("StateImpl(char const* %s) \n", name); }
  7.  
  8.   char const* name;
  9. };
  10.  
  11. struct Event
  12. {
  13.   Event(char const* e): name(e)
  14.     { printf("Event(char const* %s) \n", name); }
  15.  
  16.   char const* name;
  17. };
  18.  
  19. struct State;
  20. struct StateNode
  21. {
  22.   StateNode(Event e, State const& s, StateNode const* n):
  23.     event(e), destination(s), next(n)
  24.       {
  25.         printf(" StateNode(Event %s, State const& %s, StateNode const* %s) \n",e.name, 0, 0 );
  26.       }
  27.  
  28.   Event event;
  29.   State const& destination;
  30.   StateNode const* next;
  31. };
  32.  
  33. struct State
  34. {
  35.   State(char const* name):
  36.     me(0), impl(name)
  37.       { printf("StateNode const* = %s \n", me); }
  38.  
  39.   StateNode const* me;
  40.   StateImpl impl;
  41. };
  42.  
  43. struct Transition
  44. {
  45.   Transition(State& origin, Event e, State const& destination):
  46.     node(e, destination, origin.me)
  47.       { printf("Transition Impliments StateNode. See Above ^^ \n"); }
  48.  
  49.   StateNode node;
  50. };
  51.  
  52. int main ( void )
  53. {
  54.   printf("Make some States: \n");
  55.     State state1("S1"), state2("S2");
  56.   printf("\n");
  57.  
  58.   printf("Make some Events: \n");
  59.     Event KEY_UP("w");
  60.     Event KEY_DOWN("s");
  61.   printf("\n");
  62.  
  63.   printf("Make some Transitions: \n");
  64.     Transition t0(state1, KEY_UP, state2);
  65.     Transition t1(state2, KEY_DOWN, state1);
  66.   printf("\n");
  67.  
  68.   return(0);
  69. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement