fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / System / FileIO / Base / OSGSceneFileHandler.h
blob06881ac505dfac0b967a0539aa9910e2fbb75451
1 /*---------------------------------------------------------------------------*\
2 * OpenSG *
3 * *
4 * *
5 * Copyright (C) 2000-2002 by the OpenSG Forum *
6 * *
7 * www.opensg.org *
8 * *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
10 * *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
13 * License *
14 * *
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. *
18 * *
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. *
23 * *
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. *
27 * *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
30 * Changes *
31 * *
32 * *
33 * *
34 * *
35 * *
36 * *
37 \*---------------------------------------------------------------------------*/
39 #ifndef _OSGSCENEFILEHANDLER_H_
40 #define _OSGSCENEFILEHANDLER_H_
41 #ifdef __sgi
42 #pragma once
43 #endif
45 #include <string>
46 #include <list>
47 #include <map>
48 #include <iostream>
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"
58 OSG_BEGIN_NAMESPACE
60 class GraphOpSeq;
62 /*! \brief Brief OSGSceneFileHandler
63 \ingroup GrpSystemFileIOBase
64 \ingroup GrpLibOSGSystem
67 class OSG_SYSTEM_DLLMAPPING SceneFileHandlerBase
69 /*========================== PUBLIC =================================*/
71 typedef NodeTransitPtr (*FileIOReadCBF )(SceneFileType *type,
72 std::istream &is,
73 Char8 const *ext );
75 typedef bool (*FileIOWriteCBF)(SceneFileType * type,
76 Node * const node,
77 std::ostream &os,
78 Char8 const *ext,
79 bool compress);
82 typedef SceneFileType::Resolver Resolver;
84 public:
86 /*---------------------------------------------------------------------*/
87 /*! \name Get */
88 /*! \{ */
90 virtual SceneFileType *getFileType(const Char8 *fileNameOrExtension);
92 virtual int getSuffixList(std::list<const Char8*> &suffixList,
93 UInt32 flags = (
94 SceneFileType::OSG_READ_SUPPORTED |
95 SceneFileType::OSG_WRITE_SUPPORTED));
97 /*! \} */
98 /*---------------------------------------------------------------------*/
99 /*! \name Progress */
100 /*! \{ */
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 );
129 /*! \} */
130 /*---------------------------------------------------------------------*/
131 /*! \name Read */
132 /*! \{ */
134 virtual NodeTransitPtr read( std::istream &is,
135 const Char8 *ext,
136 GraphOpSeq *graphOpSeq =
137 _defaultgraphOpSeq,
138 Resolver resolver = NULL);
140 virtual NodeTransitPtr read(const Char8 *fileName,
141 GraphOpSeq *graphOpSeq =
142 _defaultgraphOpSeq,
143 Resolver resolver = NULL,
144 bool bWarnNotFound = true );
146 /*! \} */
147 /*---------------------------------------------------------------------*/
148 /*! \name Read Callback */
149 /*! \{ */
151 void setReadCB(FileIOReadCBF fp);
152 FileIOReadCBF getReadCB(void );
154 /*! \} */
155 /*---------------------------------------------------------------------*/
156 /*! \name Write */
157 /*! \{ */
159 virtual bool write(Node * const node,
160 std::ostream &os,
161 Char8 const *ext,
162 bool compress = false);
164 virtual bool write(Node * const node,
165 Char8 const *fileName,
166 bool compress = false);
167 /*! \} */
168 /*---------------------------------------------------------------------*/
169 /*! \name Write Callback */
170 /*! \{ */
172 void setWriteCB(FileIOWriteCBF fp);
173 FileIOWriteCBF getWriteCB(void );
175 /*! \} */
176 /*---------------------------------------------------------------------*/
177 /*! \name PathHandler */
178 /*! \{ */
180 virtual PathHandler* getPathHandler(void );
181 virtual void setPathHandler(PathHandler *pathHandler);
183 /*! \} */
184 /*---------------------------------------------------------------------*/
185 /*! \name PathHandler */
186 /*! \{ */
188 Resolver getGlobalResolver(void ) const;
189 void setGlobalResolver(Resolver oResolver);
191 /*! \} */
192 /*---------------------------------------------------------------------*/
193 /*! \name DefaultGraphOp */
194 /*! \{ */
196 virtual GraphOpSeq *getDefaultGraphOp(void );
197 virtual void setDefaultGraphOp(GraphOpSeq *graphOpSeq);
199 /*! \} */
200 /*---------------------------------------------------------------------*/
201 /*! \name Options */
202 /*! \{ */
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,
218 ValueTypeT &value );
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);
230 #endif
232 /*! \} */
233 /*---------------------------------------------------------------------*/
234 /*! \name Debug */
235 /*! \{ */
237 void print (void);
239 /*! \} */
240 /*========================= PROTECTED ===============================*/
242 protected:
244 typedef std::list< SceneFileType *> FileTypeList;
245 typedef std::map <std::string, FileTypeList *> FileTypeMap;
247 struct FindOverride
249 UInt32 uiRefPriority;
251 bool operator() (SceneFileType *fileTypeP);
254 /*---------------------------------------------------------------------*/
255 /*! \name Member */
256 /*! \{ */
258 FileTypeMap _suffixTypeMap;
261 bool addSceneFileType(SceneFileType &fileType);
262 bool subSceneFileType(SceneFileType &fileType);
264 /*! \} */
265 /*---------------------------------------------------------------------*/
266 /*! \name Constructors */
267 /*! \{ */
269 SceneFileHandlerBase(void);
271 /*! \} */
272 /*---------------------------------------------------------------------*/
273 /*! \name Destructors */
274 /*! \{ */
276 virtual ~SceneFileHandlerBase(void);
278 /*! \} */
279 /*---------------------------------------------------------------------*/
280 /*! \name Destructors */
281 /*! \{ */
283 static bool terminateSceneFileTypes (void);
284 bool doTerminateSceneFileTypes(void);
286 /*! \} */
287 /*---------------------------------------------------------------------*/
288 /*! \name Destructors */
289 /*! \{ */
291 void triggerReadBegin (const Char8 *fname);
292 void triggerReadEnd (const Char8 *fname);
294 void triggerWriteBegin(const Char8 *fname);
295 void triggerWriteEnd (const Char8 *fname);
298 /*! \} */
299 /*========================== PRIVATE ================================*/
301 private:
303 friend class SceneFileType;
305 template <class SingletonT>
306 friend class SingletonHolder;
308 std::string initPathHandler(const Char8 *fileName);
310 /*! \nohierarchy
313 struct progressS
315 ThreadRefPtr thread;
316 UInt64 length;
317 std::istream *is;
319 progressS(void) : thread(NULL), length(0), is(NULL) {}
321 private:
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;
336 bool _readReady;
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);
358 #if defined(WIN32)
359 OSG_SYSTEM_EXPIMP_TMPL
360 template class OSG_SYSTEM_DLLMAPPING SingletonHolder<SceneFileHandlerBase>;
361 #endif
363 /*! \typedef OSG::SingletonHolder<OSG::SceneFileHandlerBase> SceneFileHandler;
364 \ingroup GrpSystemFileIOBase
365 \relatesalso OSG::SceneFileHandlerBase
368 typedef SingletonHolder<SceneFileHandlerBase> SceneFileHandler;
370 typedef SceneFileHandler* SceneFileHandlerP;
372 OSG_END_NAMESPACE
374 #include "OSGSceneFileHandler.inl"
376 #endif // OSGIMAGEFILEHANDLER_CLASS_DECLARATION