From 122ee0a0017b69dd7dc3e5296a1bf5c9985a1190 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 13 May 2009 19:46:16 +0000 Subject: [PATCH] Added ReaderWriter::fileExists() method to help enable querrying of existing of files on servers using the curl plugin --- include/osgDB/Options | 2 +- include/osgDB/ReaderWriter | 4 ++++ src/osgDB/ReaderWriter.cpp | 9 +++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/include/osgDB/Options b/include/osgDB/Options index febb7db72..38aa72acb 100644 --- a/include/osgDB/Options +++ b/include/osgDB/Options @@ -142,7 +142,7 @@ class OSGDB_EXPORT Options : public osg::Object void setPluginStringData(const std::string& s, const std::string& v) const { _pluginStringData[s] = v; } /** Get a string from the PluginStrData */ - std::string getPluginStringData(const std::string& s) { return _pluginStringData[s]; } + std::string& getPluginStringData(const std::string& s) { return _pluginStringData[s]; } /** Get a value from the PluginData */ const std::string getPluginStringData(const std::string& s) const diff --git a/include/osgDB/ReaderWriter b/include/osgDB/ReaderWriter index ee2d7fb1c..8eaa757eb 100644 --- a/include/osgDB/ReaderWriter +++ b/include/osgDB/ReaderWriter @@ -200,6 +200,10 @@ class OSGDB_EXPORT ReaderWriter : public osg::Object typedef osgDB::Options Options; + /** determine if a file exists, normally the default implementation will be approrpiate for local file access + * but with plugins like the libcurl based on it will return true if the file is accessible a server.*/ + virtual bool fileExists(const std::string& filename, const Options* options) const; + /** open an archive for reading, writing, or to create an empty archive for writing to.*/ virtual ReadResult openArchive(const std::string& /*fileName*/,ArchiveStatus, unsigned int =4096, const Options* =NULL) const { return ReadResult(ReadResult::NOT_IMPLEMENTED); } diff --git a/src/osgDB/ReaderWriter.cpp b/src/osgDB/ReaderWriter.cpp index 8fc2d029f..8cf48cf17 100644 --- a/src/osgDB/ReaderWriter.cpp +++ b/src/osgDB/ReaderWriter.cpp @@ -117,3 +117,12 @@ ReaderWriter::FeatureList ReaderWriter::featureAsString(ReaderWriter::Features f } return result; } + +bool ReaderWriter::fileExists(const std::string& filename, const Options* /*options*/) const +{ +#ifdef OSG_USE_UTF8_FILENAME + return _waccess( OSGDB_STRING_TO_FILENAME(filename).c_str(), F_OK ) == 0; +#else + return access( filename.c_str(), F_OK ) == 0; +#endif +}