fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / System / FileIO / Base / OSGSceneFileHandler.cpp
blobef8ed0eb47e93aafcc95871072d9bd1d7e840c29
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 //-------------------------------
40 // Includes
41 //-------------------------------
43 #define OSG_COMPILE_SCENEFILEHANDLER
45 #include <cstdlib>
46 #include <cstdio>
48 #include <fstream>
50 #include "OSGConfig.h"
52 #include "OSGLog.h"
53 #include "OSGBaseTypes.h"
54 #include "OSGPathHandler.h"
56 #include "OSGGraphOpSeq.h"
58 #include "OSGImageFileHandler.h"
60 #include "OSGSceneFileHandler.h"
61 #include "OSGZStream.h"
63 #include "OSGNode.h"
64 #include "OSGThread.h"
65 #include "OSGThreadManager.h"
66 #include "OSGBaseFunctions.h"
67 #include "OSGFileContextAttachment.h"
69 #include "OSGSingletonHolder.ins"
71 OSG_BEGIN_NAMESPACE
73 OSG_SINGLETON_INST(SceneFileHandlerBase, addPostFactoryExitFunction)
75 template class SingletonHolder<SceneFileHandlerBase>;
77 GraphOpSeq *SceneFileHandlerBase::_defaultgraphOpSeq = NULL;
79 SceneFileType *SceneFileHandlerBase::getFileType(
80 const Char8 *fileNameOrExtension)
82 const Char8 separator = '.';
84 if(fileNameOrExtension == NULL)
85 return NULL;
87 std::string fe = fileNameOrExtension;
89 SizeT p = fe.rfind(separator);
91 std::string ext;
93 if(p != std::string::npos)
95 ext = fe.substr(p + 1, fe.length() - p - 1);
97 else
99 ext = fe; // extension without '.'
102 // skip .gz extension
103 if(ext == "gz")
105 fe = fe.substr(0, p);
106 p = fe.rfind(separator);
108 if(p != std::string::npos)
110 ext = fe.substr(p + 1, fe.length() - p - 1);
112 else
114 ext = fe;
118 std::string suffix;
120 suffix.assign (ext.c_str());
121 // suffix.toLower( );
122 std::transform(suffix.begin(), suffix.end(), suffix.begin(), ::tolower);
124 FileTypeMap::iterator sI = _suffixTypeMap.find(suffix);
126 SceneFileType *type =
127 (sI == _suffixTypeMap.end()) ? 0 : sI->second->front();
129 return type;
132 //CHECK
133 #ifdef OSG_WIN32_ICL
134 #pragma warning (disable : 383)
135 #endif
137 Int32 SceneFileHandlerBase::getSuffixList(std::list<const Char8 *> &suffixList,
138 UInt32 flags)
140 Int32 count = 0;
141 FileTypeMap::iterator sI;
143 suffixList.clear();
145 for(sI = _suffixTypeMap.begin(); sI != _suffixTypeMap.end(); ++sI)
147 SceneFileType *type = sI->second->front();
149 if((type->getFlags() & flags) == flags)
151 suffixList.push_back(sI->first.c_str());
152 count++;
156 return count;
159 #ifdef OSG_WIN32_ICL
160 #pragma warning (default : 383)
161 #endif
164 NodeTransitPtr SceneFileHandlerBase::read(
165 std::istream &is,
166 const Char8 *fileNameOrExtension,
167 GraphOpSeq *graphOpSeq ,
168 Resolver resolver )
170 SceneFileType *type = getFileType(fileNameOrExtension);
171 NodeUnrecPtr scene = NULL;
173 if(!fileNameOrExtension)
175 SWARNING << "cannot read NULL extension" << std::endl;
176 return NodeTransitPtr(scene);
179 if(type != NULL)
181 SINFO << "try to read stream as " << type->getName() << std::endl;
183 // check for fileio read callback
184 if(_readFP != NULL)
186 initReadProgress(is);
187 scene = _readFP(type, is, fileNameOrExtension);
188 terminateReadProgress();
190 else
192 if(isGZip(is))
194 SINFO << "Detected gzip compressed stream." << std::endl;
196 #ifdef OSG_WITH_ZLIB
198 initReadProgress(is);
200 zip_istream unzipper(is);
202 scene = type->read(unzipper,
203 fileNameOrExtension,
204 resolver ? resolver : _oGlobalResolver);
206 if(scene != NULL)
208 if(unzipper.check_crc() == true)
210 SINFO << "Compressed stream has correct checksum."
211 << std::endl;
213 else
215 SWARNING << "Compressed stream has wrong checksum."
216 << std::endl;
219 terminateReadProgress();
220 #else
221 SFATAL << "Compressed streams are not supported! Configure "
222 << "with --enable-png --with-png=DIR options."
223 << std::endl;
224 #endif
226 else
228 initReadProgress(is);
230 scene = type->read(is,
231 fileNameOrExtension,
232 resolver ? resolver : _oGlobalResolver);
234 terminateReadProgress();
238 if(scene != NULL)
240 if(graphOpSeq != NULL)
241 graphOpSeq->traverse(scene);
243 SINFO << "read ok:" << std::endl;
245 else
247 SWARNING << "could not read " << std::endl;
250 else
252 SWARNING << "could not read unknown file format" << std::endl;
255 commitChanges();
257 return NodeTransitPtr(scene);
261 NodeTransitPtr SceneFileHandlerBase::read(const Char8 *fileName,
262 GraphOpSeq *graphOpSeq,
263 Resolver resolver,
264 bool bWarnNotFound )
266 NodeTransitPtr returnValue(NULL);
268 if(fileName == NULL)
270 SWARNING << "cannot read NULL file" << std::endl;
271 return NodeTransitPtr(NULL);
274 std::string fullFilePath = initPathHandler(fileName);
276 if(fullFilePath.empty() == true)
278 if(_readFP != NULL)
280 // that's a fallback could be a url so the callback
281 // can handle this correctly.
282 SceneFileType *type = getFileType(fileName);
283 if(type != NULL)
285 // create a dummy stream with the bad flag set.
286 std::ifstream in;
287 in.setstate(std::ios::badbit);
288 returnValue = _readFP(type, in, fileName);
290 else
292 if(bWarnNotFound == true)
293 SWARNING << "Couldn't open file " << fileName << std::endl;
296 else
298 if(bWarnNotFound == true)
299 SWARNING << "Couldn't open file " << fileName << std::endl;
302 commitChanges();
304 return returnValue;
308 SceneFileType *type = getFileType(fullFilePath.c_str());
309 NodeUnrecPtr scene = NULL;
311 if(type != NULL)
313 triggerReadBegin(fullFilePath.c_str());
314 updateReadProgress(0);
316 SINFO << "try to read " << fullFilePath
317 << " as " << type->getName() << std::endl;
319 std::ifstream in(fullFilePath.c_str(), std::ios::binary);
321 if(in)
323 scene = read(in, fullFilePath.c_str(), graphOpSeq);
325 in.close();
327 if(scene != NULL)
329 triggerReadEnd(fullFilePath.c_str());
331 FileContextAttachmentUnrecPtr pFContext =
332 dynamic_cast<FileContextAttachment *>(
333 scene->findAttachment(
334 FileContextAttachment::getClassGroupId()));
336 if(pFContext == NULL)
338 pFContext = FileContextAttachment::create();
340 pFContext->setResolvedName(fullFilePath);
342 scene->addAttachment(pFContext);
346 else
348 if(bWarnNotFound == true)
350 SWARNING << "Couldn't open input stream for file "
351 << fullFilePath
352 << std::endl;
356 #ifndef OSG_DISABLE_DEPRECATED
358 // Ok stream interface didn't work try via filename
359 if(scene == NULL)
360 scene = type->readFile(fullFilePath.c_str());
362 if(scene != NULL)
364 if(graphOpSeq != NULL)
365 graphOpSeq->run(scene);
367 SINFO << "read ok:" << std::endl;
369 else
371 if(bWarnNotFound == true)
372 SWARNING << "could not read " << std::endl;
374 #endif
376 #if 0
377 if(scene != NULL && graphOpSeq != NULL)
379 SINFO << "Running GraphOps..." << std::endl;
380 graphOpSeq->run(scene);
382 #endif
384 else
386 if(bWarnNotFound == true)
388 SWARNING << "could not read " << fullFilePath
389 << "; unknown file format" << std::endl;
393 commitChanges();
395 return NodeTransitPtr(scene);
399 void SceneFileHandlerBase::setReadCB(FileIOReadCBF fp)
401 _readFP = fp;
404 SceneFileHandlerBase::FileIOReadCBF SceneFileHandlerBase::getReadCB(void)
406 return _readFP;
409 bool SceneFileHandlerBase::write(Node * const node,
410 std::ostream &os,
411 Char8 const *fileNameOrExtension,
412 bool compress )
414 bool retCode = false;
415 SceneFileType *type = getFileType(fileNameOrExtension);
417 if(type != NULL)
419 updateWriteProgress(0);
421 SINFO << "try to write stream as " << type->getName() << std::endl;
423 if(_writeFP != NULL)
425 retCode = _writeFP(type, node, os, fileNameOrExtension, compress);
427 else
429 if(compress == true)
431 #ifdef OSG_WITH_ZLIB
432 SINFO << "writing compressed stream." << std::endl;
434 zip_ostream zipper(os, true);
436 retCode = type->write(node, zipper, fileNameOrExtension);
438 zipper.zflush();
439 #else
440 SFATAL << "Compressed streams are not supported! Build "
441 << "with zlib= options."
442 << std::endl;
443 #endif
445 else
447 retCode = type->write(node, os, fileNameOrExtension);
451 else
453 SWARNING << "can't write stream unknown scene format" << std::endl;
456 return retCode;
459 bool SceneFileHandlerBase::write(Node * const node,
460 Char8 const *fileName,
461 bool compress)
463 bool retCode = false;
464 SceneFileType *type = getFileType(fileName);
466 if(type != NULL)
468 updateWriteProgress(0);
469 triggerWriteBegin(fileName);
471 SINFO << "try to write "
472 << fileName
473 << " as "
474 << type->getName()
475 << std::endl;
477 std::ofstream out(fileName, std::ios::binary);
479 if(out)
481 retCode = write(node, out, fileName, compress);
482 out.close();
484 else
486 SWARNING << "Can not open output stream for file '"
487 << fileName
488 << "'!"
489 << std::endl;
492 #ifndef OSG_DISABLE_DEPRECATED
493 if(!retCode)
495 retCode = type->writeFile(node, fileName);
497 #endif
499 if(!retCode)
501 SWARNING << "Couldn't write " << fileName << std::endl;
503 else
505 triggerWriteEnd(fileName);
508 else
509 SWARNING << "can't write "
510 << fileName
511 << "; unknown scene format"
512 << std::endl;
514 return retCode;
517 void SceneFileHandlerBase::setWriteCB(FileIOWriteCBF fp)
519 _writeFP = fp;
522 SceneFileHandlerBase::FileIOWriteCBF SceneFileHandlerBase::getWriteCB(void)
524 return _writeFP;
527 PathHandler *SceneFileHandlerBase::getPathHandler(void)
529 if(_pathHandler == NULL)
531 return &_defaultPathHandler;
533 else
535 return _pathHandler;
539 void SceneFileHandlerBase::setPathHandler(PathHandler *pathHandler)
541 _pathHandler = pathHandler;
544 SceneFileHandlerBase::Resolver
545 SceneFileHandlerBase::getGlobalResolver(void) const
547 return _oGlobalResolver;
550 void SceneFileHandlerBase::setGlobalResolver(Resolver oResolver)
552 _oGlobalResolver = oResolver;
555 std::string SceneFileHandlerBase::initPathHandler(const Char8 *fileName)
557 std::string fullFilePath;
559 if(_pathHandler != NULL)
561 // Set also a image path handler if not set.
563 if(ImageFileHandler::the()->getPathHandler() == NULL)
565 ImageFileHandler::the()->setPathHandler(_pathHandler);
568 fullFilePath = _pathHandler->findFile(fileName);
570 else
572 // Set a default image path handler if not set.
573 if(ImageFileHandler::the()->getPathHandler() == NULL)
575 ImageFileHandler::the()->setPathHandler(&_defaultPathHandler);
578 _defaultPathHandler.clearPathList();
579 _defaultPathHandler.clearBaseFile();
581 _defaultPathHandler.push_frontCurrentDir( );
583 fullFilePath = _defaultPathHandler.findFile(fileName);
585 _defaultPathHandler.setBaseFile(fullFilePath.c_str());
588 return fullFilePath;
591 GraphOpSeq *SceneFileHandlerBase::getDefaultGraphOp(void)
593 return _defaultgraphOpSeq;
596 void SceneFileHandlerBase::setDefaultGraphOp(GraphOpSeq *graphOpSeq)
598 setRefd(_defaultgraphOpSeq, graphOpSeq);
601 /*-------------------------------------------------------------------------*/
602 /* Options */
604 /*! Sets the option \a name to \a value for the SceneFileType that handles
605 files with the given \a suffix.
606 Returns \c true if the option was set successfully, \c false otherwise.
608 \param[in] suffix File extension to choose the scene file type
609 this option applies to.
610 \param[in] name Name of the option.
611 \param[in] value Value of the option.
612 \return Whether the value was set successfully.
614 bool
615 SceneFileHandlerBase::setOption(
616 const std::string &suffix,
617 const std::string &name,
618 const std::string &value )
620 bool retVal = false;
621 SceneFileType *type = getFileType(suffix.c_str());
623 if(type != NULL)
625 type->setOption(name, value);
626 retVal = true;
629 return retVal;
632 /*! Removes the option \a name from the ImageFileType that handles files
633 with the given \a suffix. If the option is not present \c false is
634 returned, \c true otherwise.
636 \param[in] suffix File extension to choose the scene file type
637 this option applies to.
638 \param[in] name Name of the option.
639 \return Whether the option was successfully removed.
641 bool
642 SceneFileHandlerBase::unsetOption(
643 const std::string &suffix,
644 const std::string &name )
646 bool retVal = false;
647 SceneFileType *type = getFileType(suffix.c_str());
649 if(type != NULL)
651 retVal = type->unsetOption(name);
654 return retVal;
657 /*! Retrieves the option \a name from the SceneFileType that handles files
658 with the given \a suffix and stores its value in \a value.
659 Returns \c true if successful, \c false otherwise in which case \a value has
660 an undefined value.
662 \param[in] suffix File extension to choose the scene file type
663 this option applies to.
664 \param[in] name Name of the option.
665 \param[out] value Value the option.
666 \return Whether the option is present for the given SceneFileType.
668 bool
669 SceneFileHandlerBase::getOption(
670 const std::string &suffix,
671 const std::string &name,
672 std::string &value )
674 bool retVal = false;
675 SceneFileType *type = getFileType(suffix.c_str());
677 if(type != NULL)
679 retVal = type->getOption(name, value);
682 return retVal;
685 void SceneFileHandlerBase::pushOptions(const std::string &suffix,
686 bool copyTop)
688 SceneFileType *type = getFileType(suffix.c_str());
690 if(type != NULL)
692 type->pushOptions(copyTop);
696 void SceneFileHandlerBase::popOptions(const std::string &suffix)
698 SceneFileType *type = getFileType(suffix.c_str());
700 if(type != NULL)
702 type->popOptions();
706 #if defined(OSG_1_COMPAT)
707 void SceneFileHandlerBase::setOptions(const std::string &suffix,
708 const std::string &osg1Options)
711 #endif
713 void SceneFileHandlerBase::print (void )
715 FileTypeMap::iterator sI;
717 for(sI = _suffixTypeMap.begin(); sI != _suffixTypeMap.end(); sI++)
719 std::string rw;
720 SceneFileType *type = sI->second->front();
722 if((type->getFlags() & SceneFileType::OSG_READ_SUPPORTED) &&
723 (type->getFlags() & SceneFileType::OSG_WRITE_SUPPORTED))
725 rw = "reader and writer";
727 else
729 if(type->getFlags() & SceneFileType::OSG_READ_SUPPORTED)
730 rw = "reader";
732 if(type->getFlags() & SceneFileType::OSG_WRITE_SUPPORTED)
733 rw = "writer";
736 std::cerr << "suffix: " << sI->first.c_str()
737 << ", type: " << sI->second->front()->getName()
738 << " " << rw
739 << std::endl;
743 bool SceneFileHandlerBase::FindOverride::operator() (SceneFileType *fileTypeP)
745 if(fileTypeP == NULL)
746 return false;
748 if(fileTypeP->doOverride() == false)
749 return true;
751 if(fileTypeP->getOverridePriority() <= uiRefPriority)
752 return true;
754 return false;
757 //CHECK
758 #ifdef OSG_WIN32_ICL
759 #pragma warning (disable : 383)
760 #endif
762 bool SceneFileHandlerBase::addSceneFileType(SceneFileType &fileType)
764 bool retCode = false;
766 std::list<std::string>::iterator sI;
767 FileTypeMap ::iterator smI;
769 std::string suffix;
771 for( sI = fileType.suffixList().begin();
772 sI != fileType.suffixList().end();
773 ++sI)
775 suffix.assign (sI->c_str());
776 // suffix.toLower();
777 std::transform(suffix.begin(), suffix.end(), suffix.begin(), ::tolower);
779 smI = _suffixTypeMap.find(suffix);
781 if (smI != _suffixTypeMap.end())
783 if(fileType.doOverride() == true)
785 FindOverride overrideFinder;
786 FileTypeList::iterator lIt;
788 overrideFinder.uiRefPriority = fileType.getOverridePriority();
790 lIt = std::find_if(_suffixTypeMap[suffix]->begin(),
791 _suffixTypeMap[suffix]->end (),
792 overrideFinder);
794 _suffixTypeMap[suffix]->insert(lIt, &fileType);
796 SWARNING << "Added an file type with suffix "
797 << suffix
798 << " overriding "
799 << std::endl;
801 else
803 _suffixTypeMap[suffix]->push_back(&fileType);
805 SWARNING << "Added an file type with suffix "
806 << suffix
807 << " non overriding at the end of the list"
808 << std::endl;
811 else
813 FileTypeList *pTmpList = new FileTypeList;
815 pTmpList->push_back(&fileType);
817 _suffixTypeMap[suffix] = pTmpList;
819 retCode = true;
823 return retCode;
826 bool SceneFileHandlerBase::subSceneFileType(SceneFileType &fileType)
828 bool retCode = false;
830 std::list<std::string>::iterator sI;
831 FileTypeMap ::iterator smI;
833 std::string suffix;
835 for( sI = fileType.suffixList().begin();
836 sI != fileType.suffixList().end();
837 ++sI)
839 suffix.assign(sI->c_str());
840 //suffix.toLower();
841 std::transform(suffix.begin(), suffix.end(), suffix.begin(), ::tolower);
842 smI = _suffixTypeMap.find(suffix);
844 if (smI != _suffixTypeMap.end())
846 _suffixTypeMap.erase(smI);
847 retCode = true;
850 return retCode;
853 #ifdef OSG_WIN32_ICL
854 #pragma warning (default : 383)
855 #endif
858 static bool initializeDefaultGraphOps(void)
860 GraphOpSeqRefPtr ops = GraphOpSeq::create();
862 ops->setGraphOps(
863 "Stripe() SharePtr(includes=Material,StateChunk)");
865 SceneFileHandlerBase *the = SceneFileHandler::the();
867 the->setDefaultGraphOp(ops);
869 return true;
872 static bool terminateDefaultGraphOps(void)
874 SceneFileHandlerBase *the = SceneFileHandler::the();
876 the->setDefaultGraphOp(NULL);
878 return true;
881 SceneFileHandlerBase::SceneFileHandlerBase(void) :
882 _suffixTypeMap ( ),
883 _readProgressFP (NULL ),
884 _readBeginFP (NULL ),
885 _readEndFP (NULL ),
886 _progressData ( ),
887 _readReady (false ),
888 _useProgressThread (false ),
889 _writeProgressFP (NULL ),
890 _writeBeginFP (NULL ),
891 _writeEndFP (NULL ),
892 _pathHandler (NULL ),
893 _defaultPathHandler( ),
894 _readFP (NULL ),
895 _writeFP (NULL ),
896 _oGlobalResolver (NULL )
898 _progressData.length = 0;
899 _progressData.is = NULL;
901 addPostFactoryInitFunction(initializeDefaultGraphOps);
902 addPreFactoryExitFunction (terminateDefaultGraphOps );
903 addPreFactoryExitFunction (terminateSceneFileTypes );
906 // read progress stuff.
908 void SceneFileHandlerBase::setReadProgressCB(progresscbfp fp, bool use_thread)
910 if(use_thread)
912 terminateReadProgress();
914 else
916 //check if setReadProgressCB was called before with use_thread enabled.
918 if(_useProgressThread)
919 terminateReadProgress();
922 _readProgressFP = fp;
923 _useProgressThread = use_thread;
926 SceneFileHandlerBase::progresscbfp
927 SceneFileHandlerBase::getReadProgressCB(void)
929 return _readProgressFP;
932 void SceneFileHandlerBase::setReadBeginCB(filenamecbfp fp)
934 _readBeginFP = fp;
937 SceneFileHandlerBase::filenamecbfp SceneFileHandlerBase::getReadBeginCB(void)
939 return _readBeginFP;
942 void SceneFileHandlerBase::setReadEndCB(filenamecbfp fp)
944 _readEndFP = fp;
947 SceneFileHandlerBase::filenamecbfp SceneFileHandlerBase::getReadEndCB(void)
949 return _readEndFP;
952 void SceneFileHandlerBase::triggerReadBegin(const Char8 *fname)
954 if(_readBeginFP != NULL)
955 _readBeginFP(fname);
958 void SceneFileHandlerBase::triggerReadEnd(const Char8 *fname)
960 if(_readEndFP != NULL)
961 _readEndFP(fname);
964 void SceneFileHandlerBase::initReadProgress(std::istream &is)
966 if(_readProgressFP == NULL)
967 return;
969 // get length of the stream.
970 _progressData.is = &is;
971 is.seekg(0, std::ios::end);
972 _progressData.length = is.tellg();
973 is.seekg(0, std::ios::beg);
975 _readReady = false;
977 if(_useProgressThread)
979 _progressData.thread = Thread::find("OSG::FileIOReadProgressThread");
981 if(_progressData.thread == NULL)
983 _progressData.thread =
984 OSG::Thread::get("OSG::FileIOReadProgressThread", true);
987 if(_progressData.thread != NULL)
989 _progressData.thread->runFunction(readProgress, 0, NULL);
991 else
993 SWARNING << "Couldn't create read progress thread!" << std::endl;
998 void SceneFileHandlerBase::terminateReadProgress(void)
1000 if(_readProgressFP == NULL)
1001 return;
1003 _readReady = true;
1005 if(_progressData.thread != NULL)
1007 // terminate thread
1008 Thread::join(_progressData.thread);
1009 _progressData.thread = NULL;
1012 _progressData.length = 0;
1013 _progressData.is = NULL;
1016 void SceneFileHandlerBase::readProgress(void * OSG_CHECK_ARG(data))
1018 SceneFileHandlerBase *the = SceneFileHandler::the();
1020 if(the->_readProgressFP == NULL || the->_progressData.is == NULL)
1021 return;
1023 UInt32 p = 0;
1025 while(p < 100 && !the->_readReady)
1027 if(!the->_progressData.is->eof() &&
1028 !the->_progressData.is->bad())
1030 UInt64 pos = the->_progressData.is->tellg();
1031 p = UInt32((pos * 100) / the->_progressData.length);
1032 if(p > 100)
1033 p = 100;
1035 else
1037 p = 100;
1040 the->_readProgressFP(p);
1042 if(the->_useProgressThread)
1044 osgSleep(100);
1046 else
1048 break;
1052 if(the->_useProgressThread && p < 100)
1054 the->_readProgressFP(100);
1058 void SceneFileHandlerBase::updateReadProgress(void)
1060 if(_readProgressFP == NULL)
1061 return;
1063 if(_useProgressThread)
1064 return;
1066 readProgress(NULL);
1069 void SceneFileHandlerBase::updateReadProgress(UInt32 p)
1071 if(_readProgressFP == NULL)
1072 return;
1074 _readProgressFP(p);
1077 // write progress stuff.
1079 void SceneFileHandlerBase::setWriteProgressCB(progresscbfp fp)
1081 _writeProgressFP = fp;
1084 SceneFileHandlerBase::progresscbfp
1085 SceneFileHandlerBase::getWriteProgressCB(void)
1087 return _writeProgressFP;
1090 void SceneFileHandlerBase::setWriteBeginCB(filenamecbfp fp)
1092 _writeBeginFP = fp;
1095 SceneFileHandlerBase::filenamecbfp SceneFileHandlerBase::getWriteBeginCB(void)
1097 return _writeBeginFP;
1100 void SceneFileHandlerBase::setWriteEndCB(filenamecbfp fp)
1102 _writeEndFP = fp;
1105 SceneFileHandlerBase::filenamecbfp SceneFileHandlerBase::getWriteEndCB(void)
1107 return _writeEndFP;
1110 void SceneFileHandlerBase::triggerWriteBegin(const Char8 *fname)
1112 if(_writeBeginFP != NULL)
1113 _writeBeginFP(fname);
1116 void SceneFileHandlerBase::triggerWriteEnd(const Char8 *fname)
1118 if(_writeEndFP != NULL)
1119 _writeEndFP(fname);
1122 void SceneFileHandlerBase::updateWriteProgress(UInt32 p)
1124 if(_writeProgressFP == NULL)
1125 return;
1127 _writeProgressFP(p);
1130 SceneFileHandlerBase::~SceneFileHandlerBase(void)
1132 FileTypeMap::iterator smIt = _suffixTypeMap.begin();
1133 FileTypeMap::iterator smEnd = _suffixTypeMap.end ();
1135 while(smIt != smEnd)
1137 delete (*smIt).second;
1138 ++smIt;
1141 _suffixTypeMap.clear();
1144 bool SceneFileHandlerBase::doTerminateSceneFileTypes(void)
1146 FileTypeMap ::iterator sI;
1147 FileTypeList::iterator lI;
1149 for(sI = _suffixTypeMap.begin(); sI != _suffixTypeMap.end(); ++sI)
1151 for(lI = sI->second->begin(); lI != sI->second->end(); ++lI)
1153 (*lI)->terminate();
1157 return true;
1160 bool SceneFileHandlerBase::terminateSceneFileTypes(void)
1162 return SceneFileHandler::the()->doTerminateSceneFileTypes();
1166 OSG_END_NAMESPACE