Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
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 {
00012     start, //!< Passed to constructor, indicates this control should start the behavior when activated
00013     stop,  //!< Passed to constructor, indicates this control should stop the behavior when activated
00014     toggle //!< Passed to constructor, indicates this control should toggle the behavior when activated
00015   };
00016 
00017   //@{
00018   //!constructors
00019   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();}
00020   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();}
00021   BehaviorActivatorControl(const std::string& n, const std::string& d, BehaviorBase* behave, Mode_t m=toggle) : NullControl(n,d), target(behave), mode(m) {init();}
00022   //@}
00023 
00024   //!destructor
00025   virtual ~BehaviorActivatorControl() {target->removeReference();}
00026 
00027   //! performs the action denoted by #mode
00028   virtual ControlBase * activate(MC_ID disp_id, Socket * gui) {
00029     switch(mode) {
00030     case start:
00031       target->start();
00032       break;
00033     case stop:
00034       target->stop();
00035       break;
00036     case toggle:
00037       if(target->isActive())
00038         target->stop();
00039       else
00040         target->start();
00041       break;
00042     }
00043     /*if(disp_id!=invalid_MC_ID) {
00044       MMAccessor<LedMC> display(disp_id);
00045       display.mc()->flash(FaceLEDMask,100);
00046       }*/
00047     return NullControl::activate(disp_id,gui);
00048   }
00049 
00050 protected:
00051   //! adds to target's reference counter
00052   void init() {
00053     target->addReference();
00054   }
00055 
00056   BehaviorBase* target; //!< The behavior to activate/deactivate
00057   Mode_t mode;       //!< the mode this control is in
00058 
00059 private:
00060   BehaviorActivatorControl(const BehaviorActivatorControl&); //!< don't copy this class
00061   BehaviorActivatorControl operator=(const BehaviorActivatorControl&); //!< don't assign this class
00062 };
00063 
00064 /*! @file
00065  * @brief Defines BehaviorActivatorControl, which can either start, stop, or toggle a behavior when activated
00066  * @author ejt (Creator)
00067  */
00068 
00069 #endif

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