MCNode.h
Go to the documentation of this file.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 #include "IPC/SharedObject.h"
00009
00010
00011 class MCNodeBase : public StateNode {
00012 public:
00013 static const char defName[];
00014 static const char defDesc[];
00015
00016
00017 virtual ~MCNodeBase() { delete mc; mc=NULL; }
00018
00019
00020 virtual void preStart();
00021
00022
00023 virtual void stop();
00024
00025
00026 virtual void doEvent();
00027
00028
00029
00030 virtual void setMC(MotionManager::MC_ID mcid);
00031
00032
00033 virtual MotionManager::MC_ID getMC_ID() { return mc_id; }
00034
00035
00036 virtual float getPriority() const { return priority; }
00037
00038
00039 virtual void setPriority(const float p);
00040
00041
00042
00043
00044
00045
00046 virtual void motionFails();
00047
00048 static std::string getClassDescription() { return defName; }
00049 virtual std::string getDescription() const { return getClassDescription(); }
00050
00051 protected:
00052
00053 MCNodeBase(bool expectCompletion)
00054 : StateNode(), mc(NULL), mc_id(MotionManager::invalid_MC_ID),
00055 priority(MotionManager::kStdPriority), mcCompletes(expectCompletion)
00056 {}
00057
00058
00059 MCNodeBase(const std::string &node_name, bool expectCompletion=true)
00060 : StateNode(node_name), mc(NULL), mc_id(MotionManager::invalid_MC_ID),
00061 priority(MotionManager::kStdPriority), mcCompletes(expectCompletion)
00062 {}
00063
00064
00065
00066
00067 virtual SharedObjectBase& getPrivateMC()=0;
00068
00069
00070 virtual bool hasPrivateMC() { return mc!=NULL; }
00071
00072 SharedObjectBase* mc;
00073 MotionManager::MC_ID mc_id;
00074 float priority;
00075 bool mcCompletes;
00076
00077 private:
00078 MCNodeBase(const MCNodeBase&);
00079 MCNodeBase& operator=(const MCNodeBase&);
00080 };
00081
00082
00083 template<class T, const char* mcName=MCNodeBase::defName, const char* mcDesc=MCNodeBase::defDesc, bool completes=true>
00084 class MCNode : public MCNodeBase {
00085 public:
00086
00087 MCNode()
00088 : MCNodeBase(completes)
00089 {}
00090
00091
00092 explicit MCNode(const std::string& nm)
00093 : MCNodeBase(nm,completes)
00094 {}
00095
00096
00097 explicit MCNode(const char* nm)
00098 : MCNodeBase(nm,completes)
00099 {}
00100
00101
00102 virtual ~MCNode() {}
00103
00104
00105
00106 virtual MMAccessor<T> getMC();
00107
00108 static std::string getClassDescription() { return mcDesc; }
00109 virtual std::string getDescription() const { return getClassDescription(); }
00110
00111 protected:
00112 explicit MCNode(bool subCompletes) : MCNodeBase(subCompletes) {}
00113
00114
00115 MCNode(const std::string& nm, bool subCompletes) : MCNodeBase(nm,subCompletes) {}
00116
00117 virtual SharedObject<T>& getPrivateMC();
00118 };
00119
00120
00121
00122
00123
00124
00125 template<class T, const char* mcName, const char* mcDesc, bool completes>
00126 MMAccessor<T> MCNode<T,mcName,mcDesc,completes>::getMC() {
00127 if(mc_id==MotionManager::invalid_MC_ID) {
00128
00129 return MMAccessor<T>(*getPrivateMC(),false);
00130 } else {
00131
00132 return MMAccessor<T>(mc_id);
00133 }
00134 }
00135
00136 template<class T, const char* mcName, const char* mcDesc, bool completes>
00137 SharedObject<T>& MCNode<T,mcName,mcDesc,completes>::getPrivateMC() {
00138 if(mc==NULL)
00139 mc=new SharedObject<T>;
00140 return dynamic_cast<SharedObject<T>&>(*mc);
00141 }
00142
00143
00144
00145
00146
00147
00148
00149 #endif