Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

TextMsgTrans.h

Go to the documentation of this file.
00001 //-*-c++-*-
00002 #ifndef INCLUDED_TextMsgTrans_h_
00003 #define INCLUDED_TextMsgTrans_h_
00004 
00005 #include "Behaviors/Transition.h"
00006 #include "Events/TextMsgEvent.h"
00007 
00008 //! Fires when a matching string is received
00009 class TextMsgTrans : public Transition {
00010 
00011   // **************************** //
00012   // ******* CONSTRUCTORS ******* //
00013   // **************************** //
00014 public:
00015   //! default constructor, use type name as instance name
00016   TextMsgTrans(StateNode* destination, const std::string& trigger )
00017     : Transition("TextMsgTrans",destination), msg(trigger)
00018   {}
00019 
00020 protected:
00021   //! constructor for subclasses (which would need to provide a different class name)
00022   TextMsgTrans(const std::string &class_name, const std::string &instance_name, StateNode* destination, const std::string& trigger )
00023     : Transition(class_name,instance_name,destination), msg(trigger)
00024   {}
00025   
00026   
00027   // **************************** //
00028   // ********* METHODS ********** //
00029   // **************************** //
00030 public:
00031   //! Just like a behavior, called when it's time to start doing your thing
00032   virtual void DoStart() {
00033     Transition::DoStart(); // do this first (required)
00034     erouter->addListener(this, EventBase::textmsgEGID );
00035   }
00036 
00037   virtual void processEvent(const EventBase& event) {
00038     const TextMsgEvent *e = dynamic_cast<const TextMsgEvent*>(&event);
00039     if(e==NULL)
00040       return;
00041     if(e->getText()==msg)
00042       fire();
00043   }
00044 
00045   //! Just like a behavior, called when it's time to stop doing your thing
00046   virtual void DoStop() {
00047     erouter->removeListener(this); //generally a good idea, unsubscribe all
00048     Transition::DoStop(); // do this last (required)
00049   }
00050 
00051   static std::string getClassDescription() { return "Fires when a matching string is received"; }
00052   virtual std::string getDescription() const { return getClassDescription(); }
00053 
00054 
00055   // **************************** //
00056   // ********* MEMBERS ********** //
00057   // **************************** //
00058 protected:
00059   std::string msg; //!< the trigger to match messages against
00060 
00061 
00062   // **************************** //
00063   // ********** OTHER *********** //
00064   // **************************** //
00065 private:
00066   // Providing declarations for these functions will avoid a compiler warning if
00067   // you have any class members which are pointers.  However, as it is, an error
00068   // will result if you inadvertantly cause a call to either (which is probably
00069   // a good thing, unless you really intended to copy/assign a behavior, in
00070   // which case simply provide implementations for the functions)
00071   TextMsgTrans(const TextMsgTrans&); //!< don't call (copy constructor)
00072   TextMsgTrans& operator=(const TextMsgTrans&); //!< don't call (assignment operator)
00073 };
00074 
00075 /*! @file
00076  * @brief Defines TextMsgTrans, which fires when a matching string is received
00077  * @author ejt (Creator)
00078  *
00079  * $Author: ejt $
00080  * $Name: tekkotsu-2_4_1 $
00081  * $Revision: 1.3 $
00082  * $State: Exp $
00083  * $Date: 2005/08/07 04:11:03 $
00084  */
00085 
00086 #endif

Tekkotsu v2.4.1
Generated Tue Aug 16 16:32:49 2005 by Doxygen 1.4.4