Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

X3DComponentWalker.h

Go to the documentation of this file.
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 "SFSceneGraph.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 SFType *type) const;
00034   
00035 protected:  
00037   Walker *walker;
00039   Visitor *visitor;
00041   template<class C, class T> 
00042   void defineWalkingFunction(void (C::*ptrF)(T *) const)
00043   {
00044     SFType::beginFunctionDefinition();
00045     WalkingFunction *WF = new WalkingFunction(reinterpret_cast<ptrToWalkingFunction>(ptrF), this);
00046     //finding if an occurence of T
00047     T *t = new T();
00048     SFString name = t->getTypeName();
00049     SFComponent *TComponent = t->getType()->getComponent();
00050     //checking if the node belongs to the component.
00051     if (TComponent != component)
00052     {
00053       SFString sg1, sg2;
00054       if (component->getSceneGraphName() != "")
00055         sg1 = " of the " + component->getSceneGraphName() + " scene graph";
00056       if (t->getType()->getSceneGraphName() != "")
00057         sg1 = " of the " + t->getType()->getSceneGraphName() + " scene graph";  
00058 
00059       cx3d << "warning: defineWalkingFunction for " << name << " which doesn't belong to the " << component->getName() << " component" << sg1 << "," << std::endl;
00060       cx3d << "         but to the " << t->getType()->getComponentName() << " component" << sg2 << std::endl;    
00061     }         
00062     else
00063       _walkingDict.insert(std::pair<SFString, WalkingFunction *>(t->getType()->getEncodedName(), WF));
00064     
00065     delete t;       
00066     SFType::endFunctionDefinition();
00067   };
00068   
00069 private:
00070   WalkingDict _walkingDict;
00071 };
00072 
00073 }
00074 
00075 #endif

Generated on Thu Dec 4 13:25:49 2003 for X3DToolKit by doxygen1.2.18