00001 00002 // X3DComponentWalker.h // 00004 00005 #ifndef X3DCOMPONENTWALKER_H 00006 #define X3DCOMPONENTWALKER_H 00007 00008 #include "X3DComponent.h" 00009 #include "WalkingFunction.h" 00010 #include "X3DAbstractNode.h" 00011 #include "Walker.h" 00012 #include "Visitor.h" 00013 #include "SceneGraph.h" 00014 00015 namespace X3DTK { 00016 00018 00019 class X3DComponentWalker : public X3DComponent 00020 { 00021 public: 00023 X3DComponentWalker(); 00025 virtual ~X3DComponentWalker() = 0; 00026 00028 void setWalker(Walker *walker); 00030 void setVisitor(Visitor *visitor); 00031 00033 WalkingFunction *getWalkingFunctionOf(const Type *type) const; 00034 00035 protected: 00037 Walker *walker; 00039 Visitor *visitor; 00041 template<class C, class T> 00042 void defineNewWalkingFunction(void (C::*ptrF)(T *) const) 00043 { 00044 Type::beginFunctionDefinition(); 00045 00046 WalkingFunction *WF = new WalkingFunction(reinterpret_cast<ptrToWalkingFunction>(ptrF), this); 00047 //finding if an occurence of T 00048 T *t = new T(); 00049 SFString name = t->getTypeName(); 00050 Component *TComponent = t->getType()->getComponent(); 00051 //checking if the node belongs to the component. 00052 if (TComponent != component) 00053 { 00054 SFString sg1, sg2; 00055 if (component->getSceneGraphName() != "") 00056 sg1 = " of the " + component->getSceneGraphName() + " scene graph"; 00057 if (t->getType()->getSceneGraphName() != "") 00058 sg1 = " of the " + t->getType()->getSceneGraphName() + " scene graph"; 00059 00060 std::cerr << "warning: defineNewWalkingFunction for " << name << " which doesn't belong to the " << component->getName() << " component" << sg1 << "," << std::endl; 00061 std::cerr << " but to the " << t->getType()->getComponentName() << " component" << sg2 << std::endl; 00062 } 00063 else 00064 _walkingDict.insert(std::pair<SFString, WalkingFunction *>(t->getType()->getEncodedName(), WF)); 00065 00066 delete t; 00067 Type::endFunctionDefinition(); 00068 }; 00069 00070 private: 00071 WalkingDict _walkingDict; 00072 }; 00073 00074 } 00075 00076 #endif