Changeset 11902

Show
Ignore:
Timestamp:
11/09/10 13:41:55 (4 years ago)
Author:
robert
Message:

From Wang Rui, "I'd like to submit my latest modification of the serialization IO
functionalities. It includes two main parts: a version checking macro
for handling backward-compatiblity since 3.0, and enhencement of
current schema mechanism. I also change the option handling process to
use getPluginStringData(), and add new USE_SERIALIZER_WRAPPER macro in
the Registry header to allow for static-link usage as well.

The enhencement of schema machanism just tells the type of each
serializer while outputting them, such as:
osg::Group = Children:1

The meaning of the number can be found in the osgDB/Serializer header,
BaseSerializer::Type enum. It may help 3rdparty utilities understand
the structure of the wrapper and do some reflection work in the
future.

The new macro UPDATE_TO_VERSION can help indicate the InputStream? (no
affect on the writer) that a serializer is added/removed since certain
OSG version. An example wrapper file is also attached. The
Geode_modified.cpp is based on the serializers/osg/Geode.cpp file
(hey, don't merge it :-), but assumes that a new user serializer
'Test' is added since version 65 (that is, the OSG_SOVERSION):

REGISTER_OBJECT_WRAPPER( Geode, ... )
{

ADD_USER_SERIALIZER( Drawables ); // origin ones

UPDATE_TO_VERSION( 65 )
{

ADD_USER_SERIALIZER( Test ); // a serializer added from version 65

}

}

All kinds of ADD_... macros following UPDATE_TO_VERSION will
automatically apply the updated version. The braces here are only for
typesetting!
While reading an osgt/osgb/osgx file, OSG will now check if the file
version (recorded as the writer's soversion, instead of previous
meaningless "#Version 2") is equal or greater than Test's version, and
try reading it, or just ignore it if file version is lesser.

And we also have the REMOVE_SERIALIZER macro will mark a named
serializer as removed in some version, with which all files generated
by further versions will just ignore it:

UPDATE_TO_VERSION( 70 )
{

REMOVE_SERIALIZER( Test );

}

This means that from version 70, the serializer Test is removed (but
not actually erased from the list) and should not be read anymore. If
the read file version is less than 70 (and equal or greater than 65),
Test will still be handled when reading; otherwise it will be ignored
to keep compatiblity on different OSG versions.
"

Location:
OpenSceneGraph/trunk
Files:
7 modified

Legend:

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

    r11816 r11902  
    7070     
    7171    bool isBinary() const { return _in->isBinary(); } 
     72    int getFileVersion() const { return _fileVersion; } 
    7273    const osgDB::Options* getOptions() const { return _options.get(); } 
    7374     
     
    160161    IdentifierMap _identifierMap; 
    161162     
     163    int _fileVersion; 
    162164    int _byteSwap; 
    163165    bool _useSchemaData; 
  • OpenSceneGraph/trunk/include/osgDB/ObjectWrapper

    r11859 r11902  
    5151    ObjectWrapper( osg::Object* proto, const std::string& name, 
    5252                   const std::string& associates ); 
     53    void setUpdatedVersion( int ver ) { _version = ver; } 
    5354     
    5455    const osg::Object* getProto() const { return _proto.get(); } 
    5556    const std::string& getName() const { return _name; } 
    5657    const StringList& getAssociates() const { return _associates; } 
    57      
    58     void addSerializer( BaseSerializer* s ) { _serializers.push_back(s); } 
     58 
     59    void addSerializer( BaseSerializer* s, BaseSerializer::Type t=BaseSerializer::RW_UNDEFINED ) 
     60    { s->_version = _version; _serializers.push_back(s); _typeList.push_back(static_cast<int>(t)); } 
     61 
     62    void markSerializerAsRemoved( const std::string& name ); 
     63    BaseSerializer* getSerializer( const std::string& name ); 
    5964    void addFinishedObjectReadCallback ( FinishedObjectReadCallback* forc) { _finishedObjectReadCallbacks.push_back(forc); } 
    6065 
    61      
    6266    bool read( InputStream&, osg::Object& ); 
    6367    bool write( OutputStream&, const osg::Object& ); 
    64      
    65     bool readSchema( const StringList& properties ); 
    66     void writeSchema( StringList& properties ); 
     68 
     69    bool readSchema( const StringList& properties, const std::vector<int>& types ); 
     70    void writeSchema( StringList& properties, std::vector<int>& types ); 
    6771    void resetSchema() 
    6872    { if ( _backupSerializers.size()>0 ) _serializers = _backupSerializers; } 
    6973     
    7074protected: 
    71     ObjectWrapper() {} 
     75    ObjectWrapper() : _version(0) {} 
    7276    virtual ~ObjectWrapper() {} 
    73      
     77 
    7478    osg::ref_ptr<osg::Object> _proto; 
    7579    std::string _name; 
     
    7781    SerializerList _serializers; 
    7882    SerializerList _backupSerializers; 
     83    std::vector<int> _typeList; 
    7984    FinishedObjectReadCallbackList _finishedObjectReadCallbacks; 
     85    int _version;  // Last updated version of the wrapper 
    8086}; 
    8187 
     
    144150 
    145151#define REGISTER_OBJECT_WRAPPER(NAME, PROTO, CLASS, ASSOCIATES) \ 
     152    extern "C" void wrapper_serializer_##NAME(void) {} \ 
    146153    extern void wrapper_propfunc_##NAME(osgDB::ObjectWrapper*); \ 
    147154    static osgDB::RegisterWrapperProxy wrapper_proxy_##NAME( \ 
     
    151158 
    152159#define REGISTER_OBJECT_WRAPPER2(NAME, PROTO, CLASS, CLASSNAME, ASSOCIATES) \ 
     160    extern "C" void wrapper_serializer_##NAME(void) {} \ 
    153161    extern void wrapper_propfunc_##NAME(osgDB::ObjectWrapper*); \ 
    154162    static osgDB::RegisterWrapperProxy wrapper_proxy_##NAME( \ 
     
    168176 
    169177#define REGISTER_COMPRESSOR(NAME, CLASS) \ 
     178    extern "C" void wrapper_compressor_##CLASS(void) {} \ 
    170179    static osgDB::RegisterCompressorProxy compressor_proxy_##CLASS(NAME, new CLASS); 
    171180 
  • OpenSceneGraph/trunk/include/osgDB/Registry

    r11084 r11902  
    638638    static osgDB::PluginFunctionProxy proxy_dotosgwrapper_##classname(dotosgwrapper_##classname); 
    639639 
     640#define USE_SERIALIZER_WRAPPER(classname) \ 
     641    extern "C" void wrapper_serializer_##classname(void); \ 
     642    static osgDB::PluginFunctionProxy proxy_serializer_##classname(wrapper_serializer_##classname); 
     643 
     644#define USE_COMPRESSOR_WRAPPER(classname) \ 
     645    extern "C" void wrapper_serializer_##classname(void); \ 
     646    static osgDB::PluginFunctionProxy proxy_compressor_##classname(wrapper_compressor_##classname); 
     647 
    640648#define REGISTER_OSGPLUGIN(ext, classname) \ 
    641649    extern "C" void osgdb_##ext(void) {} \ 
  • OpenSceneGraph/trunk/include/osgDB/Serializer

    r11816 r11902  
    117117class BaseSerializer : public osg::Referenced 
    118118{ 
    119 public: 
    120     BaseSerializer() {} 
     119    friend class ObjectWrapper; 
     120public: 
     121    enum Type 
     122    { 
     123        RW_UNDEFINED = 0, RW_USER, RW_OBJECT, RW_IMAGE, RW_LIST, 
     124        RW_BOOL, RW_SHORT, RW_USHORT, RW_INT, RW_UINT, RW_FLOAT, RW_DOUBLE, 
     125        RW_VEC2F, RW_VEC2D, RW_VEC3F, RW_VEC3D, RW_VEC4F, RW_VEC4D, RW_QUAT, RW_PLANE, 
     126        RW_MATRIXF, RW_MATRIXD, RW_MATRIX, RW_GLENUM, RW_STRING, RW_ENUM 
     127    }; 
     128 
     129    BaseSerializer() : _version(0) {} 
    121130    virtual bool read( InputStream&, osg::Object& ) = 0; 
    122131    virtual bool write( OutputStream&, const osg::Object& ) = 0; 
    123132    virtual const std::string& getName() const = 0; 
     133 
     134protected: 
     135    int _version;  // Library version when the serializer is added, or removed (neg value) 
    124136}; 
    125137 
     
    768780#define ADD_USER_SERIALIZER(PROP) \ 
    769781    wrapper->addSerializer( new osgDB::UserSerializer<MyClass>( \ 
    770         #PROP, &check##PROP, &read##PROP, &write##PROP) ) 
     782        #PROP, &check##PROP, &read##PROP, &write##PROP), osgDB::BaseSerializer::RW_USER ) 
    771783 
    772784#define ADD_BOOL_SERIALIZER(PROP, DEF) \ 
    773785    wrapper->addSerializer( new osgDB::PropByValSerializer< MyClass, bool >( \ 
    774         #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP) ) 
     786        #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_BOOL ) 
    775787 
    776788#define ADD_SHORT_SERIALIZER(PROP, DEF) \ 
    777789    wrapper->addSerializer( new osgDB::PropByValSerializer< MyClass, short >( \ 
    778         #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP) ) 
     790        #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_SHORT ) 
    779791 
    780792#define ADD_USHORT_SERIALIZER(PROP, DEF) \ 
    781793    wrapper->addSerializer( new osgDB::PropByValSerializer< MyClass, unsigned short >( \ 
    782         #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP) ) 
     794        #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_USHORT ) 
    783795 
    784796#define ADD_HEXSHORT_SERIALIZER(PROP, DEF) \ 
    785797    wrapper->addSerializer( new osgDB::PropByValSerializer< MyClass, unsigned short >( \ 
    786         #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP, true) ) 
     798        #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP, true), osgDB::BaseSerializer::RW_USHORT ) 
    787799 
    788800#define ADD_INT_SERIALIZER(PROP, DEF) \ 
    789801    wrapper->addSerializer( new osgDB::PropByValSerializer< MyClass, int >( \ 
    790         #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP) ) 
     802        #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_INT ) 
    791803 
    792804#define ADD_UINT_SERIALIZER(PROP, DEF) \ 
    793805    wrapper->addSerializer( new osgDB::PropByValSerializer< MyClass, unsigned int >( \ 
    794         #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP) ) 
     806        #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_UINT ) 
    795807         
    796808#define ADD_GLINT_SERIALIZER(PROP, DEF) \ 
    797809    wrapper->addSerializer( new osgDB::PropByValSerializer< MyClass, GLint >( \ 
    798         #PROP, ((int)(DEF)), &MyClass::get##PROP, &MyClass::set##PROP) ) 
     810        #PROP, ((int)(DEF)), &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_INT ) 
    799811 
    800812#define ADD_HEXINT_SERIALIZER(PROP, DEF) \ 
    801813    wrapper->addSerializer( new osgDB::PropByValSerializer< MyClass, unsigned int >( \ 
    802         #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP, true) ) 
     814        #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP, true), osgDB::BaseSerializer::RW_UINT ) 
    803815 
    804816#define ADD_FLOAT_SERIALIZER(PROP, DEF) \ 
    805817    wrapper->addSerializer( new osgDB::PropByValSerializer< MyClass, float >( \ 
    806         #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP) ) 
     818        #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_FLOAT ) 
    807819 
    808820#define ADD_DOUBLE_SERIALIZER(PROP, DEF) \ 
    809821    wrapper->addSerializer( new osgDB::PropByValSerializer< MyClass, double >( \ 
    810         #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP) ) 
     822        #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_DOUBLE ) 
    811823 
    812824#define ADD_VEC2F_SERIALIZER(PROP, DEF) \ 
    813825    wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::Vec2f >( \ 
    814         #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP) ) 
     826        #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_VEC2F ) 
    815827 
    816828#define ADD_VEC2D_SERIALIZER(PROP, DEF) \ 
    817829    wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::Vec2d >( \ 
    818         #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP) ) 
     830        #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_VEC2D ) 
    819831 
    820832#define ADD_VEC2_SERIALIZER(PROP, DEF) ADD_VEC2F_SERIALIZER(PROP, DEF) 
     
    822834#define ADD_VEC3F_SERIALIZER(PROP, DEF) \ 
    823835    wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::Vec3f >( \ 
    824         #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP) ) 
     836        #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_VEC3F ) 
    825837 
    826838#define ADD_VEC3D_SERIALIZER(PROP, DEF) \ 
    827839    wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::Vec3d >( \ 
    828         #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP) ) 
     840        #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_VEC3D ) 
    829841 
    830842#define ADD_VEC3_SERIALIZER(PROP, DEF) ADD_VEC3F_SERIALIZER(PROP, DEF) 
     
    832844#define ADD_VEC4F_SERIALIZER(PROP, DEF) \ 
    833845    wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::Vec4f >( \ 
    834         #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP) ) 
     846        #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_VEC4F ) 
    835847 
    836848#define ADD_VEC4D_SERIALIZER(PROP, DEF) \ 
    837849    wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::Vec4d >( \ 
    838         #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP) ) 
     850        #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_VEC4D ) 
    839851 
    840852#define ADD_VEC4_SERIALIZER(PROP, DEF) ADD_VEC4F_SERIALIZER(PROP, DEF) 
     
    842854#define ADD_QUAT_SERIALIZER(PROP, DEF) \ 
    843855    wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::Quat >( \ 
    844         #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP) ) 
     856        #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_QUAT ) 
    845857 
    846858#define ADD_PLANE_SERIALIZER(PROP, DEF) \ 
    847859    wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::Plane >( \ 
    848         #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP) ) 
     860        #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_PLANE ) 
    849861 
    850862#define ADD_MATRIXF_SERIALIZER(PROP, DEF) \ 
    851863    wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::Matrixf >( \ 
    852         #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP) ) 
     864        #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_MATRIXF ) 
    853865 
    854866#define ADD_MATRIXD_SERIALIZER(PROP, DEF) \ 
    855867    wrapper->addSerializer( new osgDB::PropByRefSerializer< MyClass, osg::Matrixd >( \ 
    856         #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP) ) 
     868        #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_MATRIXD ) 
    857869 
    858870#define ADD_MATRIX_SERIALIZER(PROP, DEF) \ 
    859871    wrapper->addSerializer( new osgDB::MatrixSerializer< MyClass >( \ 
    860         #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP) ) 
     872        #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_MATRIX ) 
    861873 
    862874#define ADD_GLENUM_SERIALIZER(PROP, TYPE, DEF) \ 
    863875    wrapper->addSerializer( new osgDB::GLenumSerializer< MyClass, TYPE >( \ 
    864         #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP) ) 
     876        #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_GLENUM ) 
    865877 
    866878#define ADD_STRING_SERIALIZER(PROP, DEF) \ 
    867879    wrapper->addSerializer( new osgDB::StringSerializer< MyClass >( \ 
    868         #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP) ) 
     880        #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_STRING ) 
    869881 
    870882#define ADD_OBJECT_SERIALIZER(PROP, TYPE, DEF) \ 
    871883    wrapper->addSerializer( new osgDB::ObjectSerializer< MyClass, TYPE >( \ 
    872         #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP) ) 
     884        #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_OBJECT ) 
    873885 
    874886#define ADD_IMAGE_SERIALIZER(PROP, TYPE, DEF) \ 
    875887    wrapper->addSerializer( new osgDB::ImageSerializer< MyClass, TYPE >( \ 
    876         #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP) ) 
     888        #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_IMAGE ) 
    877889 
    878890#define ADD_LIST_SERIALIZER(PROP, TYPE) \ 
    879891    wrapper->addSerializer( new osgDB::ListSerializer< MyClass, TYPE >( \ 
    880         #PROP, &MyClass::get##PROP, &MyClass::set##PROP) ) 
     892        #PROP, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_LIST ) 
    881893 
    882894#define BEGIN_ENUM_SERIALIZER(PROP, DEF) \ 
     
    900912        #PROP, PROPERTIES_CLASS::DEF, &MyClass::get##PROP, &MyClass::set##PROP) 
    901913 
    902  
    903914#define ADD_ENUM_VALUE(VALUE) \ 
    904915    serializer->add(#VALUE, MyClass::VALUE) 
     
    908919 
    909920#define END_ENUM_SERIALIZER() \ 
    910     wrapper->addSerializer(serializer.get()); } 
     921    wrapper->addSerializer(serializer.get(), osgDB::BaseSerializer::RW_ENUM); } 
     922 
     923// VERSION CONTROL OPERATORS 
     924#define UPDATE_TO_VERSION(VER) \ 
     925    wrapper->setUpdatedVersion( (VER) ); 
     926 
     927#define REMOVE_SERIALIZER(PROP) \ 
     928    wrapper->markSerializerAsRemoved( #PROP ); 
    911929 
    912930} 
  • OpenSceneGraph/trunk/src/osgDB/InputStream.cpp

    r11816 r11902  
    2525 
    2626InputStream::InputStream( const osgDB::Options* options ) 
    27     :   _byteSwap(0), _useSchemaData(false), _forceReadingImage(false), _dataDecompress(0) 
     27    :   _fileVersion(0), _byteSwap(0), _useSchemaData(false), _forceReadingImage(false), _dataDecompress(0) 
    2828{ 
    2929    if ( !options ) return; 
     
    3131     
    3232    std::string schema; 
    33     StringList optionList; 
    34     split( options->getOptionString(), optionList ); 
    35     for ( StringList::iterator itr=optionList.begin(); itr!=optionList.end(); ++itr ) 
    36     { 
    37         const std::string& option = *itr; 
    38         if ( option=="Ascii" ) 
    39         { 
    40             // Omit this 
    41         } 
    42         else if ( option=="ForceReadingImage" ) 
    43         { 
    44             _forceReadingImage = true; 
    45         } 
    46         else 
    47         { 
    48             StringList keyAndValues; 
    49             split( option, keyAndValues, '=' ); 
    50             if ( keyAndValues.size()<2 ) continue; 
    51              
    52             if ( keyAndValues[0]=="SchemaFile" ) 
    53             { 
    54                 schema = keyAndValues[1]; 
    55                 if ( s_lastSchema!=schema ) 
    56                 { 
    57                     osgDB::ifstream schemaStream( schema.c_str(), std::ios::in ); 
    58                     if ( !schemaStream.fail() ) readSchema( schemaStream ); 
    59                     schemaStream.close(); 
    60                     s_lastSchema = schema; 
    61                 } 
    62             } 
    63             else 
    64                 OSG_WARN << "InputStream: Unknown option " << option << std::endl; 
    65         } 
    66     } 
     33    if ( options->getPluginStringData("ForceReadingImage")=="true" ) 
     34        _forceReadingImage = true; 
     35    if ( !options->getPluginStringData("SchemaFile").empty() ) 
     36    { 
     37        schema = options->getPluginStringData("SchemaFile"); 
     38        if ( s_lastSchema!=schema ) 
     39        { 
     40            osgDB::ifstream schemaStream( schema.c_str(), std::ios::in ); 
     41            if ( !schemaStream.fail() ) readSchema( schemaStream ); 
     42            schemaStream.close(); 
     43            s_lastSchema = schema; 
     44        } 
     45    } 
     46     
    6747    if ( schema.empty() ) 
    6848    { 
     
    734714    } 
    735715     
    736     // Check file version 
    737     if ( version!=PLUGIN_VERSION ) 
    738     { 
    739         OSG_WARN << "InputStream: Input data version " << version 
    740                                << " may be incompatible with current reader version " 
    741                                << PLUGIN_VERSION << std::endl; 
    742     } 
     716    // Record file version for back-compatibility checking of wrappers 
     717    _fileVersion = version; 
    743718    _fields.pop_back(); 
    744719    return type; 
     
    794769    } 
    795770     
    796     StringList schema; 
     771    StringList schema, methods, keyAndValue; 
     772    std::vector<int> types; 
    797773    split( properties, schema ); 
    798     wrapper->readSchema( schema ); 
     774    for ( StringList::iterator itr=schema.begin(); itr!=schema.end(); ++itr ) 
     775    { 
     776        split( *itr, keyAndValue, ':' ); 
     777        if ( keyAndValue.size()>1 ) 
     778        { 
     779            methods.push_back( keyAndValue.front() ); 
     780            types.push_back( atoi(keyAndValue.back().c_str()) ); 
     781        } 
     782        else 
     783        { 
     784            methods.push_back( *itr ); 
     785            types.push_back( 0 ); 
     786        } 
     787        keyAndValue.clear(); 
     788    } 
     789    wrapper->readSchema( methods, types ); 
    799790} 
    800791 
  • OpenSceneGraph/trunk/src/osgDB/ObjectWrapper.cpp

    r11859 r11902  
    8787                              const std::string& associates ) 
    8888:   osg::Referenced(), 
    89     _proto(proto), _name(name) 
     89    _proto(proto), _name(name), _version(0) 
    9090{ 
    9191    split( associates, _associates ); 
     92} 
     93 
     94void ObjectWrapper::markSerializerAsRemoved( const std::string& name ) 
     95{ 
     96    for ( SerializerList::iterator itr=_serializers.begin(); itr!=_serializers.end(); ++itr ) 
     97    { 
     98        // When a serializer is marked as 'removed', it means that this serializer won't be used any more 
     99        // from specified OSG version (by macro UPDATE_TO_VERSION). The read() functions of higher versions 
     100        // will thus ignore it according to the sign and value of the _version variable. 
     101        if ( (*itr)->getName()==name ) 
     102            (*itr)->_version = -_version; 
     103    } 
     104} 
     105 
     106BaseSerializer* ObjectWrapper::getSerializer( const std::string& name ) 
     107{ 
     108    for ( SerializerList::iterator itr=_serializers.begin(); itr!=_serializers.end(); ++itr ) 
     109    { 
     110        if ( (*itr)->getName()==name ) 
     111            return *itr; 
     112    } 
     113     
     114    for ( StringList::const_iterator itr=_associates.begin(); itr!=_associates.end(); ++itr ) 
     115    { 
     116        const std::string& assocName = *itr; 
     117        ObjectWrapper* assocWrapper = Registry::instance()->getObjectWrapperManager()->findWrapper(assocName); 
     118        if ( !assocWrapper ) 
     119        { 
     120            osg::notify(osg::WARN) << "ObjectWrapper::getSerializer(): Unsupported associated class " 
     121                                   << assocName << std::endl; 
     122            continue; 
     123        } 
     124         
     125        for ( SerializerList::iterator aitr=assocWrapper->_serializers.begin(); 
     126              aitr!=assocWrapper->_serializers.end(); ++aitr ) 
     127        { 
     128            if ( (*aitr)->getName()==name ) 
     129                return *aitr; 
     130        } 
     131    } 
     132    return NULL; 
    92133} 
    93134 
     
    98139          itr!=_serializers.end(); ++itr ) 
    99140    { 
     141        int serializerVersion = (*itr)->_version; 
     142        if ( serializerVersion!=0 ) 
     143        { 
     144            if ( serializerVersion<0 ) 
     145            { 
     146                serializerVersion = -serializerVersion; 
     147                 
     148                // The serializer is removed from a specified version, 
     149                // and the file in reading is at the same or higher version, ignore it. 
     150                if ( is.getFileVersion()>=serializerVersion ) continue; 
     151            } 
     152            else 
     153            { 
     154                // The serializer is added at a specified version, 
     155                // but the file in reading is at a lower version, ignore it. 
     156                if ( is.getFileVersion()<serializerVersion ) continue; 
     157            } 
     158        } 
     159         
    100160        if ( (*itr)->read(is, obj) ) continue; 
    101161        OSG_WARN << "ObjectWrapper::read(): Error reading property " 
     
    128188} 
    129189 
    130 bool ObjectWrapper::readSchema( const StringList& properties ) 
    131 { 
     190bool ObjectWrapper::readSchema( const StringList& properties, const std::vector<int>& ) 
     191{ 
     192    // FIXME: At present, I didn't do anything to determine serializers from their types... 
    132193    if ( !_backupSerializers.size() ) 
    133194        _backupSerializers = _serializers; 
     
    170231} 
    171232 
    172 void ObjectWrapper::writeSchema( StringList& properties ) 
     233void ObjectWrapper::writeSchema( StringList& properties, std::vector<int>& types ) 
    173234{ 
    174235    for ( SerializerList::iterator itr=_serializers.begin(); 
     
    176237    { 
    177238        properties.push_back( (*itr)->getName() ); 
     239    } 
     240     
     241    for ( std::vector<int>::iterator itr=_typeList.begin(); 
     242          itr!=_typeList.end(); ++itr ) 
     243    { 
     244        types.push_back( (*itr) ); 
    178245    } 
    179246} 
  • OpenSceneGraph/trunk/src/osgDB/OutputStream.cpp

    r11816 r11902  
    1919#include <osgDB/ObjectWrapper> 
    2020#include <fstream> 
     21#include <sstream> 
    2122 
    2223using namespace osgDB; 
     
    2829    _options = options; 
    2930     
    30     StringList optionList; 
    31     split( options->getOptionString(), optionList ); 
    32     for ( StringList::iterator itr=optionList.begin(); itr!=optionList.end(); ++itr ) 
    33     { 
    34         const std::string& option = *itr; 
    35         if ( option=="Ascii" ) 
    36         { 
    37             // Omit this 
    38         } 
    39         else if ( option=="SchemaData" ) 
    40         { 
    41             _useSchemaData = true; 
    42         } 
    43         else 
    44         { 
    45             StringList keyAndValues; 
    46             split( option, keyAndValues, '=' ); 
    47             if ( keyAndValues.size()<2 ) continue; 
    48              
    49             if ( keyAndValues[0]=="SchemaFile" ) 
    50                 _schemaName = keyAndValues[1]; 
    51             else if ( keyAndValues[0]=="Compressor" ) 
    52                 _compressorName = keyAndValues[1]; 
    53             else if ( keyAndValues[0]=="WriteImageHint" ) 
    54             { 
    55                 if ( keyAndValues[1]=="IncludeData" ) _writeImageHint = WRITE_INLINE_DATA; 
    56                 else if ( keyAndValues[1]=="IncludeFile" ) _writeImageHint = WRITE_INLINE_FILE; 
    57                 else if ( keyAndValues[1]=="UseExternal" ) _writeImageHint = WRITE_USE_EXTERNAL; 
    58                 else if ( keyAndValues[1]=="WriteOut" ) _writeImageHint = WRITE_EXTERNAL_FILE; 
    59             } 
    60             else 
    61                 OSG_WARN << "OutputStream: Unknown option " << option << std::endl; 
    62         } 
     31    if ( options->getPluginStringData("SchemaData")=="true" ) 
     32        _useSchemaData = true; 
     33    if ( !options->getPluginStringData("SchemaFile").empty() ) 
     34        _schemaName = options->getPluginStringData("SchemaFile"); 
     35    if ( !options->getPluginStringData("Compressor").empty() ) 
     36        _compressorName = options->getPluginStringData("Compressor"); 
     37    if ( !options->getPluginStringData("WriteImageHint").empty() ) 
     38    { 
     39        std::string hintString = options->getPluginStringData("WriteImageHint"); 
     40        if ( hintString=="IncludeData" ) _writeImageHint = WRITE_INLINE_DATA; 
     41        else if ( hintString=="IncludeFile" ) _writeImageHint = WRITE_INLINE_FILE; 
     42        else if ( hintString=="UseExternal" ) _writeImageHint = WRITE_USE_EXTERNAL; 
     43        else if ( hintString=="WriteOut" ) _writeImageHint = WRITE_EXTERNAL_FILE; 
    6344    } 
    6445} 
     
    491472            { 
    492473                StringList properties; 
    493                 assocWrapper->writeSchema( properties ); 
    494                 if ( properties.size()>0 ) 
     474                std::vector<int> types; 
     475                assocWrapper->writeSchema( properties, types ); 
     476                 
     477                unsigned int size = osg::minimum( properties.size(), types.size() ); 
     478                if ( size>0 ) 
    495479                { 
    496                     std::string propertiesString; 
    497                     for ( StringList::iterator sitr=properties.begin(); sitr!=properties.end(); ++sitr ) 
     480                    std::stringstream propertiesStream; 
     481                    for ( unsigned int i=0; i<size; ++i ) 
    498482                    { 
    499                         propertiesString += *sitr; 
    500                         propertiesString += ' '; 
     483                        propertiesStream << properties[i] << ":" << types[i] << " "; 
    501484                    } 
    502                     _inbuiltSchemaMap[assocName] = propertiesString; 
     485                    _inbuiltSchemaMap[assocName] = propertiesStream.str(); 
    503486                } 
    504487            } 
     
    527510    if ( isBinary() ) 
    528511    { 
    529         *this << (unsigned int)type << (unsigned int)PLUGIN_VERSION; 
     512        *this << (unsigned int)type << (unsigned int)OPENSCENEGRAPH_SOVERSION; 
    530513         
    531514        bool useCompressSource = false; 
     
    575558         
    576559        *this << typeString << std::endl; 
    577         *this << PROPERTY("#Version") << (unsigned int)PLUGIN_VERSION << std::endl; 
     560        *this << PROPERTY("#Version") << (unsigned int)OPENSCENEGRAPH_SOVERSION << std::endl; 
    578561        *this << PROPERTY("#Generator") << std::string("OpenSceneGraph") 
    579562              << std::string(osgGetVersion()) << std::endl; 
     
    643626         
    644627        StringList properties; 
    645         wrapper->writeSchema( properties ); 
    646         if ( properties.size()>0 ) 
    647         { 
    648             for ( StringList::iterator sitr=properties.begin(); sitr!=properties.end(); ++sitr ) 
    649             { 
    650                 fout << ' ' << *sitr; 
    651             } 
     628        std::vector<int> types; 
     629        wrapper->writeSchema( properties, types ); 
     630         
     631        std::string propertiesString; 
     632        unsigned int size = osg::minimum( properties.size(), types.size() ); 
     633        for ( unsigned int i=0; i<size; ++i ) 
     634        { 
     635            fout << " " << properties[i] << ":" << types[i]; 
    652636        } 
    653637        fout << std::endl;