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

GraphTraversal.h

Go to the documentation of this file.
00001 
00002 //                            GraphTraversal.h                                //
00004 
00005 #ifndef GRAPHTRAVERSAL_H
00006 #define GRAPHTRAVERSAL_H
00007 
00008 #include "StateVariables.h"
00009 #include "X3DTypes.h"
00010 
00011 #include <list>
00012 #include <typeinfo>
00013 #include <iostream>
00014 
00015 namespace X3DTK {
00016 
00017 class Walker;
00018 class Visitor; 
00019 class X3DComponentWalker;
00020 class X3DComponentVisitor;
00021 
00023 
00024 class GraphTraversal
00025 {
00026 public:
00028   GraphTraversal();
00030   virtual ~GraphTraversal();
00031   
00033   void setComponentWalker(X3DComponentWalker *component);
00035   void setComponentVisitor(X3DComponentVisitor *component);
00037   void setAutoDeleteComponents(bool value);
00039   void traverse(SFAbstractNode N) const;
00040   
00042   friend GraphTraversal *joinGraphTraversals(GraphTraversal *A1, GraphTraversal *A2);
00044   friend GraphTraversal *mergeGraphTraversals(GraphTraversal *A1, GraphTraversal *A2);
00045   
00047   template <class S>
00048   static S *getInstanceOf()
00049   {
00050     for (std::list<StateVariables *>::iterator it = _stateVariablesList.begin(); it != _stateVariablesList.end(); ++it)
00051     {
00052       if (typeid(*(*it)) == typeid(S))
00053         return static_cast<S *>(*it);       
00054     }
00055     S *s = new S();
00056     _stateVariablesList.push_back(s);
00057     return s;
00058   };
00059 
00061   template <class S>
00062   static void removeInstanceOf()
00063   {
00064     for (std::list<StateVariables *>::iterator it = _stateVariablesList.begin(); it != _stateVariablesList.end(); ++it)
00065     {
00066       if (typeid(*(*it)) == typeid(S))
00067       {
00068         delete *it;
00069         _stateVariablesList.erase(it);
00070         break;
00071       }  
00072     }
00073   };
00074     
00075 protected:
00077   Visitor *visitor;     
00079   Walker *walker;
00080 
00081 private:
00082   static std::list<StateVariables *> _stateVariablesList;  
00083 };
00084 
00085 }
00086 
00087 #endif

Generated on Thu Dec 4 13:25:46 2003 for X3DToolKit by doxygen1.2.18