Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

SignalTrans.h

Go to the documentation of this file.
00001 //-*-c++-*-
00002 #ifndef INCLUDED_SignalTrans_h_
00003 #define INCLUDED_SignalTrans_h_
00004 
00005 #include "Behaviors/Transition.h"
00006 #include "Events/DataEvent.h"
00007 #include "Events/EventRouter.h"
00008 
00009 //! causes a transition if a DataEvent from stateSignalEGID occurs with a specific value
00010 /*! This allows a state node to signal a transition to another state
00011  *  in a clean symbolic way.  Only the transition itself needs to
00012  *  know the address of the destination node.
00013  */
00014 
00015 template<class T>
00016 class SignalTrans : public Transition {
00017 public:
00018   //! Constructor
00019   SignalTrans(StateNode *destination, const T &value) :
00020     Transition("SignalTrans",destination), val(value)
00021   { }
00022 
00023   //! Constructor
00024   SignalTrans(const std::string &name, StateNode *destination, const T &value) :
00025     Transition("SignalTrans",name,destination), val(value)
00026   { }
00027 
00028   virtual void DoStart() {
00029     Transition::DoStart();
00030     for ( std::vector<StateNode*>::const_iterator it = srcs.begin(); it != srcs.end(); it++ )
00031       erouter->addListener(this,EventBase::stateSignalEGID,(unsigned int)*it);
00032   }
00033 
00034   virtual void processEvent(const EventBase &event) {
00035     const DataEvent<T> &d_event = dynamic_cast<const DataEvent<T>&>(event);
00036     if ( d_event.getData() == val )
00037       fire();
00038   }
00039 
00040 protected:
00041   //! Constructor
00042   SignalTrans(const std::string &classname, const std::string &instancename,
00043         StateNode *destination, const T &value) :
00044     Transition(classname,instancename,destination,value)
00045   { }
00046 
00047   T val; //!< value to compare against
00048 
00049 };
00050 
00051 #endif

Tekkotsu v4.0
Generated Thu Nov 22 00:54:55 2007 by Doxygen 1.5.4