00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #ifndef _OSGSCENEFILEHANDLER_H_
00040 #define _OSGSCENEFILEHANDLER_H_
00041 #ifdef __sgi
00042 #pragma once
00043 #endif
00044
00045 #include <string>
00046 #include <list>
00047 #include <map>
00048 #include <iostream>
00049
00050 #include <OSGSystemDef.h>
00051 #include <OSGBaseTypes.h>
00052 #include <OSGSceneFileType.h>
00053 #include <OSGPathHandler.h>
00054
00055 OSG_BEGIN_NAMESPACE
00056
00057 class GraphOpSeq;
00058
00063 class OSG_SYSTEMLIB_DLLMAPPING SceneFileHandler
00064 {
00065
00066 public:
00067
00068 typedef std::vector<FieldContainerPtr> FCPtrStore;
00069
00070
00074 static SceneFileHandler &the(void);
00075
00077
00081 virtual ~SceneFileHandler(void);
00082
00084
00088 virtual SceneFileType *getFileType(const Char8 *fileNameOrExtension);
00089
00090 virtual int getSuffixList(std::list<const Char8*> & suffixList,
00091 UInt32 flags = SceneFileType::OSG_READ_SUPPORTED |
00092 SceneFileType::OSG_WRITE_SUPPORTED);
00093
00095
00099 typedef void (*progresscbfp) (UInt32 p);
00100 typedef void (*filenamecbfp) (const Char8 *fname);
00101
00102 void setReadProgressCB(progresscbfp fp, bool use_thread = true);
00103 progresscbfp getReadProgressCB(void);
00104
00105 void setReadBeginCB(filenamecbfp fp);
00106 filenamecbfp getReadBeginCB(void);
00107
00108 void setReadEndCB(filenamecbfp fp);
00109 filenamecbfp getReadEndCB(void);
00110
00111 void updateReadProgress(void);
00112 void updateReadProgress(UInt32 p);
00113
00114 void triggerReadBegin(const Char8 *fname);
00115 void triggerReadEnd (const Char8 *fname);
00116
00117 void setWriteProgressCB(progresscbfp fp);
00118 progresscbfp getWriteProgressCB(void);
00119
00120 void setWriteBeginCB(filenamecbfp fp);
00121 filenamecbfp getWriteBeginCB(void);
00122
00123 void setWriteEndCB(filenamecbfp fp);
00124 filenamecbfp getWriteEndCB(void);
00125
00126 void updateWriteProgress(UInt32 p);
00127
00128 void triggerWriteBegin(const Char8 *fname);
00129 void triggerWriteEnd (const Char8 *fname);
00130
00132
00136 virtual NodePtr read (std::istream &is, const Char8* ext,
00137 GraphOpSeq *graphOpSeq = _defaultgraphOpSeq);
00138
00139 virtual FCPtrStore readTopNodes (std::istream &is, const Char8* ext,
00140 GraphOpSeq *graphOpSeq = _defaultgraphOpSeq);
00141
00142 virtual NodePtr read (const Char8 *fileName,
00143 GraphOpSeq *graphOpSeq = _defaultgraphOpSeq);
00144
00145 virtual FCPtrStore readTopNodes (const Char8 *fileName,
00146 GraphOpSeq *graphOpSeq = _defaultgraphOpSeq);
00147
00148 typedef NodePtr (*fileioreadcbfp) (SceneFileType *type,
00149 std::istream &is, const Char8* ext);
00150 void setReadCB(fileioreadcbfp fp);
00151 fileioreadcbfp getReadCB(void);
00152
00154
00158 virtual bool write(const NodePtr &node, std::ostream &os, const Char8 *ext, bool compress = false);
00159 virtual bool write(const NodePtr &node, const Char8 *fileName, bool compress = false);
00160
00161 typedef bool (*fileiowritecbfp) (SceneFileType *type,
00162 const NodePtr &node, std::ostream &os,
00163 const Char8 *ext, bool compress);
00164 void setWriteCB(fileiowritecbfp fp);
00165 fileiowritecbfp getWriteCB(void);
00166
00168
00172 virtual PathHandler* getPathHandler(void );
00173 virtual void setPathHandler(PathHandler *pathHandler);
00174
00176
00180 virtual GraphOpSeq *getDefaultGraphOp(void );
00181 virtual void setDefaultGraphOp(GraphOpSeq *graphOpSeq);
00182
00184
00188 virtual bool setOptions(const Char8 *suffix, const Char8 *options);
00189 virtual const Char8 *getOptions(const Char8 *suffix);
00190
00192
00196 void print (void);
00197
00199
00200 protected:
00201
00202 typedef std::list< SceneFileType *> FileTypeList;
00203 typedef std::map <IDString, FileTypeList *> FileTypeMap;
00204
00205 struct FindOverride
00206 {
00207 UInt32 uiRefPriority;
00208
00209 bool operator() (SceneFileType *fileTypeP);
00210 };
00211
00212
00216 static SceneFileHandler *_the;
00217
00218 static GraphOpSeq *_defaultgraphOpSeq;
00219
00220 FileTypeMap _suffixTypeMap;
00221
00222
00223 static bool addSceneFileType(SceneFileType &fileType);
00224 static bool subSceneFileType(SceneFileType &fileType);
00225
00227
00231 SceneFileHandler(void);
00232 SceneFileHandler(const SceneFileHandler &obj);
00233
00235
00236 private:
00237
00238 friend class OSG_SYSTEMLIB_DLLMAPPING SceneFileType;
00239
00240 std::string initPathHandler(const Char8 *fileName);
00241
00243 void operator =(const SceneFileHandler &source);
00244
00245 typedef struct
00246 {
00247 UInt64 length;
00248 std::istream *is;
00249 } progressS;
00250
00251 void initReadProgress(std::istream &is);
00252 void terminateReadProgress(void);
00253 static void readProgress(void *data);
00254
00255 progresscbfp _readProgressFP;
00256 filenamecbfp _readBeginFP;
00257 filenamecbfp _readEndFP;
00258
00259 progressS _progressData;
00260 bool _readReady;
00261 bool _useProgressThread;
00262
00263 progresscbfp _writeProgressFP;
00264 filenamecbfp _writeBeginFP;
00265 filenamecbfp _writeEndFP;
00266
00267 PathHandler *_pathHandler;
00268 PathHandler _defaultPathHandler;
00269
00270 fileioreadcbfp _readFP;
00271 fileiowritecbfp _writeFP;
00272
00273 };
00274
00275 typedef SceneFileHandler* SceneFileHandlerP;
00276
00277 OSG_END_NAMESPACE
00278
00279 #define OSGSCENEFILEHANDLER_HEADER_CVSID "@(#)$Id: $"
00280
00281 #endif // OSGIMAGEFILEHANDLER_CLASS_DECLARATION