00001
00002 #ifndef INCLUDED_MCNode_h_
00003 #define INCLUDED_MCNode_h_
00004
00005 #include "Behaviors/StateNode.h"
00006 #include "Motion/MotionManager.h"
00007 #include "Motion/MMAccessor.h"
00008
00009
00010 class MCNodeBase : public StateNode {
00011 public:
00012 static const char defName[];
00013 static const char defDesc[];
00014
00015
00016 virtual ~MCNodeBase() { delete mc; }
00017
00018
00019 virtual void DoStart();
00020
00021
00022 virtual void processEvent(const EventBase& );
00023
00024
00025 virtual void DoStop();
00026
00027
00028
00029 virtual void setMC(MotionManager::MC_ID mcid);
00030
00031
00032 virtual MotionManager::MC_ID getMC_ID() { return mc_id; }
00033
00034 static std::string getClassDescription() { return defName; }
00035 virtual std::string getDescription() const { return getClassDescription(); }
00036
00037 protected:
00038
00039 MCNodeBase(const std::string &class_name, const std::string &node_name, bool expectCompletion=true)
00040 : StateNode(class_name,node_name), mc(NULL), mc_id(MotionManager::invalid_MC_ID), mcCompletes(expectCompletion)
00041 {}
00042
00043
00044
00045
00046 virtual SharedObjectBase& getPrivateMC()=0;
00047
00048
00049 virtual bool hasPrivateMC() { return mc!=NULL; }
00050
00051 SharedObjectBase* mc;
00052 MotionManager::MC_ID mc_id;
00053 bool mcCompletes;
00054
00055 private:
00056 MCNodeBase(const MCNodeBase&);
00057 MCNodeBase& operator=(const MCNodeBase&);
00058 };
00059
00060
00061 template<class T, const char* mcName=MCNodeBase::defName, const char* mcDesc=MCNodeBase::defDesc, bool completes=true>
00062 class MCNode : public MCNodeBase {
00063 public:
00064
00065 MCNode()
00066 : MCNodeBase(mcName,mcName,completes)
00067 {}
00068
00069
00070 MCNode(const std::string& nm)
00071 : MCNodeBase(mcName,nm,completes)
00072 {}
00073
00074
00075 virtual ~MCNode() {}
00076
00077
00078
00079 virtual MMAccessor<T> getMC();
00080
00081 static std::string getClassDescription() { return mcDesc; }
00082 virtual std::string getDescription() const { return getClassDescription(); }
00083
00084 protected:
00085
00086 MCNode(const std::string &class_name, const std::string &node_name)
00087 : MCNodeBase(class_name,node_name)
00088 {}
00089
00090 virtual SharedObject<T>& getPrivateMC();
00091 };
00092
00093
00094
00095
00096
00097
00098 template<class T, const char* mcName, const char* mcDesc, bool completes>
00099 MMAccessor<T> MCNode<T,mcName,mcDesc,completes>::getMC() {
00100 if(mc_id==MotionManager::invalid_MC_ID) {
00101
00102 return MMAccessor<T>(*getPrivateMC());
00103 } else {
00104
00105 return MMAccessor<T>(mc_id);
00106 }
00107 }
00108
00109 template<class T, const char* mcName, const char* mcDesc, bool completes>
00110 SharedObject<T>& MCNode<T,mcName,mcDesc,completes>::getPrivateMC() {
00111 if(mc==NULL)
00112 mc=new SharedObject<T>;
00113 return dynamic_cast<SharedObject<T>&>(*mc);
00114 }
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128 #endif