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 { start, stop, toggle };
00012
00013
00014
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
00021 virtual ~BehaviorActivatorControl() {target->RemoveReference();}
00022
00023
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
00040
00041
00042
00043 return NullControl::activate(disp_id,gui);
00044 }
00045
00046 protected:
00047
00048 void init() {
00049 target->AddReference();
00050 }
00051
00052 BehaviorBase* target;
00053 Mode_t mode;
00054
00055 private:
00056 BehaviorActivatorControl(const BehaviorActivatorControl&);
00057 BehaviorActivatorControl operator=(const BehaviorActivatorControl&);
00058 };
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071 #endif