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 
00003 
00005 
00006 
00011 
00016 
00021 //                            X3DComponentWalker.h                            //
00023 
00024 #ifndef X3DCOMPONENTWALKER_H
00025 #define X3DCOMPONENTWALKER_H
00026 
00027 #include "X3DComponent.h"
00028 #include "WalkingFunction.h"
00029 #include "NodeCreationProxy.h"
00030 #include "X3DAbstractNode.h"
00031 
00032 namespace X3DTK {
00033 
00034 class NodeWalkingProxy;
00035 class NodeVisitingProxy;
00036 
00038 
00039 class X3DComponentWalker : public X3DComponent
00040 {
00041 public:
00043   X3DComponentWalker();
00045   virtual ~X3DComponentWalker() = 0;
00046   
00048   void setNodeWalkingProxy(const NodeWalkingProxy *nodeWalkingProxy);
00050   void setNodeVisitingProxy(const NodeVisitingProxy *nodeVisitingProxy);
00051   
00053   template<class T> 
00054   void setActiveFunction()
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     WalkingDict::const_iterator it = walkingDict_.find(name);
00067     if (it != walkingDict_.end())
00068       (*it).second->setActive();
00069       
00070   };
00072   template<class T> 
00073   void setInactiveFunction()
00074   {
00075     T *t = new T();
00076     //iterating the list
00077     SFString name = t->getName();
00078     delete t;
00079     //checking if the node belongs to the component.
00080 /*    if ((nodeCreationProxy_ != 0) && (nodeCreationProxy_->getComponentNameOf(name) != name_))
00081     {
00082       std::cerr << "warning: " << name << " doesn't belong to the " << name_ << " component!" << std::endl;
00083       return;
00084     }*/
00085     if (name != "X3DNode")
00086     {
00087       WalkingDict::const_iterator it = walkingDict_.find(name);
00088       if (it != walkingDict_.end())
00089         (*it).second->setInactive();
00090     } 
00091   };
00093   void setActiveAllFunctions();
00095   void setInactiveAllFunctions();
00096   
00098   WalkingFunction *getWalkingFunctionOf(const Type *type) const;
00099   
00100 protected:  
00102   NodeWalkingProxy *nodeWalkingProxy;
00104   NodeVisitingProxy *nodeVisitingProxy;
00106   template<class C, class T> 
00107   void defineNewWalkingFunction(void (C::*ptrF)(T *) const)
00108   {
00109     Type::beginFunctionDefinition();
00110     
00111     WalkingFunction *WF = new WalkingFunction(reinterpret_cast<ptrToWalkingFunction>(ptrF), this);
00112     //finding if an occurence of T
00113     T *t = new T();
00114     SFString name = t->getTypeName();
00115     Component *TComponent = t->getType()->getComponent();
00116     //checking if the node belongs to the component.
00117     if (TComponent != component)
00118     {
00119       std::cerr << "warning: defineNewWalkingFunction for " << name << " which doesn't belong to the " << component->getName() << " component," << std::endl;
00120       std::cerr << "         but to the " << t->getType()->getComponent()->getName() << " component!" << std::endl;
00121     }         
00122     else
00123       walkingDict_.insert(std::pair<SFString, WalkingFunction *>(component->getName() + "_" + name, WF));
00124     
00125     delete t;       
00126     Type::endFunctionDefinition();
00127   };
00128   
00129 private:
00130   WalkingDict walkingDict_;
00131 };
00132 
00133 }
00134 
00135 #endif

Generated on Wed Sep 10 11:25:15 2003 for X3DToolKit by doxygen1.3