From 38a0e6bf4ec67fba1d99e4962df5344f9053bbed Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 6 Oct 2004 13:11:04 +0000 Subject: [PATCH] Added support for parsing http:// names and mapping automatically to use the .net plugin --- include/osgDB/FileNameUtils | 4 ++++ src/osgDB/FileNameUtils.cpp | 44 +++++++++++++++++++++++++++++++++++++ src/osgDB/Registry.cpp | 29 ++++++++++++++++++++++++ 3 files changed, 77 insertions(+) diff --git a/include/osgDB/FileNameUtils b/include/osgDB/FileNameUtils index 8d454b00e..9ffc515ed 100644 --- a/include/osgDB/FileNameUtils +++ b/include/osgDB/FileNameUtils @@ -30,6 +30,10 @@ extern OSGDB_EXPORT std::string getStrippedName(const std::string& fileName); extern OSGDB_EXPORT bool equalCaseInsensitive(const std::string& lhs,const std::string& rhs); extern OSGDB_EXPORT bool equalCaseInsensitive(const std::string& lhs,const char* rhs); +extern OSGDB_EXPORT bool containsServerAddress(const std::string& filename); +extern OSGDB_EXPORT std::string getServerAddress(const std::string& filename); +extern OSGDB_EXPORT std::string getServerFileName(const std::string& filename); + } #endif diff --git a/src/osgDB/FileNameUtils.cpp b/src/osgDB/FileNameUtils.cpp index 96edb728b..526bc8374 100644 --- a/src/osgDB/FileNameUtils.cpp +++ b/src/osgDB/FileNameUtils.cpp @@ -115,6 +115,50 @@ bool osgDB::equalCaseInsensitive(const std::string& lhs,const char* rhs) return true; } +bool osgDB::containsServerAddress(const std::string& filename) +{ + // need to check for http:// + if (filename.size()<7) return false; + if (filename.compare(0,7,"http://")==0) return true; + return false; +} + +std::string osgDB::getServerAddress(const std::string& filename) +{ + if (filename.size()>=7 && filename.compare(0,7,"http://")==0) + { + std::string::size_type pos_slash = filename.find_first_of('/',7); + if (pos_slash!=std::string::npos) + { + return filename.substr(7,pos_slash-7); + } + else + { + return filename.substr(7,std::string::npos); + } + } + return ""; +} + +std::string osgDB::getServerFileName(const std::string& filename) +{ + if (filename.size()>=7 && filename.compare(0,7,"http://")==0) + { + std::string::size_type pos_slash = filename.find_first_of('/',7); + if (pos_slash!=std::string::npos) + { + return filename.substr(pos_slash+1,std::string::npos); + } + else + { + return ""; + } + + } + return filename; +} + + // // here a little test I wrote to make sure a couple of the above methods are // // working fine. // void test() diff --git a/src/osgDB/Registry.cpp b/src/osgDB/Registry.cpp index ba68f0149..afbaca063 100644 --- a/src/osgDB/Registry.cpp +++ b/src/osgDB/Registry.cpp @@ -1596,6 +1596,35 @@ ReaderWriter::WriteResult Registry::writeHeightFieldImplementation(const HeightF ReaderWriter::ReadResult Registry::readNode(const std::string& fileName) { + + if (containsServerAddress(fileName)) + { + std::string serverName = getServerAddress(fileName); + std::string serverFile = getServerFileName(fileName); + osg::notify(osg::INFO)<<"Contains sever address : "<readNode(serverName+":"+serverFile,_options.get()); + } + else + { + return ReaderWriter::ReadResult("Warning: Could not find the .net plugin to read from server."); + } + } + // record the errors reported by readerwriters. typedef std::vector Results; Results results;