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

Generated on Tue Jul 15 16:46:53 2003 for X3DToolKit by doxygen1.3