00001 00002 00003 #ifndef FSAHELPER_H 00004 #define FSAHELPER_H 00005 00006 #include "IS3DCommon.H" 00007 #include "Event.H" 00008 00009 namespace IS3D { 00010 00012 typedef ReferenceCountedPointer<class FsaArc> FsaArcRef; 00013 class FsaArc : public ReferenceCountedObject 00014 { 00015 public: 00016 FsaArc(const std::string &arcName, 00017 const int &toState, 00018 const Array<std::string> &triggerEvents); 00019 FsaArc(); 00020 virtual ~FsaArc(); 00021 00022 void addCallback(EventCallbackFunctor *f); 00023 void callCallbacks(EventRef event); 00024 00025 std::string getName() const { return _name; } 00026 int getTo() const { return _to; } 00027 int getNumTriggers() const { return _triggers.size(); } 00028 std::string getTrigger(int i) const { return _triggers[i]; } 00029 00030 protected: 00031 Array<EventCallbackFunctor*> _callbacks; 00032 Array<std::string> _triggers; 00033 std::string _name; 00034 int _to; 00035 }; 00036 00037 00039 class FsaState 00040 { 00041 public: 00042 FsaState(const std::string &stateName); 00043 FsaState(); 00044 virtual ~FsaState(); 00045 00046 void addArcRef(FsaArcRef a); 00047 00048 void addEnterCallback(EventCallbackFunctor *f); 00049 void addExitCallback(EventCallbackFunctor *f); 00050 00051 void callEnterCallbacks(); 00052 void callExitCallbacks(); 00053 00054 FsaArcRef getArcRef(int i) { return _arcs[i]; } 00055 int getNumArcs() const { return _arcs.size(); } 00056 std::string getName() const { return _name; } 00057 00058 protected: 00059 std::string _name; 00060 Array<FsaArcRef> _arcs; 00061 Array<EventCallbackFunctor*> _enterCallbacks; 00062 Array<EventCallbackFunctor*> _exitCallbacks; 00063 }; 00064 00065 00066 } // end namespace 00067 00068 #endif 00069