00001
00002
00004
00005 #ifndef X3DLOADER_H
00006 #define X3DLOADER_H
00007
00008 #include "X3DTypes.h"
00009
00010 #include <list>
00011
00012 namespace X3DTK {
00013
00014 class X3DComponentWalker;
00015 class X3DComponentVisitor;
00016
00017 namespace X3D {
00018
00019 class Creator;
00020 class X3DComponentCreator;
00021 class Scene;
00022 class X3DFileValidator;
00023 class X3DXmlLoader;
00024
00025 }
00026
00028
00029 class X3DLoader
00030 {
00031 public:
00033 X3DLoader();
00035 virtual ~X3DLoader() = 0;
00036
00040 X3D::Scene *load(const char *file, bool fileValidation = true) const;
00041
00043 void setComponentCreator(X3D::X3DComponentCreator *component);
00045 void setComponentWalkerForFileValidator(X3DComponentWalker *component);
00047 void setComponentVisitorForFileValidator(X3DComponentVisitor *component);
00048
00050 template <class L>
00051 static L *getInstanceOf()
00052 {
00053 for (std::list<X3DLoader *>::iterator it = _X3DLoaderList.begin(); it != _X3DLoaderList.end(); ++it)
00054 {
00055 if (typeid(*(*it)) == typeid(L))
00056 return static_cast<L *>(*it);
00057 }
00058 L *l = new L();
00059 _X3DLoaderList.push_back(l);
00060 return l;
00061 };
00062
00064 template <class L>
00065 static void removeInstanceOf()
00066 {
00067 for (std::list<X3DLoader *>::iterator it = _X3DLoaderList.begin(); it != _X3DLoaderList.end(); ++it)
00068 {
00069 if (typeid(*(*it)) == typeid(L))
00070 {
00071 delete *it;
00072 _X3DLoaderList.erase(it);
00073 break;
00074 }
00075 }
00076 };
00077
00079 static void removeAllInstances();
00080
00081 protected:
00083 X3D::Creator *creator;
00085 X3D::X3DFileValidator *fileValidator;
00087 X3D::X3DXmlLoader *xmlLoader;
00088
00089 private:
00090 static std::list<X3DLoader *> _X3DLoaderList;
00091 };
00092
00093 }
00094
00095 #endif