00001 00002 // X3DComponentWalker.h // 00004 00005 #ifndef X3DCOMPONENTWALKER_H 00006 #define X3DCOMPONENTWALKER_H 00007 00008 #include "X3DComponent.h" 00009 #include "WalkingFunction.h" 00010 #include "NodeCreationProxy.h" 00011 #include "X3DAbstractNode.h" 00012 00013 namespace X3DTK { 00014 00015 class NodeWalkingProxy; 00016 class NodeVisitingProxy; 00017 00019 00020 class X3DComponentWalker : public X3DComponent 00021 { 00022 public: 00024 X3DComponentWalker(); 00026 virtual ~X3DComponentWalker() = 0; 00027 00029 void setNodeWalkingProxy(const NodeWalkingProxy *nodeWalkingProxy); 00031 void setNodeVisitingProxy(const NodeVisitingProxy *nodeVisitingProxy); 00032 00034 template<class T> 00035 void setActiveFunction() 00036 { 00037 T *t = new T(); 00038 //iterating the list 00039 SFString name = t->getName(); 00040 delete t; 00041 //checking if the node belongs to the component. 00042 /* if ((nodeCreationProxy_ != 0) && (nodeCreationProxy_->getComponentNameOf(name) != name_)) 00043 { 00044 std::cerr << "warning: " << name << " doesn't belong to the " << name_ << " component!" << std::endl; 00045 return; 00046 }*/ 00047 WalkingDict::const_iterator it = walkingDict_.find(name); 00048 if (it != walkingDict_.end()) 00049 (*it).second->setActive(); 00050 00051 }; 00053 template<class T> 00054 void setInactiveFunction() 00055 { 00056 T *t = new T(); 00057 //iterating the list 00058 SFString name = t->getName(); 00059 delete t; 00060 //checking if the node belongs to the component. 00061 /* if ((nodeCreationProxy_ != 0) && (nodeCreationProxy_->getComponentNameOf(name) != name_)) 00062 { 00063 std::cerr << "warning: " << name << " doesn't belong to the " << name_ << " component!" << std::endl; 00064 return; 00065 }*/ 00066 if (name != "X3DNode") 00067 { 00068 WalkingDict::const_iterator it = walkingDict_.find(name); 00069 if (it != walkingDict_.end()) 00070 (*it).second->setInactive(); 00071 } 00072 }; 00074 void setActiveAllFunctions(); 00076 void setInactiveAllFunctions(); 00077 00079 WalkingFunction *getWalkingFunctionOf(const Type *type) const; 00080 00081 protected: 00083 NodeWalkingProxy *nodeWalkingProxy; 00085 NodeVisitingProxy *nodeVisitingProxy; 00087 template<class C, class T> 00088 void defineNewWalkingFunction(void (C::*ptrF)(T *) const) 00089 { 00090 Type::beginFunctionDefinition(); 00091 00092 WalkingFunction *WF = new WalkingFunction(reinterpret_cast<ptrToWalkingFunction>(ptrF), this); 00093 //finding if an occurence of T 00094 T *t = new T(); 00095 SFString name = t->getTypeName(); 00096 Component *TComponent = t->getType()->getComponent(); 00097 //checking if the node belongs to the component. 00098 if (TComponent != component) 00099 { 00100 std::cerr << "warning: defineNewWalkingFunction for " << name << " which doesn't belong to the " << component->getName() << " component," << std::endl; 00101 std::cerr << " but to the " << t->getType()->getComponent()->getName() << " component!" << std::endl; 00102 } 00103 else 00104 walkingDict_.insert(std::pair<SFString, WalkingFunction *>(component->getName() + "_" + name, WF)); 00105 00106 delete t; 00107 Type::endFunctionDefinition(); 00108 }; 00109 00110 private: 00111 WalkingDict walkingDict_; 00112 }; 00113 00114 } 00115 00116 #endif