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

X3DComponentVisitor.h

Go to the documentation of this file.
00001 
00002 //                            X3DComponentVisitor.h                           //
00004 
00005 #ifndef X3DCOMPONENTVISITOR_H
00006 #define X3DCOMPONENTVISITOR_H
00007 
00008 #include "X3DComponent.h"
00009 #include "GVManager.h"
00010 #include "EnterFunction.h"
00011 #include "WalkOnFunction.h"
00012 #include "LeaveFunction.h"
00013 #include "X3DAbstractNode.h"
00014 #include "SceneGraph.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 Type *type) const;
00031   WalkOnFunction *getWalkOnFunctionOf(const Type *type) const;
00033   LeaveFunction *getLeaveFunctionOf(const Type *type) const;
00034   
00035 protected:    
00037   template<class C, class T> 
00038   void defineNewEnterFunction(void (C::*ptrF)(T *) const)
00039   {
00040     Type::beginFunctionDefinition();
00041     
00042     EnterFunction *EF = new EnterFunction(reinterpret_cast<ptrToEnterFunction>(ptrF), this);
00043     //finding if an occurence of T
00044     T *t = new T();
00045     SFString name = t->getTypeName();
00046     Component *TComponent = t->getType()->getComponent();
00047     //checking if the node belongs to the component.
00048     if (TComponent != component)
00049     {
00050       SFString sg1, sg2;
00051       if (component->getSceneGraphName() != "")
00052         sg1 = " of the " + component->getSceneGraphName() + " scene graph";
00053       if (t->getType()->getSceneGraphName() != "")
00054         sg1 = " of the " + t->getType()->getSceneGraphName() + " scene graph";  
00055 
00056       std::cerr << "warning: defineNewEnterFunction for " << name << " which doesn't belong to the " << component->getName() << " component" << sg1 << "," << std::endl;
00057       std::cerr << "         but to the " << t->getType()->getComponentName() << " component" << sg2 << std::endl;
00058     }
00059     else
00060       _enterDict.insert(std::pair<SFString, EnterFunction *>(t->getType()->getEncodedName(), EF));
00061 
00062     delete t;
00063     Type::endFunctionDefinition();
00064   };
00065   
00067   template<class C, class T> 
00068   void defineNewWalkOnFunction(bool (C::*ptrF)(T *, SFAbstractNode) const)
00069   {
00070     Type::beginFunctionDefinition();
00071     
00072     WalkOnFunction *WF = new WalkOnFunction(reinterpret_cast<ptrToWalkOnFunction>(ptrF), this);
00073     //finding if an occurence of T
00074     T *t = new T();
00075     SFString name = t->getTypeName();
00076     Component *TComponent = t->getType()->getComponent();
00077     //checking if the node belongs to the component.
00078     if (TComponent != component)
00079     {
00080       SFString sg1, sg2;
00081       if (component->getSceneGraphName() != "")
00082         sg1 = " of the " + component->getSceneGraphName() + " scene graph";
00083       if (t->getType()->getSceneGraphName() != "")
00084         sg1 = " of the " + t->getType()->getSceneGraphName() + " scene graph";  
00085 
00086       std::cerr << "warning: defineNewWalkOnFunction for " << name << " which doesn't belong to the " << component->getName() << " component" << sg1 << "," << std::endl;
00087       std::cerr << "         but to the " << t->getType()->getComponentName() << " component" << sg2 << std::endl;    
00088     }
00089     else
00090       _walkonDict.insert(std::pair<SFString, WalkOnFunction *>(t->getType()->getEncodedName(), WF));
00091       
00092     delete t;
00093     Type::endFunctionDefinition();
00094   };
00095   
00097   template<class C, class T> 
00098   void defineNewLeaveFunction(void (C::*ptrF)(T *) const)
00099   {
00100     Type::beginFunctionDefinition();
00101     
00102     LeaveFunction *LF = new LeaveFunction(reinterpret_cast<ptrToLeaveFunction>(ptrF), this);
00103     //finding if an occurence of T
00104     T *t = new T();
00105     SFString name = t->getTypeName();
00106     Component *TComponent = t->getType()->getComponent();
00107     //checking if the node belongs to the component.
00108     if (TComponent != component)
00109     {
00110       SFString sg1, sg2;
00111       if (component->getSceneGraphName() != "")
00112         sg1 = " of the " + component->getSceneGraphName() + " scene graph";
00113       if (t->getType()->getSceneGraphName() != "")
00114         sg1 = " of the " + t->getType()->getSceneGraphName() + " scene graph";  
00115 
00116       std::cerr << "warning: defineNewLeaveFunction for " << name << " which doesn't belong to the " << component->getName() << " component" << sg1 << "," << std::endl;
00117       std::cerr << "         but to the " << t->getType()->getComponentName() << " component" << sg2 << std::endl;    
00118     }
00119     else
00120       _leaveDict.insert(std::pair<SFString, LeaveFunction *>(t->getType()->getEncodedName(), LF));
00121       
00122     delete t;    
00123     Type::endFunctionDefinition();
00124   };
00125   
00126 private:
00127   EnterDict _enterDict;  
00128   WalkOnDict _walkonDict;  
00129   LeaveDict _leaveDict;  
00130 };
00131 
00132 }
00133 
00134 #endif

Generated on Thu Oct 9 13:50:55 2003 for X3DToolKit by doxygen1.2.18