Homepage Demos Overview Downloads Tutorials Reference
Credits

BehaviorActivatorControl.h

Go to the documentation of this file.
00001 //-*-c++-*-
00002 #ifndef INCLUDED_BehaviorActivatorControl_h
00003 #define INCLUDED_BehaviorActivatorControl_h
00004 
00005 #include "NullControl.h"
00006 
00007 //! Upon activation, will start, stop, or toggle a behavior
00008 class BehaviorActivatorControl : public NullControl {
00009 public:
00010   //! lets you tell it what action to perform
00011   enum Mode_t { start, stop, toggle };
00012 
00013   //@{
00014   //!constructors
00015   BehaviorActivatorControl(BehaviorBase* behave, Mode_t m=toggle) : NullControl(m==toggle?"Toggle":(m==start?"Start":"Stop"),m==toggle?"Toggles the behavior's activation":(m==start?"Starts the behavior":"Stops the behavior")), target(behave), mode(m) {init();}
00016   BehaviorActivatorControl(const std::string& n, BehaviorBase* behave, Mode_t m=toggle) : NullControl(n,m==toggle?"Toggles the behavior's activation":(m==start?"Starts the behavior":"Stops the behavior")), target(behave), mode(m) {init();}
00017   BehaviorActivatorControl(const std::string& n, const std::string& d, BehaviorBase* behave, Mode_t m=toggle) : NullControl(n,d), target(behave), mode(m) {init();}
00018   //@}
00019 
00020   //!destructor
00021   virtual ~BehaviorActivatorControl() {target->RemoveReference();}
00022 
00023   //! performs the action denoted by #mode
00024   virtual ControlBase * activate(MotionManager::MC_ID disp_id, Socket * gui) {
00025     switch(mode) {
00026     case start:
00027       target->DoStart();
00028       break;
00029     case stop:
00030       target->DoStop();
00031       break;
00032     case toggle:
00033       if(target->isActive())
00034         target->DoStop();
00035       else
00036         target->DoStart();
00037       break;
00038     }
00039     /*if(disp_id!=MotionManager::invalid_MC_ID) {
00040       MMAccessor<LedMC> display(disp_id);
00041       display.mc()->flash(FaceLEDMask,100);
00042       }*/
00043     return NullControl::activate(disp_id,gui);
00044   }
00045 
00046 protected:
00047   //! adds to target's reference counter
00048   void init() {
00049     target->AddReference();
00050   }
00051 
00052   BehaviorBase* target; //!< The behavior to activate/deactivate
00053   Mode_t mode;       //!< the mode this control is in
00054 
00055 private:
00056   BehaviorActivatorControl(const BehaviorActivatorControl&); //!< don't copy this class
00057   BehaviorActivatorControl operator=(const BehaviorActivatorControl&); //!< don't assign this class
00058 };
00059 
00060 /*! @file
00061  * @brief Defines BehaviorActivatorControl, which can either start, stop, or toggle a behavior when activated
00062  * @author ejt (Creator)
00063  *
00064  * $Author: ejt $
00065  * $Name: tekkotsu-2_0 $
00066  * $Revision: 1.8 $
00067  * $State: Rel $
00068  * $Date: 2003/09/25 15:26:10 $
00069  */
00070 
00071 #endif

Tekkotsu v2.0
Generated Wed Jan 21 03:20:27 2004 by Doxygen 1.3.4