2 // FiniteStateMachine.h
5 // Created by clement choquereau on 5/4/11.
6 // Copyright 2011 Parrot. All rights reserved.
9 #import <Foundation/Foundation.h>
15 @interface FiniteStateMachine : NSObject <NSXMLParserDelegate>
19 unsigned int statesCount;
20 unsigned int actionsCount;
21 unsigned int currentState;
23 NSMutableDictionary *objects;
24 NSMutableDictionary *enterCallbacks;
25 NSMutableDictionary *quitCallbacks;
26 NSMutableDictionary *stateActions;
28 // should always be nil:
32 @property (nonatomic, retain) id delegate;
33 @property (readonly) id currentObject;
35 @property (readonly) unsigned int statesCount;
36 @property (readonly) unsigned int actionsCount;
37 @property unsigned int currentState;
40 * You can create a FSM with a XML file:
41 * (For element 'state', attributes 'enter-callback', 'quit-callback' and 'object' aren't mandatory.)
43 * <?xml version="1.0"?>
46 * <state name="myState" enter-callback="onEnterState:" quit-callback="onQuitState:" object="aStringObject" />
50 * <action name="myAction" />
54 * <association from-state="aState" action="anAction" to-state="anotherState" />
59 + (id) fsmWithXML:(NSString *)fileName;
62 - (unsigned int) createState;
63 - (void) createStates:(unsigned int)count inArray:(unsigned int *)states;
64 - (void) setObject:(id)object forState:(unsigned int)state;
65 - (void) setEnterStateCallback:(SEL)enter forState:(unsigned int)state;
66 - (void) setQuitStateCallback:(SEL)quit forState:(unsigned int)state;
68 - (unsigned int) createStateWithObject:(id)object andEnterStateCallback:(SEL)enter andQuitStateCallback:(SEL)quit;
69 - (void) createStates:(unsigned int)count withObjects:(id *)items andEnterStateCallbacks:(SEL *)enters andQuitStateCallbacks:(SEL *)quits inArray:(unsigned int *)states;
72 - (unsigned int) createAction;
73 - (void) createActions:(unsigned int)count inArray:(unsigned int *)actions;
76 - (void) createAssociationFromState:(unsigned int)start withAction:(unsigned int)action toState:(unsigned int)end;
77 - (void) createAssociationFromState:(unsigned int)start withActions:(unsigned int *)actions toStates:(unsigned int *)ends andNumAssociations:(unsigned int)count;
78 - (void) doAction:(unsigned int)action;