Changeset 8577

Show
Ignore:
Timestamp:
07/13/08 17:24:45
Author:
robert
Message:

Added new ReaderWriter? methods for recording what protocols, extensions and options are
support by ReaderWriters?

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • OpenSceneGraph/trunk/include/osgDB/FileNameUtils

    r6005 r8577  
    3131extern OSGDB_EXPORT std::string convertFileNameToWindowsStyle(const std::string& fileName); 
    3232extern OSGDB_EXPORT std::string convertFileNameToUnixStyle(const std::string& fileName); 
     33extern OSGDB_EXPORT std::string convertToLowerCase(const std::string& fileName); 
    3334 
    3435extern OSGDB_EXPORT bool isFileNameNativeStyle(const std::string& fileName); 
  • OpenSceneGraph/trunk/include/osgDB/ReaderWriter

    r8535 r8577  
    2323 
    2424#include <deque> 
     25#include <list> 
    2526#include <iosfwd> 
    2627 
     
    4849        META_Object(osgDB,ReaderWriter); 
    4950 
    50         virtual bool acceptsExtension(const std::string& /*extension*/) const { return false; } 
     51        typedef std::map<std::string, std::string> FormatDescriptionMap; 
     52 
     53        /** return which protocols are supported by ReaderWriter. */ 
     54        virtual const FormatDescriptionMap& supportedProtocols() const { return _supportedProtocols; } 
     55         
     56        /** return which list of file extensions supported by ReaderWriter. */ 
     57        virtual const FormatDescriptionMap& supportedExtension() const { return _supportedExtensions; } 
     58         
     59        /** return which list of file extensions supported by ReaderWriter. */ 
     60        virtual const FormatDescriptionMap& supportedOptions() const { return _supportedOptions; } 
     61 
     62        /** return true if ReaderWriter accepts specified file extension.*/ 
     63        virtual bool acceptsExtension(const std::string& /*extension*/) const; 
    5164 
    5265        /** Options base class used for passing options into plugins to control their operation.*/ 
     
    305318        virtual WriteResult writeShader(const osg::Shader& /*shader*/,std::ostream& /*fout*/,const Options* =NULL) const { return WriteResult(WriteResult::FILE_NOT_HANDLED); } 
    306319 
     320    protected: 
     321     
     322        void supportsProtocol(const std::string& fmt, const std::string& description); 
     323        void supportsExtension(const std::string& fmt, const std::string& description); 
     324        void supportsOption(const std::string& fmt, const std::string& description); 
     325 
     326        FormatDescriptionMap _supportedProtocols; 
     327        FormatDescriptionMap _supportedExtensions; 
     328        FormatDescriptionMap _supportedOptions; 
    307329}; 
    308330 
  • OpenSceneGraph/trunk/src/osgDB/FileNameUtils.cpp

    r7994 r8577  
    114114std::string osgDB::getLowerCaseFileExtension(const std::string& filename) 
    115115{ 
    116     std::string ext = osgDB::getFileExtension(filename); 
    117     for(std::string::iterator itr=ext.begin(); 
    118         itr!=ext.end(); 
     116    return convertToLowerCase(osgDB::getFileExtension(filename)); 
     117
     118 
     119std::string osgDB::convertToLowerCase(const std::string& str) 
     120
     121    std::string lowcase_str(str); 
     122    for(std::string::iterator itr=lowcase_str.begin(); 
     123        itr!=lowcase_str.end(); 
    119124        ++itr) 
    120125    { 
    121126        *itr = tolower(*itr); 
    122127    } 
    123     return ext; 
    124 
    125  
     128    return lowcase_str; 
     129
    126130 
    127131// strip one level of extension from the filename. 
  • OpenSceneGraph/trunk/src/osgDB/ReaderWriter.cpp

    r7908 r8577  
    1313 
    1414#include <osgDB/ReaderWriter> 
     15#include <osgDB/FileNameUtils> 
    1516#include <osgDB/Archive> 
    1617 
     
    3435{ 
    3536} 
     37 
     38bool ReaderWriter::acceptsExtension(const std::string& extension) const 
     39{ 
     40    std::string lowercase_ext = convertToLowerCase(extension); 
     41    return (_supportedExtensions.count(lowercase_ext)!=0); 
     42} 
     43 
     44void ReaderWriter::supportsProtocol(const std::string& fmt, const std::string& description) 
     45{ 
     46    _supportedProtocols[convertToLowerCase(fmt)] = description; 
     47} 
     48 
     49void ReaderWriter::supportsExtension(const std::string& fmt, const std::string& description) 
     50{ 
     51    _supportedExtensions[convertToLowerCase(fmt)] = description; 
     52} 
     53 
     54void ReaderWriter::supportsOption(const std::string& fmt, const std::string& description) 
     55{ 
     56    _supportedOptions[fmt] = description; 
     57} 
  • OpenSceneGraph/trunk/src/osgPlugins/curl/ReaderWriterCURL.cpp

    r8325 r8577  
    143143ReaderWriterCURL::ReaderWriterCURL() 
    144144{ 
    145     //osg::notify(osg::NOTICE)<<"ReaderWriterCURL::ReaderWriterCURL()"<<std::endl; 
     145    supportsProtocol("http","Read from http port using libcurl."); 
     146    supportsExtension("curl","Psuedo file extension, used to select curl plugin."); 
     147    supportsOption("OSG_CURL_PROXY","Specify the http proxy."); 
     148    supportsOption("OSG_CURL_PROXYPORT","Specify the http proxy oirt."); 
    146149} 
    147150 
     
    186189    osg::notify(osg::INFO)<<"ReaderWriterCURL::readFile("<<fullFileName<<")"<<std::endl; 
    187190 
    188     std::string cacheFilePath, cacheFileName; 
    189191    std::string proxyAddress, optProxy, optProxyPort; 
    190192 
     
    196198        { 
    197199            int index = opt.find( "=" ); 
    198             if( opt.substr( 0, index ) == "OSG_FILE_CACHE" ) 
    199                 cacheFilePath = opt.substr( index+1 ); //Setting Cache Directory by OSG Options 
    200             else if( opt.substr( 0, index ) == "OSG_CURL_PROXY" ) 
     200            if( opt.substr( 0, index ) == "OSG_CURL_PROXY" ) 
    201201                optProxy = opt.substr( index+1 ); 
    202202            else if( opt.substr( 0, index ) == "OSG_CURL_PROXYPORT" ) 
     
    223223    } 
    224224 
    225     //Getting CURL Environment Variables (If found rewrite OSG Options) 
    226     const char* fileCachePath = getenv("OSG_FILE_CACHE"); 
    227     if (fileCachePath) //Env Cache Directory 
    228         cacheFilePath = std::string(fileCachePath); 
    229  
    230     if (!cacheFilePath.empty()) 
    231     { 
    232         cacheFileName = cacheFilePath + "/" +  
    233                         osgDB::getServerAddress(fileName) + "/" +  
    234                         osgDB::getServerFileName(fileName); 
    235  
    236         std::string path = osgDB::getFilePath(cacheFileName); 
    237  
    238         if (!osgDB::fileExists(path) && !osgDB::makeDirectory(path)) 
    239         { 
    240             cacheFileName.clear(); 
    241         } 
    242     } 
    243  
    244 #if 0 
    245     if (!cacheFilePath.empty() && osgDB::fileExists(cacheFileName)) 
    246     { 
    247         osg::notify(osg::NOTICE) << "Reading cache file " << cacheFileName <<", previous path "<<osgDB::getFilePath(fileName)<<std::endl; 
    248         ReadResult result = osgDB::Registry::instance()->readObject(cacheFileName,options); 
    249          
    250         return result;                 
    251     } 
    252 #endif 
    253225 
    254226    osgDB::ReaderWriter *reader =  
     
    274246    std::stringstream buffer; 
    275247 
    276 #if 0 
    277     EasyCurl::StreamObject sp(&buffer, cacheFileName); 
    278 #else 
    279248    EasyCurl::StreamObject sp(&buffer, std::string()); 
    280 #endif 
    281249 
    282250    ReadResult curlResult = getEasyCurl().read(proxyAddress, fileName, sp); 
     
    290258 
    291259        ReadResult readResult = readFile(objectType, reader, buffer, local_opt.get() ); 
    292  
    293 #if 0 
    294         if (!cacheFileName.empty() && readResult.success()) 
    295         { 
    296             switch(objectType) 
    297             { 
    298                 case(NODE):  
    299                     osg::notify(osg::NOTICE)<<"Write to cache "<<cacheFileName<<std::endl; 
    300                     reader->writeNode(*readResult.getNode(), cacheFileName, local_opt.get()); 
    301                     break; 
    302                 default: 
    303                     osg::notify(osg::NOTICE)<<"Curl plugin write to cache not implemented yet"<<std::endl; 
    304             } 
    305         } 
    306 #endif 
    307260 
    308261        local_opt->getDatabasePathList().pop_front(); 
  • OpenSceneGraph/trunk/src/osgPlugins/ive/ReaderWriterIVE.cpp

    r6753 r8577  
    1414{ 
    1515    public: 
     16     
     17        ReaderWriterIVE() 
     18        { 
     19            supportsExtension("ive","OpenSceneGraph native binary format"); 
     20        } 
     21     
    1622        virtual const char* className() const { return "IVE Reader/Writer"; } 
    1723 
  • OpenSceneGraph/trunk/src/osgPlugins/osg/ReaderWriterOSG.cpp

    r7447 r8577  
    1717{ 
    1818    public: 
     19     
     20        OSGReaderWriter() 
     21        { 
     22            supportsExtension("osg","OpenSceneGraph Ascii file format"); 
     23            supportsExtension("osgs","Psuedo OpenSceneGraph file loaded, with file encoded in filename string"); 
     24            supportsOption("precision","Set the floating point precision when writing out files"); 
     25            supportsOption("OutputTextureFiles","Write out the texture images to file"); 
     26        } 
     27     
    1928        virtual const char* className() const { return "OSG Reader/Writer"; } 
    20  
    21         virtual bool acceptsExtension(const std::string& extension) const 
    22         { 
    23             return equalCaseInsensitive(extension,"osg"); 
    24         } 
    2529 
    2630        virtual ReadResult readObject(const std::string& file, const Options* opt) const 
  • OpenSceneGraph/trunk/src/osgPlugins/rgb/ReaderWriterRGB.cpp

    r8295 r8577  
    444444{ 
    445445    public: 
     446     
     447        ReaderWriterRGB() 
     448        { 
     449            supportsExtension("rgb","rgb image format"); 
     450            supportsExtension("rgba","rgba image format"); 
     451            supportsExtension("sgi","sgi image format"); 
     452            supportsExtension("int","int image format"); 
     453            supportsExtension("inta","inta image format"); 
     454            supportsExtension("bw","bw image format"); 
     455        } 
     456     
    446457        virtual const char* className() const { return "RGB Image Reader/Writer"; } 
    447458         
    448         virtual bool acceptsExtension(const std::string& extension) const 
    449         { 
    450             return osgDB::equalCaseInsensitive(extension,"rgb") || 
    451                 osgDB::equalCaseInsensitive(extension,"sgi") || 
    452                 osgDB::equalCaseInsensitive(extension,"rgba") || 
    453                 osgDB::equalCaseInsensitive(extension,"int") ||  
    454                 osgDB::equalCaseInsensitive(extension,"inta") || 
    455                 osgDB::equalCaseInsensitive(extension,"bw"); 
    456         } 
    457  
    458459        ReadResult readRGBStream(std::istream& fin) const 
    459460        {