Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

GrasperTrans.h

Go to the documentation of this file.
00001 //-*-c++-*-
00002 #ifndef INCLUDED_GrasperTrans_h_
00003 #define INCLUDED_GrasperTrans_h_
00004 
00005 #include "Behaviors/Transition.h"
00006 #include "Events/GrasperEvent.h"
00007 #include "Events/EventRouter.h"
00008 
00009 //! Causes a transition if a GrasperEvent from grasperEGID occurs, and checks for a specific error value if one is supplied.
00010 /*! This allows a GrasperNode 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.  The GrasperEvent
00013  *  will be supplied to the destination node's doStart() method.
00014  */
00015 
00016 class GrasperTrans : public Transition {
00017 public:
00018   //! Constructor
00019   GrasperTrans(StateNode *destination) :
00020     Transition(destination), errorCode(), valueSupplied(false)
00021   { }
00022 
00023   //! Constructor
00024   GrasperTrans(StateNode *destination, GrasperRequest::GrasperErrorType_t value) :
00025     Transition(destination), errorCode(value), valueSupplied(true)
00026   { }
00027 
00028   //! Constructor
00029   GrasperTrans(const std::string &name, StateNode *destination) :
00030     Transition(name,destination), errorCode(), valueSupplied(false)
00031   { }
00032 
00033   //! Constructor
00034   GrasperTrans(const std::string &name, StateNode *destination, GrasperRequest::GrasperErrorType_t value) :
00035     Transition(name,destination), errorCode(value), valueSupplied(true)
00036   { }
00037 
00038   virtual void postStart() {
00039     Transition::postStart();
00040     for ( std::vector<StateNode*>::const_iterator it = srcs.begin(); it != srcs.end(); it++ )
00041       erouter->addListener(this,EventBase::grasperEGID,(size_t)*it);
00042   }
00043 
00044   virtual void doEvent() {
00045     const GrasperEvent *graspEvent = dynamic_cast<const GrasperEvent*>(event);
00046     if ( graspEvent != NULL )
00047       // Fire if we have a GrasperEvent and (1) no errorCode was
00048       // specified for the transition, or (2) the event matches the
00049       // specified code, or (3) the specified code is someError and
00050       // the event has any code other than noError.
00051       if ( !valueSupplied || 
00052      graspEvent->getErrorType() == errorCode ||
00053      (errorCode == GrasperRequest::someError && graspEvent->getErrorType() != GrasperRequest::noError) )
00054   fire(*event);
00055   }
00056 
00057   //! Copy constructor required in case we're storing a pointer
00058   GrasperTrans(const GrasperTrans &src) : Transition(src), errorCode(src.errorCode), valueSupplied(src.valueSupplied) {}
00059   
00060   //! Assignment operator required in case we're storing a pointer
00061   GrasperTrans& operator=(const GrasperTrans& src) {
00062     errorCode = src.errorCode;
00063     valueSupplied = src.valueSupplied;
00064     return *this;
00065   }
00066 
00067 protected:
00068   GrasperRequest::GrasperErrorType_t errorCode; //!< value to compare against
00069   bool valueSupplied;  //!< true if a value was supplied in the constructor
00070 };
00071 
00072 #endif

Tekkotsu v5.1CVS
Generated Mon May 9 04:58:41 2016 by Doxygen 1.6.3