Changeset 9887

Show
Ignore:
Timestamp:
03/10/09 16:00:39 (5 years ago)
Author:
robert
Message:

From Ralf Habacker, "The appended patch fixes this issue by adding a virtual method named supportedFeatures() to the class ReaderWriter?, which could be overriden by a specific plugin to adjust the set of features.
Single features are implemented as bits asother enums in ReaderWriter? class already does, so that combinations are possible and fast comparison operations are possible

By default all features are enabled.

I have added this virtual method to the dot plugin to get an idea how to use these features.

With this patch osgconv --formats shows an additional line 'features' for each plugin"

Location:
OpenSceneGraph/trunk
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/include/osgDB/PluginQuery

    r8689 r9887  
    4040        ReaderWriter::FormatDescriptionMap  extensions; 
    4141        ReaderWriter::FormatDescriptionMap  options; 
     42        ReaderWriter::Features              features; 
    4243 
    4344    protected: 
  • OpenSceneGraph/trunk/include/osgDB/ReaderWriter

    r9200 r9887  
    4949 
    5050        typedef std::map<std::string, std::string> FormatDescriptionMap; 
     51        typedef std::list<std::string> FeatureList; 
    5152 
    5253        /** return which protocols are supported by ReaderWriter. */ 
     
    6162        /** return true if ReaderWriter accepts specified file extension.*/ 
    6263        virtual bool acceptsExtension(const std::string& /*extension*/) const; 
     64 
     65        /// bit mask for setting up which feature types are available for read and/or write 
     66        enum Features 
     67        { 
     68            FEATURE_NONE               = 0, 
     69            FEATURE_READ_OBJECT        = 1<<0, 
     70            FEATURE_READ_IMAGE         = 1<<1,  
     71            FEATURE_READ_HEIGHT_FIELD  = 1<<2, 
     72            FEATURE_READ_NODE          = 1<<3,  
     73            FEATURE_READ_SHADER        = 1<<4,  
     74            FEATURE_WRITE_OBJECT       = 1<<5, 
     75            FEATURE_WRITE_IMAGE        = 1<<6, 
     76            FEATURE_WRITE_HEIGHT_FIELD = 1<<7, 
     77            FEATURE_WRITE_NODE         = 1<<8, 
     78            FEATURE_WRITE_SHADER       = 1<<9, 
     79            FEATURE_ALL                = FEATURE_READ_OBJECT        | 
     80                                         FEATURE_READ_IMAGE         | 
     81                                         FEATURE_READ_HEIGHT_FIELD  | 
     82                                         FEATURE_READ_NODE          | 
     83                                         FEATURE_READ_SHADER        | 
     84                                         FEATURE_WRITE_OBJECT       | 
     85                                         FEATURE_WRITE_IMAGE        | 
     86                                         FEATURE_WRITE_HEIGHT_FIELD | 
     87                                         FEATURE_WRITE_NODE         | 
     88                                         FEATURE_WRITE_SHADER        
     89        };     
     90        /** return available features*/ 
     91        virtual Features supportedFeatures() const; 
     92 
     93        /** return feature as string */ 
     94        static FeatureList featureAsString(Features feature); 
    6395 
    6496        /** Options base class used for passing options into plugins to control their operation.*/ 
  • OpenSceneGraph/trunk/src/osgDB/PluginQuery.cpp

    r8913 r9887  
    8181                rwi->extensions = rw->supportedExtensions(); 
    8282                rwi->options = rw->supportedOptions(); 
     83                rwi->features = rw->supportedFeatures(); 
    8384 
    8485                infoList.push_back(rwi.get()); 
     
    117118            out<<"    ReaderWriter : "<<info.description<<std::endl; 
    118119            out<<"    {"<<std::endl; 
    119  
     120            out<<"        features   : "; 
     121            osgDB::ReaderWriter::FeatureList fl = ReaderWriter::featureAsString(info.features); 
     122            osgDB::ReaderWriter::FeatureList::iterator fl_itr; 
     123            for(fl_itr = fl.begin(); 
     124                fl_itr != fl.end(); 
     125                ++fl_itr) 
     126            { 
     127                out << *fl_itr << " "; 
     128            }     
     129            out << std::endl; 
     130             
    120131            unsigned int longestOptionLength = 0; 
    121132            osgDB::ReaderWriter::FormatDescriptionMap::iterator fdm_itr; 
  • OpenSceneGraph/trunk/src/osgDB/ReaderWriter.cpp

    r9884 r9887  
    6161    _supportedOptions[fmt] = description; 
    6262} 
     63 
     64ReaderWriter::Features ReaderWriter::supportedFeatures() const 
     65{ 
     66    Features features = FEATURE_ALL; 
     67    return features; 
     68} 
     69 
     70ReaderWriter::FeatureList ReaderWriter::featureAsString(ReaderWriter::Features feature) 
     71{ 
     72    typedef struct { 
     73        ReaderWriter::Features feature; 
     74        const char *s; 
     75    } FeatureStringList; 
     76 
     77    FeatureStringList list[] = {  
     78        { FEATURE_READ_OBJECT, "readObject" }, 
     79        { FEATURE_READ_IMAGE,  "readImage" },         
     80        { FEATURE_READ_HEIGHT_FIELD, "readHeightField" }, 
     81        { FEATURE_READ_NODE, "readNode" },           
     82        { FEATURE_READ_SHADER, "readShader" },         
     83        { FEATURE_WRITE_OBJECT, "writeObject" }, 
     84        { FEATURE_WRITE_IMAGE, "writeImage" },         
     85        { FEATURE_WRITE_HEIGHT_FIELD, "writeHeightField" }, 
     86        { FEATURE_WRITE_NODE, "writeNode" },          
     87        { FEATURE_WRITE_SHADER, "writeShader" }, 
     88        { FEATURE_NONE,0 } 
     89    }; 
     90 
     91    FeatureList result;  
     92     
     93    for(FeatureStringList *p=list; p->feature != 0; p++) 
     94    { 
     95        if ((feature & p->feature) != 0) 
     96            result.push_back(p->s); 
     97    } 
     98    return result; 
     99}