Added support for parsing http:// names and mapping automatically to use

the .net plugin
This commit is contained in:
Robert Osfield 2004-10-06 13:11:04 +00:00
parent c4e5e0fa30
commit 38a0e6bf4e
3 changed files with 77 additions and 0 deletions

View File

@ -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

View File

@ -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()

View File

@ -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 : "<<serverName<<std::endl;
osg::notify(osg::INFO)<<" file name on server : "<<serverFile<<std::endl;
if (serverName.empty())
{
return ReaderWriter::ReadResult("Warning: Server address invalid.");
}
if (serverFile.empty())
{
return ReaderWriter::ReadResult("Warning: Server file name invalid.");
}
ReaderWriter* rw = getReaderWriterForExtension("net");
if (rw)
{
return rw->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<ReaderWriter::ReadResult> Results;
Results results;