1 /*---------------------------------------------------------------------------*\
5 * Copyright (C) 2000-2002 by the OpenSG Forum *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
15 * This library is free software; you can redistribute it and/or modify it *
16 * under the terms of the GNU Library General Public License as published *
17 * by the Free Software Foundation, version 2. *
19 * This library is distributed in the hope that it will be useful, but *
20 * WITHOUT ANY WARRANTY; without even the implied warranty of *
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
22 * Library General Public License for more details. *
24 * You should have received a copy of the GNU Library General Public *
25 * License along with this library; if not, write to the Free Software *
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
37 \*---------------------------------------------------------------------------*/
39 #ifndef _OSGSCENEFILEHANDLER_H_
40 #define _OSGSCENEFILEHANDLER_H_
50 #include <boost/function.hpp>
52 #include "OSGSystemDef.h"
53 #include "OSGBaseTypes.h"
54 #include "OSGSceneFileType.h"
55 #include "OSGPathHandler.h"
56 #include "OSGSingletonHolder.h"
62 /*! \brief Brief OSGSceneFileHandler
63 \ingroup GrpSystemFileIOBase
64 \ingroup GrpLibOSGSystem
67 class OSG_SYSTEM_DLLMAPPING SceneFileHandlerBase
69 /*========================== PUBLIC =================================*/
71 typedef NodeTransitPtr (*FileIOReadCBF
)(SceneFileType
*type
,
75 typedef bool (*FileIOWriteCBF
)(SceneFileType
* type
,
82 typedef SceneFileType::Resolver Resolver
;
86 /*---------------------------------------------------------------------*/
90 virtual SceneFileType
*getFileType(const Char8
*fileNameOrExtension
);
92 virtual int getSuffixList(std::list
<const Char8
*> &suffixList
,
94 SceneFileType::OSG_READ_SUPPORTED
|
95 SceneFileType::OSG_WRITE_SUPPORTED
));
98 /*---------------------------------------------------------------------*/
102 typedef void (*progresscbfp
) ( UInt32 p
);
103 typedef void (*filenamecbfp
) (const Char8
*fname
);
105 void setReadProgressCB (progresscbfp fp
,
106 bool use_thread
= true);
107 progresscbfp
getReadProgressCB (void );
109 void setReadBeginCB (filenamecbfp fp
);
110 filenamecbfp
getReadBeginCB (void );
112 void setReadEndCB (filenamecbfp fp
);
113 filenamecbfp
getReadEndCB (void );
115 void updateReadProgress(void );
116 void updateReadProgress(UInt32 p
);
118 void setWriteProgressCB (progresscbfp fp
);
119 progresscbfp
getWriteProgressCB (void );
121 void setWriteBeginCB (filenamecbfp fp
);
122 filenamecbfp
getWriteBeginCB (void );
124 void setWriteEndCB (filenamecbfp fp
);
125 filenamecbfp
getWriteEndCB (void );
127 void updateWriteProgress(UInt32 p
);
130 /*---------------------------------------------------------------------*/
134 virtual NodeTransitPtr
read( std::istream
&is
,
136 GraphOpSeq
*graphOpSeq
=
138 Resolver resolver
= NULL
);
140 virtual NodeTransitPtr
read(const Char8
*fileName
,
141 GraphOpSeq
*graphOpSeq
=
143 Resolver resolver
= NULL
,
144 bool bWarnNotFound
= true );
147 /*---------------------------------------------------------------------*/
148 /*! \name Read Callback */
151 void setReadCB(FileIOReadCBF fp
);
152 FileIOReadCBF
getReadCB(void );
155 /*---------------------------------------------------------------------*/
159 virtual bool write(Node
* const node
,
162 bool compress
= false);
164 virtual bool write(Node
* const node
,
165 Char8
const *fileName
,
166 bool compress
= false);
168 /*---------------------------------------------------------------------*/
169 /*! \name Write Callback */
172 void setWriteCB(FileIOWriteCBF fp
);
173 FileIOWriteCBF
getWriteCB(void );
176 /*---------------------------------------------------------------------*/
177 /*! \name PathHandler */
180 virtual PathHandler
* getPathHandler(void );
181 virtual void setPathHandler(PathHandler
*pathHandler
);
184 /*---------------------------------------------------------------------*/
185 /*! \name PathHandler */
188 Resolver
getGlobalResolver(void ) const;
189 void setGlobalResolver(Resolver oResolver
);
192 /*---------------------------------------------------------------------*/
193 /*! \name DefaultGraphOp */
196 virtual GraphOpSeq
*getDefaultGraphOp(void );
197 virtual void setDefaultGraphOp(GraphOpSeq
*graphOpSeq
);
200 /*---------------------------------------------------------------------*/
204 template <class ValueTypeT
>
205 bool setOptionAs(const std::string
&suffix
,
206 const std::string
&name
,
207 const ValueTypeT
&value
);
208 bool setOption (const std::string
&suffix
,
209 const std::string
&name
,
210 const std::string
&value
);
212 bool unsetOption(const std::string
&suffix
,
213 const std::string
&name
);
215 template <class ValueTypeT
>
216 bool getOptionAs(const std::string
&suffix
,
217 const std::string
&name
,
219 bool getOption (const std::string
&suffix
,
220 const std::string
&name
,
221 std::string
&value
);
223 void pushOptions(const std::string
&suffix
,
224 bool copyTop
= true);
225 void popOptions (const std::string
&suffix
);
227 #if defined(OSG_1_COMPAT)
228 void setOptions(const std::string
&suffix
,
229 const std::string
&osg1Options
);
233 /*---------------------------------------------------------------------*/
240 /*========================= PROTECTED ===============================*/
244 typedef std::list
< SceneFileType
*> FileTypeList
;
245 typedef std::map
<std::string
, FileTypeList
*> FileTypeMap
;
249 UInt32 uiRefPriority
;
251 bool operator() (SceneFileType
*fileTypeP
);
254 /*---------------------------------------------------------------------*/
258 FileTypeMap _suffixTypeMap
;
261 bool addSceneFileType(SceneFileType
&fileType
);
262 bool subSceneFileType(SceneFileType
&fileType
);
265 /*---------------------------------------------------------------------*/
266 /*! \name Constructors */
269 SceneFileHandlerBase(void);
272 /*---------------------------------------------------------------------*/
273 /*! \name Destructors */
276 virtual ~SceneFileHandlerBase(void);
279 /*---------------------------------------------------------------------*/
280 /*! \name Destructors */
283 static bool terminateSceneFileTypes (void);
284 bool doTerminateSceneFileTypes(void);
287 /*---------------------------------------------------------------------*/
288 /*! \name Destructors */
291 void triggerReadBegin (const Char8
*fname
);
292 void triggerReadEnd (const Char8
*fname
);
294 void triggerWriteBegin(const Char8
*fname
);
295 void triggerWriteEnd (const Char8
*fname
);
299 /*========================== PRIVATE ================================*/
303 friend class SceneFileType
;
305 template <class SingletonT
>
306 friend class SingletonHolder
;
308 std::string
initPathHandler(const Char8
*fileName
);
319 progressS(void) : thread(NULL
), length(0), is(NULL
) {}
323 progressS(const progressS
&other
);
324 void operator =(const progressS
&rhs
);
327 void initReadProgress (std::istream
&is
);
328 void terminateReadProgress(void );
329 static void readProgress (void *data
);
331 progresscbfp _readProgressFP
;
332 filenamecbfp _readBeginFP
;
333 filenamecbfp _readEndFP
;
335 progressS _progressData
;
337 bool _useProgressThread
;
339 progresscbfp _writeProgressFP
;
340 filenamecbfp _writeBeginFP
;
341 filenamecbfp _writeEndFP
;
343 PathHandler
*_pathHandler
;
344 PathHandler _defaultPathHandler
;
345 static GraphOpSeq
*_defaultgraphOpSeq
;
347 FileIOReadCBF _readFP
;
348 FileIOWriteCBF _writeFP
;
350 Resolver _oGlobalResolver
;
352 /*!\brief prohibit default function (move to 'public' if needed) */
353 void operator =(const SceneFileHandlerBase
&source
);
354 /*!\brief prohibit default function (move to 'public' if needed) */
355 SceneFileHandlerBase(const SceneFileHandlerBase
&source
);
359 OSG_SYSTEM_EXPIMP_TMPL
360 template class OSG_SYSTEM_DLLMAPPING SingletonHolder
<SceneFileHandlerBase
>;
363 /*! \typedef OSG::SingletonHolder<OSG::SceneFileHandlerBase> SceneFileHandler;
364 \ingroup GrpSystemFileIOBase
365 \relatesalso OSG::SceneFileHandlerBase
368 typedef SingletonHolder
<SceneFileHandlerBase
> SceneFileHandler
;
370 typedef SceneFileHandler
* SceneFileHandlerP
;
374 #include "OSGSceneFileHandler.inl"
376 #endif // OSGIMAGEFILEHANDLER_CLASS_DECLARATION