Homepage | Demos | Overview | Downloads | Tutorials | Reference | Credits |
CompletionTrans.hGo to the documentation of this file.00001 //-*-c++-*- 00002 #ifndef INCLUDED_CompletionTrans_h_ 00003 #define INCLUDED_CompletionTrans_h_ 00004 00005 #include "Behaviors/StateNode.h" 00006 #include "Behaviors/Transition.h" 00007 #include "Events/EventRouter.h" 00008 00009 //! causes a transition when at least @e n sources have signalled completion; @e n = 0 means "all" (default) 00010 class CompletionTrans : public Transition { 00011 protected: 00012 int minsrcs; 00013 bool *completions; //!< pointer to array for recording completion events for all sources 00014 00015 public: 00016 CompletionTrans(StateNode* destination, int n=0) : 00017 Transition(destination), minsrcs(n), completions(NULL) {}; 00018 00019 //! starts listening 00020 virtual void DoStart() { 00021 Transition::DoStart(); 00022 unsigned int const numsrcs = getSources().size(); 00023 completions = new bool[numsrcs]; 00024 for (unsigned int i = 0; i < numsrcs; i++) { 00025 completions[i] = false; 00026 erouter->addListener(this, 00027 EventBase::stateMachineEGID, 00028 (unsigned int)getSources()[i], 00029 EventBase::statusETID); 00030 }; 00031 } 00032 00033 //! stops listening 00034 virtual void DoStop() { 00035 erouter->removeListener(this); 00036 delete completions; 00037 completions = NULL; 00038 Transition::DoStop(); 00039 } 00040 00041 //! record completions, and fire the transition if all sources have completed 00042 virtual void processEvent(const EventBase &event) { 00043 int numcomplete = 0; 00044 for ( unsigned int i=0; i<getSources().size(); i++ ) { 00045 if ( event.getSourceID() == (unsigned int)getSources()[i] ) 00046 completions[i] = true; 00047 if ( completions[i] ) ++numcomplete; 00048 }; 00049 int const threshold = (minsrcs > 0 ? minsrcs : (int)getSources().size()); 00050 if (numcomplete >= threshold) fire(); 00051 } 00052 00053 virtual std::string getName() const { return "CompletionTrans"; } 00054 00055 protected: 00056 //!@name Dummy functions to satisfy the compiler 00057 CompletionTrans(const CompletionTrans&); //!< don't call this 00058 CompletionTrans& operator=(const CompletionTrans&); //!< don't call this 00059 //@} 00060 00061 }; 00062 00063 /*! @file 00064 * @brief Defines Completiontrans, which causes a transition if all sources have signalled completion 00065 * @author dst (Creator) 00066 * 00067 * $Author: ejt $ 00068 * $Name: tekkotsu-2_2 $ 00069 * $Revision: 1.6 $ 00070 * $State: Exp $ 00071 * $Date: 2004/10/17 01:16:10 $ 00072 */ 00073 00074 #endif |
Tekkotsu v2.2 |
Generated Tue Oct 19 14:19:13 2004 by Doxygen 1.3.9.1 |