Refactored the versioning of serializers so it now uses a _firstVersion and _lastVersion make it possible
to specify what range of versions support each serializer.
This commit is contained in:
parent
b8a94a6d4e
commit
b7cccf6258
@ -56,9 +56,7 @@ public:
|
||||
const std::string& getName() const { return _name; }
|
||||
const StringList& getAssociates() const { return _associates; }
|
||||
|
||||
void addSerializer( BaseSerializer* s, BaseSerializer::Type t=BaseSerializer::RW_UNDEFINED )
|
||||
{ s->_version = _version; _serializers.push_back(s); _typeList.push_back(static_cast<int>(t)); }
|
||||
|
||||
void addSerializer( BaseSerializer* s, BaseSerializer::Type t=BaseSerializer::RW_UNDEFINED );
|
||||
void markSerializerAsRemoved( const std::string& name );
|
||||
BaseSerializer* getSerializer( const std::string& name );
|
||||
void addFinishedObjectReadCallback ( FinishedObjectReadCallback* forc) { _finishedObjectReadCallbacks.push_back(forc); }
|
||||
|
@ -20,9 +20,10 @@
|
||||
#include <osg/Object>
|
||||
#include <osgDB/InputStream>
|
||||
#include <osgDB/OutputStream>
|
||||
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
namespace osgDB
|
||||
{
|
||||
@ -126,13 +127,15 @@ public:
|
||||
RW_MATRIXF, RW_MATRIXD, RW_MATRIX, RW_GLENUM, RW_STRING, RW_ENUM
|
||||
};
|
||||
|
||||
BaseSerializer() : _version(0) {}
|
||||
BaseSerializer() : _firstVersion(0), _lastVersion(INT_MAX) {}
|
||||
|
||||
virtual bool read( InputStream&, osg::Object& ) = 0;
|
||||
virtual bool write( OutputStream&, const osg::Object& ) = 0;
|
||||
virtual const std::string& getName() const = 0;
|
||||
|
||||
protected:
|
||||
int _version; // Library version when the serializer is added, or removed (neg value)
|
||||
int _firstVersion; // Library version when the serializer is first introduced
|
||||
int _lastVersion; // Library version when the serializer is last required.
|
||||
};
|
||||
|
||||
template<typename C>
|
||||
|
@ -91,6 +91,13 @@ ObjectWrapper::ObjectWrapper( osg::Object* proto, const std::string& name,
|
||||
split( associates, _associates );
|
||||
}
|
||||
|
||||
void ObjectWrapper::addSerializer( BaseSerializer* s, BaseSerializer::Type t )
|
||||
{
|
||||
s->_firstVersion = _version;
|
||||
_serializers.push_back(s);
|
||||
_typeList.push_back(static_cast<int>(t));
|
||||
}
|
||||
|
||||
void ObjectWrapper::markSerializerAsRemoved( const std::string& name )
|
||||
{
|
||||
for ( SerializerList::iterator itr=_serializers.begin(); itr!=_serializers.end(); ++itr )
|
||||
@ -99,7 +106,7 @@ void ObjectWrapper::markSerializerAsRemoved( const std::string& name )
|
||||
// from specified OSG version (by macro UPDATE_TO_VERSION). The read() functions of higher versions
|
||||
// will thus ignore it according to the sign and value of the _version variable.
|
||||
if ( (*itr)->getName()==name )
|
||||
(*itr)->_version = -_version;
|
||||
(*itr)->_lastVersion = _version-1;
|
||||
}
|
||||
}
|
||||
|
||||
@ -138,29 +145,21 @@ bool ObjectWrapper::read( InputStream& is, osg::Object& obj )
|
||||
for ( SerializerList::iterator itr=_serializers.begin();
|
||||
itr!=_serializers.end(); ++itr )
|
||||
{
|
||||
int serializerVersion = (*itr)->_version;
|
||||
if ( serializerVersion!=0 )
|
||||
BaseSerializer* serializer = itr->get();
|
||||
if ( serializer->_firstVersion <= is.getFileVersion() &&
|
||||
is.getFileVersion() <= serializer->_lastVersion)
|
||||
{
|
||||
if ( serializerVersion<0 )
|
||||
if ( !serializer->read(is, obj) )
|
||||
{
|
||||
serializerVersion = -serializerVersion;
|
||||
|
||||
// The serializer is removed from a specified version,
|
||||
// and the file in reading is at the same or higher version, ignore it.
|
||||
if ( is.getFileVersion()>=serializerVersion ) continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
// The serializer is added at a specified version,
|
||||
// but the file in reading is at a lower version, ignore it.
|
||||
if ( is.getFileVersion()<serializerVersion ) continue;
|
||||
OSG_WARN << "ObjectWrapper::read(): Error reading property "
|
||||
<< _name << "::" << (*itr)->getName() << std::endl;
|
||||
readOK = false;
|
||||
}
|
||||
}
|
||||
|
||||
if ( (*itr)->read(is, obj) ) continue;
|
||||
OSG_WARN << "ObjectWrapper::read(): Error reading property "
|
||||
<< _name << "::" << (*itr)->getName() << std::endl;
|
||||
readOK = false;
|
||||
else
|
||||
{
|
||||
// OSG_NOTICE<<"Ignoring serializer due to version mismatch"<<std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
for ( FinishedObjectReadCallbackList::iterator itr=_finishedObjectReadCallbacks.begin();
|
||||
|
Loading…
Reference in New Issue
Block a user