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 
00003 
00005 
00006 
00011 
00016 
00021 //                            X3DComponentVisitor.h                           //
00023 
00024 #ifndef X3DCOMPONENTVISITOR_H
00025 #define X3DCOMPONENTVISITOR_H
00026 
00027 #include "X3DComponent.h"
00028 #include "GVManager.h"
00029 #include "EnterFunction.h"
00030 #include "WalkOnFunction.h"
00031 #include "LeaveFunction.h"
00032 #include "NodeCreationProxy.h"
00033 #include "X3DAbstractNode.h"
00034 
00035 namespace X3DTK {
00036 
00038 
00039 class X3DComponentVisitor : public X3DComponent
00040 {
00041 public:
00043   X3DComponentVisitor();
00045   virtual ~X3DComponentVisitor() = 0;
00046   
00048   template<class T>
00049   void setActiveEnterFunction()
00050   {
00051     T *t = new T();
00052     //iterating the list
00053     SFString name = t->getName();
00054     delete t;
00055     //checking if the node belongs to the component.
00056 /*    if ((nodeCreationProxy != 0) && (nodeCreationProxy->getComponentNameOf(name) != name_))
00057     {
00058       std::cerr << "warning: " << name << " doesn't belong to the " << name_ << " component!" << std::endl;
00059       return;
00060     }*/
00061     EnterDict::const_iterator it = enterDict_.find(name);
00062     if (it != enterDict_.end())
00063       (*it).second->setActive();
00064   }
00066   template<class T>
00067   void setActiveWalkOnFunction()
00068   {
00069     T *t = new T();
00070     //iterating the list
00071     SFString name = t->getName();
00072     delete t;
00073     //checking if the node belongs to the component.
00074 /*    if ((nodeCreationProxy != 0) && (nodeCreationProxy->getComponentNameOf(name) != name_))
00075     {
00076       std::cerr << "warning: " << name << " doesn't belong to the " << name_ << " component!" << std::endl;
00077       return;
00078     }*/
00079     WalkOnDict::const_iterator it = walkonDict_.find(name);
00080     if (it != walkonDict_.end())
00081       (*it).second->setActive();
00082   };
00084   template<class T>
00085   void setActiveLeaveFunction()
00086   {
00087     T *t = new T();
00088     //iterating the list
00089     SFString name = t->getName();
00090     delete t;
00091     //checking if the node belongs to the component.
00092 /*    if ((nodeCreationProxy != 0) && (nodeCreationProxy->getComponentNameOf(name) != name_))
00093     {
00094       std::cerr << "warning: " << name << " doesn't belong to the " << name_ << " component!" << std::endl;
00095       return;
00096     }*/
00097     LeaveDict::const_iterator it = leaveDict_.find(name);
00098     if (it != leaveDict_.end())
00099       (*it).second->setActive();
00100   };
00102   template<class T>
00103   void setInactiveEnterFunction()
00104   {
00105     T *t = new T();
00106     //iterating the list
00107     SFString name = t->getName();
00108     delete t;
00109     //checking if the node belongs to the component.
00110 /*    if ((nodeCreationProxy != 0) && (nodeCreationProxy->getComponentNameOf(name) != name_))
00111     {
00112       std::cerr << "warning: " << name << " doesn't belong to the " << name_ << " component!" << std::endl;
00113       return;
00114     }*/
00115     if (name != "X3DNode")
00116     {
00117       EnterDict::const_iterator it = enterDict_.find(name);
00118       if (it != enterDict_.end())
00119         (*it).second->setInactive();
00120     }     
00121   };
00123   template<class T>
00124   void setInactiveWalkOnFunction()
00125   {
00126     T *t = new T();
00127     //iterating the list
00128     SFString name = t->getName();
00129     delete t;
00130     //checking if the node belongs to the component.
00131 /*    if ((nodeCreationProxy != 0) && (nodeCreationProxy->getComponentNameOf(name) != name_))
00132     {
00133       std::cerr << "warning: " << name << " doesn't belong to the " << name_ << " component!" << std::endl;
00134       return;
00135     }*/
00136     if (name != "X3DNode")
00137     {
00138       WalkOnDict::const_iterator it = walkonDict_.find(name);
00139       if (it != walkonDict_.end())
00140         (*it).second->setInactive();
00141     }   
00142   };
00144   template<class T>
00145   void setInactiveLeaveFunction()
00146   {
00147     T *t = new T();
00148     //iterating the list
00149     SFString name = t->getName();
00150     delete t;
00151     //checking if the node belongs to the component.
00152 /*    if ((nodeCreationProxy != 0) && (nodeCreationProxy->getComponentNameOf(name) != name_))
00153     {
00154       std::cerr << "warning: " << name << " doesn't belong to the " << name_ << " component!" << std::endl;
00155       return;
00156     }*/
00157     if (name != "X3DNode")
00158     {
00159       LeaveDict::const_iterator it = leaveDict_.find(name);
00160       if (it != leaveDict_.end())
00161         (*it).second->setInactive();
00162     } 
00163   };
00165   void setActiveAllFunctions();
00167   void setInactiveAllFunctions();
00168   
00170   EnterFunction *getEnterFunctionOf(const Type *type) const;
00172   WalkOnFunction *getWalkOnFunctionOf(const Type *type) const;
00174   LeaveFunction *getLeaveFunctionOf(const Type *type) const;
00175   
00176 protected:    
00178   template<class C, class T> 
00179   void defineNewEnterFunction(void (C::*ptrF)(T *) const)
00180   {
00181     Type::beginFunctionDefinition();
00182     
00183     EnterFunction *EF = new EnterFunction(reinterpret_cast<ptrToEnterFunction>(ptrF), this);
00184     //finding if an occurence of T
00185     T *t = new T();
00186     SFString name = t->getTypeName();
00187     Component *TComponent = t->getType()->getComponent();
00188     //checking if the node belongs to the component.
00189     if (TComponent != component)
00190     {
00191       std::cerr << "warning: defineNewEnterFunction for " << name << " which doesn't belong to the " << component->getName() << " component," << std::endl;
00192       std::cerr << "         but to the " << t->getType()->getComponent()->getName() << " component!" << std::endl;
00193     }
00194     else
00195       enterDict_.insert(std::pair<SFString, EnterFunction *>(component->getName() + "_" + name, EF));
00196       
00197     delete t;
00198     Type::endFunctionDefinition();
00199   };
00200   
00202   template<class C, class T> 
00203   void defineNewWalkOnFunction(bool (C::*ptrF)(T *, SFAbstractNode) const)
00204   {
00205     Type::beginFunctionDefinition();
00206     
00207     WalkOnFunction *WF = new WalkOnFunction(reinterpret_cast<ptrToWalkOnFunction>(ptrF), this);
00208     //finding if an occurence of T
00209     T *t = new T();
00210     SFString name = t->getTypeName();
00211     Component *TComponent = t->getType()->getComponent();
00212     //checking if the node belongs to the component.
00213     if (TComponent != component)
00214     {
00215       std::cerr << "warning: defineNewWalkOnFunction for " << name << " which doesn't belong to the " << component->getName() << " component," << std::endl;
00216       std::cerr << "         but to the " << t->getType()->getComponent()->getName() << " component!" << std::endl;
00217     }
00218     else
00219       walkonDict_.insert(std::pair<SFString, WalkOnFunction *>(component->getName() + "_" + name, WF));
00220       
00221     delete t;
00222     Type::endFunctionDefinition();
00223   };
00224   
00226   template<class C, class T> 
00227   void defineNewLeaveFunction(void (C::*ptrF)(T *) const)
00228   {
00229     Type::beginFunctionDefinition();
00230     
00231     LeaveFunction *LF = new LeaveFunction(reinterpret_cast<ptrToLeaveFunction>(ptrF), this);
00232     //finding if an occurence of T
00233     T *t = new T();
00234     SFString name = t->getTypeName();
00235     Component *TComponent = t->getType()->getComponent();
00236     //checking if the node belongs to the component.
00237     if (TComponent != component)
00238     {
00239       std::cerr << "warning: defineNewLeaveFunction for " << name << " which doesn't belong to the " << component->getName() << " component," << std::endl;
00240       std::cerr << "         but to the " << t->getType()->getComponent()->getName() << " component!" << std::endl;
00241     }
00242     else
00243       leaveDict_.insert(std::pair<SFString, LeaveFunction *>(component->getName() + "_" + name, LF));
00244       
00245     delete t;    
00246     Type::endFunctionDefinition();
00247   };
00248   
00249 private:
00250   EnterDict enterDict_;  
00251   WalkOnDict walkonDict_;  
00252   LeaveDict leaveDict_;  
00253 };
00254 
00255 }
00256 
00257 #endif

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