OSGSceneFileHandler.h

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002  *                                OpenSG                                     *
00003  *                                                                           *
00004  *                                                                           *
00005  *             Copyright (C) 2000-2002 by the OpenSG Forum                   *
00006  *                                                                           *
00007  *                            www.opensg.org                                 *
00008  *                                                                           *
00009  *   contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de          *
00010  *                                                                           *
00011 \*---------------------------------------------------------------------------*/
00012 /*---------------------------------------------------------------------------*\
00013  *                                License                                    *
00014  *                                                                           *
00015  * This library is free software; you can redistribute it and/or modify it   *
00016  * under the terms of the GNU Library General Public License as published    *
00017  * by the Free Software Foundation, version 2.                               *
00018  *                                                                           *
00019  * This library is distributed in the hope that it will be useful, but       *
00020  * WITHOUT ANY WARRANTY; without even the implied warranty of                *
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         *
00022  * Library General Public License for more details.                          *
00023  *                                                                           *
00024  * You should have received a copy of the GNU Library General Public         *
00025  * License along with this library; if not, write to the Free Software       *
00026  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                 *
00027  *                                                                           *
00028 \*---------------------------------------------------------------------------*/
00029 /*---------------------------------------------------------------------------*\
00030  *                                Changes                                    *
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 #include "OSGSingletonHolder.h"
00055 
00056 OSG_BEGIN_NAMESPACE
00057 
00058 class GraphOpSeq;
00059 
00064 class OSG_SYSTEM_DLLMAPPING SceneFileHandlerBase
00065 {
00066     /*==========================  PUBLIC  =================================*/
00067 
00068     typedef NodePtr (*FileIOReadCBF )(      SceneFileType *type,
00069                                             std::istream  &is, 
00070                                       const Char8         *ext );
00071 
00072     typedef bool    (*FileIOWriteCBF)(      SceneFileType *type,
00073                                       const NodePtr       &node, 
00074                                             std::ostream  &os,
00075                                       const Char8         *ext, 
00076                                             bool           compress);
00077 
00078   public:
00079 
00080     typedef std::vector<FieldContainerPtr> FCPtrStore;
00081 
00082     /*---------------------------------------------------------------------*/
00086     virtual SceneFileType *getFileType(const Char8 *fileNameOrExtension);
00087 
00088     virtual int getSuffixList(std::list<const Char8*> &suffixList,
00089                               UInt32                   flags = (
00090                                   SceneFileType::OSG_READ_SUPPORTED |
00091                                   SceneFileType::OSG_WRITE_SUPPORTED));
00092 
00094     /*---------------------------------------------------------------------*/
00098     typedef void (*progresscbfp) (UInt32 p);
00099     void setReadProgressCB(progresscbfp fp, bool use_thread = true);
00100     progresscbfp getReadProgressCB(void);
00101 
00102     void updateReadProgress(void);
00103     void updateReadProgress(UInt32 p);
00104 
00105     void setWriteProgressCB(progresscbfp fp);
00106     progresscbfp getWriteProgressCB(void);
00107 
00108     void updateWriteProgress(UInt32 p);
00109 
00111     /*---------------------------------------------------------------------*/
00115     virtual NodePtr    read        (      std::istream &is, 
00116                                     const Char8        *ext,
00117                                           GraphOpSeq   *graphOpSeq = 
00118                                                            _defaultgraphOpSeq);
00119 
00120     virtual FCPtrStore readTopNodes(      std::istream &is, 
00121                                     const Char8        *ext,
00122                                           GraphOpSeq   *graphOpSeq = 
00123                                                            _defaultgraphOpSeq);
00124 
00125     virtual NodePtr    read        (const  Char8       *fileName,
00126                                            GraphOpSeq  *graphOpSeq = 
00127                                                            _defaultgraphOpSeq);
00128 
00129     virtual FCPtrStore readTopNodes(const  Char8       *fileName,
00130                                            GraphOpSeq  *graphOpSeq = 
00131                                                            _defaultgraphOpSeq);
00132 
00134     /*---------------------------------------------------------------------*/
00138     void          setReadCB(FileIOReadCBF fp);
00139     FileIOReadCBF getReadCB(void            );
00140 
00142     /*---------------------------------------------------------------------*/
00146     virtual bool write(const NodePtr      &node, 
00147                              std::ostream &os, 
00148                        const Char8        *ext, 
00149                              bool          compress = false);
00150     virtual bool write(const NodePtr      &node, 
00151                        const Char8        *fileName, 
00152                              bool          compress = false);
00154     /*---------------------------------------------------------------------*/
00158     void           setWriteCB(FileIOWriteCBF fp);
00159     FileIOWriteCBF getWriteCB(void             );
00160 
00162     /*---------------------------------------------------------------------*/
00166     virtual PathHandler* getPathHandler(void                    );
00167     virtual void         setPathHandler(PathHandler *pathHandler);
00168 
00170     /*---------------------------------------------------------------------*/
00174     virtual GraphOpSeq *getDefaultGraphOp(void                  );
00175     virtual void        setDefaultGraphOp(GraphOpSeq *graphOpSeq);
00176 
00178     /*---------------------------------------------------------------------*/
00182     virtual       bool   setOptions(const Char8 *suffix, 
00183                                     const Char8 *options);
00184     virtual const Char8 *getOptions(const Char8 *suffix);
00185 
00187     /*---------------------------------------------------------------------*/
00191     void print (void);
00192 
00194     /*=========================  PROTECTED  ===============================*/
00195 
00196   protected:
00197 
00198     typedef std::list<          SceneFileType *> FileTypeList;
00199     typedef std::map <IDString, FileTypeList  *> FileTypeMap;
00200 
00201     struct FindOverride
00202     {
00203         UInt32 uiRefPriority;
00204 
00205         bool operator() (SceneFileType *fileTypeP);
00206     };
00207 
00208     /*---------------------------------------------------------------------*/
00212     FileTypeMap _suffixTypeMap;
00213 
00214 
00215     bool         addSceneFileType(SceneFileType &fileType);
00216     bool         subSceneFileType(SceneFileType &fileType);
00217     
00219     /*---------------------------------------------------------------------*/
00223     SceneFileHandlerBase(void);
00224 
00226     /*---------------------------------------------------------------------*/
00230     virtual ~SceneFileHandlerBase(void);
00231 
00233     /*==========================  PRIVATE  ================================*/
00234 
00235   private:
00236 
00237     friend class SceneFileType;
00238 
00239     template <class SingletonT>
00240     friend class SingletonHolder;
00241 
00242     std::string initPathHandler(const Char8        *fileName);
00243     
00244     struct progressS
00245     {
00246         UInt64 length;
00247         std::istream *is;
00248     };
00249 
00250            void initReadProgress     (std::istream &is);
00251            void terminateReadProgress(void            );
00252     static void readProgress         (void *data      );
00253 
00254            progresscbfp   _readProgressFP;
00255            progressS      _progressData;
00256            bool           _readReady;
00257            bool           _useProgressThread;
00258 
00259            progresscbfp   _writeProgressFP;
00260 
00261            PathHandler   *_pathHandler;
00262            PathHandler    _defaultPathHandler;
00263     static GraphOpSeq    *_defaultgraphOpSeq;
00264     
00265            FileIOReadCBF  _readFP;
00266            FileIOWriteCBF _writeFP;
00267 
00269     void operator =(const SceneFileHandlerBase &source);
00271     SceneFileHandlerBase(const SceneFileHandlerBase &source);
00272 };
00273 
00274 
00275 #if defined(WIN32)
00276 #    if !defined(OSG_COMPILE_SCENEFILEHANDLER)
00277 OSG_SYSTEM_EXPIMP_TMPL 
00278 template class OSG_SYSTEM_DLLMAPPING SingletonHolder<SceneFileHandlerBase>;
00279 #    endif
00280 #endif
00281 
00282 typedef SingletonHolder<SceneFileHandlerBase> SceneFileHandler;
00283 
00284 typedef SceneFileHandler* SceneFileHandlerP;
00285 
00286 OSG_END_NAMESPACE
00287 
00288 #endif // OSGIMAGEFILEHANDLER_CLASS_DECLARATION