SFType.h

Go to the documentation of this file.
00001 #ifndef X3DTK_SFTYPE_H
00002 #define X3DTK_SFTYPE_H
00003 
00004 #include <map>
00005 #include <vector>
00006 
00007 #include "X3DTypes.h"
00008 #include "SFSceneGraph.h"
00009 #include "SFComponent.h"
00010 #include "Singleton.h"
00011 #include "X3DNodeCloner.h"
00012 #include "X3DMemberFunctor.h"
00013 #include "X3DSFNodeFunctor.h"
00014 #include "X3DMFNodeFunctor.h"
00015 
00016 namespace X3DTK {
00017 
00018 class Visitor;
00019 class BaseRecorder;
00020 
00021 namespace X3D {
00022   class Creator;
00023   class X3DComponentCreator;
00024 }
00025 
00026 struct FieldManager
00027 {
00028   X3DMemberFunctor *memberFunctor;
00029   X3DFieldLoader *loader;
00030   X3DFieldWriter *writer;
00031   SFString init;
00032 };
00033 
00044 class SFType
00045 {
00046   friend class X3D::Creator;
00047   friend class Walker;
00048   friend class Visitor;
00049   friend class BaseRecorder;
00050   friend class X3D::X3DComponentCreator;
00051   friend class X3DComponentWalker;
00052   friend class X3DComponentVisitor;
00053   friend class X3DAbstractNode;
00054   friend class X3DRoute;
00055 
00056 public:
00058   static SFType *getTypeOfName(const SFString &sceneGraph, const SFString &component, const SFString &name);
00060   static SFType *getTypeOfId(int id);
00062   static void recomputeIds();
00063   
00065   inline const SFString &getName() const {return _name;};
00067   inline const SFString &getComponentName() const {return _component->getName();};
00069   inline const SFString &getSceneGraphName() const {return _component->getSceneGraph()->getName();};
00071   inline int getId() const {return _id;};
00073   inline SFType *getParent() const {return _parent;};
00075   inline const MFType &getChildren() const {return _childList;};
00077   inline SFComponent *getComponent() const {return _component;};
00079   inline SFSceneGraph *getSceneGraph() const {return _component->getSceneGraph();};
00081   static void printInheritanceTree();
00082 
00084   static SFString encodeKey(const SFString &sceneGraph, const SFString &component, const SFString &SFType);
00086   inline SFString getEncodedName() const {return encodeKey(getSceneGraphName(), getComponentName(), getName());};
00087   
00089   SFString getEventIn(const SFString &name) const;
00091   SFString getEventOut(const SFString &name) const;
00092   
00094   std::map<SFString, FieldManager> &attributesMap() {return _attributesMap;};
00096   std::vector<std::pair<SFString, X3DSFNodeFunctor *> > &nodeMap() {return _nodeMap;};
00098   std::vector<std::pair<SFString, X3DMFNodeFunctor *> > &nodesMap() {return _nodesMap;};
00099   
00100 private:
00102   SFType(const SFString &name, const SFString &component, const SFString &sceneGraph, X3DNodeCloner *cloner);
00103   ~SFType();
00104 
00106   void setParent(SFType *parent);
00108   void addOneReference();
00110   void addOneReferenceRecursive();
00112   static void removeOneReference(SFType *type);
00114   static void defineTypeName(SFType **type, const SFString &name, const SFString &component, const SFString &sceneGraph, X3DNodeCloner *cloner);
00116   X3DMemberFunctor *getMemberFunctor(const SFString &name) const;
00118   X3DFieldLoader *getFieldLoader(const SFString &name) const;
00120   X3DFieldWriter *getFieldWriter(const SFString &name) const;
00121   
00123   static void addVisitor(Visitor *visitor);
00125   static void removeVisitor(Visitor *visitor);
00126 
00129   static void beginFunctionDefinition();
00131   static void endFunctionDefinition();
00132   
00134   SFString _name;
00135   int _id;
00136   int _refCount;
00137   SFType *_parent;
00138   MFType _childList;
00139   SFComponent *_component;
00140   X3DNodeCloner *_cloner;
00141   std::map<SFString, FieldManager> _attributesMap;
00142   std::vector<std::pair<SFString, X3DSFNodeFunctor *> > _nodeMap;
00143   std::vector<std::pair<SFString, X3DMFNodeFunctor *> > _nodesMap;
00144   
00146   static int count;
00147   static MFType _typeList;  
00148   static std::list<Visitor *> _actorList;
00149   static bool _functionDefinition;
00150  
00151   void printInheritanceTree(SFString tab) const;
00152 };
00153 
00154 }
00155 
00156 #endif

Generated on Fri Jul 30 12:02:28 2004 for X3DToolKit by doxygen 1.3.6