00001
00002
00004
00005 #ifndef X3DCOMPONENTVISITOR_H
00006 #define X3DCOMPONENTVISITOR_H
00007
00008 #include "X3DComponent.h"
00009 #include "GraphTraversal.h"
00010 #include "EnterFunction.h"
00011 #include "WalkOnFunction.h"
00012 #include "LeaveFunction.h"
00013 #include "X3DAbstractNode.h"
00014 #include "SFSceneGraph.h"
00015
00016 namespace X3DTK {
00017
00019
00020 class X3DComponentVisitor : public X3DComponent
00021 {
00022 public:
00024 X3DComponentVisitor();
00026 virtual ~X3DComponentVisitor() = 0;
00027
00029 EnterFunction *getEnterFunctionOf(const SFType *type) const;
00031 WalkOnFunction *getWalkOnFunctionOf(const SFType *type) const;
00033 LeaveFunction *getLeaveFunctionOf(const SFType *type) const;
00034
00035 protected:
00037 template<class C, class T>
00038 void defineEnterFunction(void (C::*ptrF)(T *) const)
00039 {
00040 SFType::beginFunctionDefinition();
00041 EnterFunction *EF = new EnterFunction(reinterpret_cast<ptrToEnterFunction>(ptrF), this);
00042
00043 T *t = new T();
00044 SFString name = t->getTypeName();
00045 SFComponent *TComponent = t->getType()->getComponent();
00046
00047 if (TComponent != component)
00048 {
00049 SFString sg1, sg2;
00050 if (component->getSceneGraphName() != "")
00051 sg1 = " of the " + component->getSceneGraphName() + " scene graph";
00052 if (t->getType()->getSceneGraphName() != "")
00053 sg1 = " of the " + t->getType()->getSceneGraphName() + " scene graph";
00054
00055 cx3d << "warning: defineEnterFunction for " << name << " which doesn't belong to the " << component->getName() << " component" << sg1 << "," << std::endl;
00056 cx3d << " but to the " << t->getType()->getComponentName() << " component" << sg2 << std::endl;
00057 }
00058 else
00059 _enterDict.insert(std::pair<SFString, EnterFunction *>(t->getType()->getEncodedName(), EF));
00060
00061 delete t;
00062 SFType::endFunctionDefinition();
00063 };
00064
00066 template<class C, class T>
00067 void defineWalkOnFunction(bool (C::*ptrF)(T *, SFAbstractNode) const)
00068 {
00069 SFType::beginFunctionDefinition();
00070 WalkOnFunction *WF = new WalkOnFunction(reinterpret_cast<ptrToWalkOnFunction>(ptrF), this);
00071
00072 T *t = new T();
00073 SFString name = t->getTypeName();
00074 SFComponent *TComponent = t->getType()->getComponent();
00075
00076 if (TComponent != component)
00077 {
00078 SFString sg1, sg2;
00079 if (component->getSceneGraphName() != "")
00080 sg1 = " of the " + component->getSceneGraphName() + " scene graph";
00081 if (t->getType()->getSceneGraphName() != "")
00082 sg1 = " of the " + t->getType()->getSceneGraphName() + " scene graph";
00083
00084 cx3d << "warning: defineWalkOnFunction for " << name << " which doesn't belong to the " << component->getName() << " component" << sg1 << "," << std::endl;
00085 cx3d << " but to the " << t->getType()->getComponentName() << " component" << sg2 << std::endl;
00086 }
00087 else
00088 _walkonDict.insert(std::pair<SFString, WalkOnFunction *>(t->getType()->getEncodedName(), WF));
00089
00090 delete t;
00091 SFType::endFunctionDefinition();
00092 };
00093
00095 template<class C, class T>
00096 void defineLeaveFunction(void (C::*ptrF)(T *) const)
00097 {
00098 SFType::beginFunctionDefinition();
00099 LeaveFunction *LF = new LeaveFunction(reinterpret_cast<ptrToLeaveFunction>(ptrF), this);
00100
00101 T *t = new T();
00102 SFString name = t->getTypeName();
00103 SFComponent *TComponent = t->getType()->getComponent();
00104
00105 if (TComponent != component)
00106 {
00107 SFString sg1, sg2;
00108 if (component->getSceneGraphName() != "")
00109 sg1 = " of the " + component->getSceneGraphName() + " scene graph";
00110 if (t->getType()->getSceneGraphName() != "")
00111 sg1 = " of the " + t->getType()->getSceneGraphName() + " scene graph";
00112
00113 cx3d << "warning: defineLeaveFunction for " << name << " which doesn't belong to the " << component->getName() << " component" << sg1 << "," << std::endl;
00114 cx3d << " but to the " << t->getType()->getComponentName() << " component" << sg2 << std::endl;
00115 }
00116 else
00117 _leaveDict.insert(std::pair<SFString, LeaveFunction *>(t->getType()->getEncodedName(), LF));
00118
00119 delete t;
00120 SFType::endFunctionDefinition();
00121 };
00122
00123 private:
00124 EnterDict _enterDict;
00125 WalkOnDict _walkonDict;
00126 LeaveDict _leaveDict;
00127 };
00128
00129 }
00130
00131 #endif