BehaviorActivatorControl.h
Go to the documentation of this file.00001
00002 #ifndef INCLUDED_BehaviorActivatorControl_h
00003 #define INCLUDED_BehaviorActivatorControl_h
00004
00005 #include "NullControl.h"
00006
00007
00008 class BehaviorActivatorControl : public NullControl {
00009 public:
00010
00011 enum Mode_t {
00012 start,
00013 stop,
00014 toggle
00015 };
00016
00017
00018
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
00025 virtual ~BehaviorActivatorControl() {target->removeReference();}
00026
00027
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
00044
00045
00046
00047 return NullControl::activate(disp_id,gui);
00048 }
00049
00050 protected:
00051
00052 void init() {
00053 target->addReference();
00054 }
00055
00056 BehaviorBase* target;
00057 Mode_t mode;
00058
00059 private:
00060 BehaviorActivatorControl(const BehaviorActivatorControl&);
00061 BehaviorActivatorControl operator=(const BehaviorActivatorControl&);
00062 };
00063
00064
00065
00066
00067
00068
00069 #endif