Changeset 13041 for OpenSceneGraph/trunk/src/osgDB/Registry.cpp
- Timestamp:
- 03/21/12 18:36:20 (15 months ago)
- Files:
-
- 1 modified
-
OpenSceneGraph/trunk/src/osgDB/Registry.cpp (modified) (41 diffs)
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/src/osgDB/Registry.cpp
r13000 r13041 1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield 1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield 2 2 * 3 * This library is open source and may be redistributed and/or modified under 4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 3 * This library is open source and may be redistributed and/or modified under 4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 5 5 * (at your option) any later version. The full license is in LICENSE file 6 6 * included with this distribution, and on the openscenegraph.org website. 7 * 7 * 8 8 * This library is distributed in the hope that it will be useful, 9 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 11 * OpenSceneGraph Public License for more details. 12 12 */ … … 79 79 ReaderWriter& operator * () { return *get(); } 80 80 ReaderWriter* operator -> () { return get(); } 81 81 82 82 bool valid() { return get()!=0; } 83 84 void operator ++() 83 84 void operator ++() 85 85 { 86 86 _rwUsed.insert(get()); 87 87 } 88 88 89 89 90 90 protected: … … 94 94 Registry::ReaderWriterList& _rwList; 95 95 OpenThreads::ReentrantMutex& _pluginMutex; 96 96 97 97 std::set<ReaderWriter*> _rwUsed; 98 98 99 ReaderWriter* get() 99 ReaderWriter* get() 100 100 { 101 101 OpenThreads::ScopedLock<OpenThreads::ReentrantMutex> lock(_pluginMutex); … … 207 207 { 208 208 static ref_ptr<Registry> s_registry = new Registry; 209 if (erase) 210 { 209 if (erase) 210 { 211 211 s_registry->destruct(); 212 212 s_registry = 0; … … 224 224 _buildKdTreesHint = Options::NO_PREFERENCE; 225 225 _kdTreeBuilder = new osg::KdTreeBuilder; 226 226 227 227 const char* kdtree_str = getenv("OSG_BUILD_KDTREES"); 228 228 if (kdtree_str) … … 245 245 if (fileCachePath) 246 246 { 247 _fileCache = new FileCache(fileCachePath); 247 _fileCache = new FileCache(fileCachePath); 248 248 } 249 249 … … 254 254 _archiveExtList.push_back("osga"); 255 255 _archiveExtList.push_back("zip"); 256 256 257 257 initFilePathLists(); 258 258 … … 292 292 addFileExtensionAlias("ivz", "gz"); 293 293 addFileExtensionAlias("ozg", "gz"); 294 294 295 295 addFileExtensionAlias("mag", "dicom"); 296 296 addFileExtensionAlias("ph", "dicom"); … … 397 397 398 398 #if defined(USE_VRML) 399 addFileExtensionAlias("wrl", "vrml"); 399 addFileExtensionAlias("wrl", "vrml"); 400 400 #elif defined(USE_INVENTOR) 401 401 addFileExtensionAlias("wrl", "iv"); 402 402 #endif 403 403 404 404 // add alias for the text/freetype plugin. 405 405 addFileExtensionAlias("ttf", "freetype"); // true type … … 421 421 addFileExtensionAlias("pgm", "pnm"); 422 422 addFileExtensionAlias("ppm", "pnm"); 423 423 424 424 425 425 // add revision file mappings … … 439 439 addMimeTypeExtensionMapping( mimeType, builtinMimeTypeExtMappings[i+1] ); 440 440 } 441 441 442 442 // register server protocols, so the curl can handle it, if necessary 443 443 registerProtocol("http"); … … 460 460 // OSG_NOTICE<<"Registry::destruct()"<<std::endl; 461 461 462 // clean up the SharedStateManager 462 // clean up the SharedStateManager 463 463 _sharedStateManager = 0; 464 464 465 465 466 466 // clean up the FileCache 467 467 _fileCache = 0; 468 468 469 469 470 470 // object cache clear needed here to prevent crash in unref() of … … 476 476 clearObjectCache(); 477 477 clearArchiveCache(); 478 478 479 479 480 480 // unload all the plugin before we finally destruct. … … 491 491 // 492 492 char *ptr; 493 493 494 494 if( (ptr = getenv( "OSG_FILE_PATH" )) ) 495 495 { … … 505 505 osgDB::appendPlatformSpecificResourceFilePaths(filepath); 506 506 setDataFilePathList(filepath); 507 507 508 508 } 509 509 510 510 void Registry::setDataFilePathList(const std::string& paths) 511 511 { 512 _dataFilePath.clear(); 512 _dataFilePath.clear(); 513 513 convertStringPathIntoFilePathList(paths,_dataFilePath); 514 514 } … … 534 534 setLibraryFilePathList(ptr); 535 535 } 536 536 537 537 appendPlatformSpecificLibraryFilePaths(_libraryFilePath); 538 538 … … 555 555 loadLibrary(value); 556 556 } 557 557 558 558 while(arguments.read("-e",value)) 559 559 { … … 851 851 if((*itr)->acceptsExtension(ext)) return (*itr).get(); 852 852 } 853 853 854 854 // now look for a plug-in to load the file. 855 855 std::string libraryName = createLibraryNameForExtension(ext); … … 881 881 882 882 #if 0 883 struct concrete_wrapper: basic_type_wrapper 883 struct concrete_wrapper: basic_type_wrapper 884 884 { 885 885 virtual ~concrete_wrapper() {} … … 899 899 ReadObjectFunctor(const std::string& filename, const Options* options):ReadFunctor(filename,options) {} 900 900 901 virtual ReaderWriter::ReadResult doRead(ReaderWriter& rw) const { return rw.readObject(_filename, _options); } 901 virtual ReaderWriter::ReadResult doRead(ReaderWriter& rw) const { return rw.readObject(_filename, _options); } 902 902 virtual bool isValid(ReaderWriter::ReadResult& readResult) const { return readResult.validObject(); } 903 903 virtual bool isValid(osg::Object* object) const { return object!=0; } … … 910 910 ReadImageFunctor(const std::string& filename, const Options* options):ReadFunctor(filename,options) {} 911 911 912 virtual ReaderWriter::ReadResult doRead(ReaderWriter& rw)const { return rw.readImage(_filename, _options); } 912 virtual ReaderWriter::ReadResult doRead(ReaderWriter& rw)const { return rw.readImage(_filename, _options); } 913 913 virtual bool isValid(ReaderWriter::ReadResult& readResult) const { return readResult.validImage(); } 914 914 virtual bool isValid(osg::Object* object) const { return dynamic_cast<osg::Image*>(object)!=0; } … … 921 921 ReadHeightFieldFunctor(const std::string& filename, const Options* options):ReadFunctor(filename,options) {} 922 922 923 virtual ReaderWriter::ReadResult doRead(ReaderWriter& rw) const { return rw.readHeightField(_filename, _options); } 923 virtual ReaderWriter::ReadResult doRead(ReaderWriter& rw) const { return rw.readHeightField(_filename, _options); } 924 924 virtual bool isValid(ReaderWriter::ReadResult& readResult) const { return readResult.validHeightField(); } 925 925 virtual bool isValid(osg::Object* object) const { return dynamic_cast<osg::HeightField*>(object)!=0; } … … 932 932 ReadNodeFunctor(const std::string& filename, const Options* options):ReadFunctor(filename,options) {} 933 933 934 virtual ReaderWriter::ReadResult doRead(ReaderWriter& rw) const { return rw.readNode(_filename, _options); } 934 virtual ReaderWriter::ReadResult doRead(ReaderWriter& rw) const { return rw.readNode(_filename, _options); } 935 935 virtual bool isValid(ReaderWriter::ReadResult& readResult) const { return readResult.validNode(); } 936 936 virtual bool isValid(osg::Object* object) const { return dynamic_cast<osg::Node*>(object)!=0; } … … 945 945 _status(status), 946 946 _indexBlockSizeHint(indexBlockSizeHint) {} 947 947 948 948 ReaderWriter::ArchiveStatus _status; 949 949 unsigned int _indexBlockSizeHint; … … 960 960 ReadShaderFunctor(const std::string& filename, const Options* options):ReadFunctor(filename,options) {} 961 961 962 virtual ReaderWriter::ReadResult doRead(ReaderWriter& rw)const { return rw.readShader(_filename, _options); } 962 virtual ReaderWriter::ReadResult doRead(ReaderWriter& rw)const { return rw.readShader(_filename, _options); } 963 963 virtual bool isValid(ReaderWriter::ReadResult& readResult) const { return readResult.validShader(); } 964 964 virtual bool isValid(osg::Object* object) const { return dynamic_cast<osg::Shader*>(object)!=0; } … … 1018 1018 { 1019 1019 pathsContainsCurrentWorkingDirectory = true; 1020 } 1020 } 1021 1021 } 1022 1022 … … 1029 1029 } 1030 1030 } 1031 1031 1032 1032 1033 1033 // if a directory is included in the filename, get just the (simple) filename itself and try that … … 1109 1109 OSG_INFO<<" archive : "<<archiveName<<std::endl; 1110 1110 OSG_INFO<<" filename : "<<fileName<<std::endl; 1111 1111 1112 1112 ReaderWriter::ReadResult result = openArchiveImplementation(archiveName,ReaderWriter::READ, 4096, readFunctor._options); 1113 1113 1114 1114 if (!result.validArchive()) return result; 1115 1115 1116 1116 osgDB::Archive* archive = result.getArchive(); 1117 1117 1118 1118 //if valid options were passed through the read functor clone them 1119 1119 //otherwise make new options … … 1125 1125 1126 1126 std::auto_ptr<ReadFunctor> rf(readFunctor.cloneType(fileName, options.get())); 1127 1127 1128 1128 result = rf->doRead(*archive); 1129 1129 … … 1136 1136 } 1137 1137 } 1138 1138 1139 1139 // record the errors reported by readerwriters. 1140 1140 typedef std::vector<ReaderWriter::ReadResult> Results; … … 1181 1181 else if (ritr->status()==ReaderWriter::ReadResult::ERROR_IN_READING_FILE) ++num_ERROR_IN_READING_FILE; 1182 1182 } 1183 1183 1184 1184 if (num_FILE_NOT_HANDLED!=results.size()) 1185 1185 { … … 1236 1236 } 1237 1237 } 1238 1238 1239 1239 if (!results.empty()) 1240 1240 { … … 1252 1252 else if (ritr->status()==ReaderWriter::ReadResult::ERROR_IN_READING_FILE) ++num_ERROR_IN_READING_FILE; 1253 1253 } 1254 1254 1255 1255 if (num_FILE_NOT_HANDLED!=results.size()) 1256 1256 { … … 1306 1306 } 1307 1307 } 1308 1308 1309 1309 ReaderWriter::ReadResult rr = read(readFunctor); 1310 if (rr.validObject()) 1310 if (rr.validObject()) 1311 1311 { 1312 1312 // update cache with new entry. … … 1438 1438 return ReaderWriter::WriteResult("Warning: Could not find plugin to write image to file \""+fileName+"\"."); 1439 1439 } 1440 1440 1441 1441 if (results.front().message().empty()) 1442 1442 { … … 1501 1501 } 1502 1502 } 1503 1503 1504 1504 return results.front(); 1505 1505 } … … 1519 1519 1520 1520 return readImplementation(ReadNodeFunctor(fileName, options),Options::CACHE_NODES); 1521 1521 1522 1522 #endif 1523 1523 } … … 1549 1549 { 1550 1550 ReaderWriter::WriteResult rr = itr->writeNode(node,fileName,options); 1551 1551 1552 1552 if (rr.success()) return rr; 1553 1553 else results.push_back(rr); … … 1611 1611 return ReaderWriter::WriteResult("Warning: Could not find plugin to write shader to file \""+fileName+"\"."); 1612 1612 } 1613 1613 1614 1614 if (results.front().message().empty()) 1615 1615 { … … 1710 1710 OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_archiveCacheMutex); 1711 1711 ArchiveCache::iterator itr = _archiveCache.find(fileName); 1712 if (itr!=_archiveCache.end()) 1712 if (itr!=_archiveCache.end()) 1713 1713 { 1714 1714 _archiveCache.erase(itr); … … 1759 1759 { 1760 1760 if (!_sharedStateManager) _sharedStateManager = new SharedStateManager; 1761 1761 1762 1762 return _sharedStateManager.get(); 1763 1763 } 1764 1764 1765 1765 1766 void Registry::registerProtocol(const std::string& protocol) 1767 { 1768 _registeredProtocols.insert( convertToLowerCase(protocol) ); 1769 } 1770 1771 bool Registry::isProtocolRegistered(const std::string& protocol) 1772 { 1773 return (_registeredProtocols.find( convertToLowerCase(protocol) ) != _registeredProtocols.end()); 1774 } 1775 1766 void Registry::registerProtocol(const std::string& protocol) 1767 { 1768 _registeredProtocols.insert( convertToLowerCase(protocol) ); 1769 } 1770 1771 bool Registry::isProtocolRegistered(const std::string& protocol) 1772 { 1773 return (_registeredProtocols.find( convertToLowerCase(protocol) ) != _registeredProtocols.end()); 1774 } 1775
