Added get/set method to Serializer to allow pointer passing without going through InputStream/OutputStream.

This commit is contained in:
Robert Osfield 2013-10-10 09:28:26 +00:00
parent 9c53794bc7
commit 4e4d2b35cf
2 changed files with 46 additions and 2 deletions

View File

@ -138,6 +138,9 @@ public:
BaseSerializer() : _firstVersion(0), _lastVersion(INT_MAX) {} BaseSerializer() : _firstVersion(0), _lastVersion(INT_MAX) {}
virtual bool set(osg::Object& /*object*/, void* /*value*/) { return false; }
virtual bool get(const osg::Object& /*object*/, void* /*value*/) { return false; }
virtual bool read( InputStream&, osg::Object& ) = 0; virtual bool read( InputStream&, osg::Object& ) = 0;
virtual bool write( OutputStream&, const osg::Object& ) = 0; virtual bool write( OutputStream&, const osg::Object& ) = 0;
virtual const std::string& getName() const = 0; virtual const std::string& getName() const = 0;
@ -507,6 +510,9 @@ public:
ObjectSerializer( const char* name, P* def, Getter gf, Setter sf ) ObjectSerializer( const char* name, P* def, Getter gf, Setter sf )
: ParentType(name, def), _getter(gf), _setter(sf) {} : ParentType(name, def), _getter(gf), _setter(sf) {}
virtual bool set(osg::Object& obj, void* value) { C& object = OBJECT_CAST<C&>(obj); (object.*_setter)( *(reinterpret_cast<P**>(value)) ); return true; }
virtual bool get(const osg::Object& obj, void* value) { const C& object = OBJECT_CAST<const C&>(obj);*(reinterpret_cast<const P**>(value )) = (object.*_getter)(); return true; }
virtual bool read( InputStream& is, osg::Object& obj ) virtual bool read( InputStream& is, osg::Object& obj )
{ {
C& object = OBJECT_CAST<C&>(obj); C& object = OBJECT_CAST<C&>(obj);

View File

@ -367,13 +367,51 @@ bool PropertyInterface::copyPropertyDataToObject(osg::Object* object, const std:
bool PropertyInterface::copyPropertyObjectFromObject(const osg::Object* object, const std::string& propertyName, void* valuePtr, unsigned int valueSize, osgDB::BaseSerializer::Type valueType) bool PropertyInterface::copyPropertyObjectFromObject(const osg::Object* object, const std::string& propertyName, void* valuePtr, unsigned int valueSize, osgDB::BaseSerializer::Type valueType)
{ {
OSG_NOTICE<<"PropertyInterface::copyPropertyObjectFromObject() Not Supported yet."<<std::endl; OSG_NOTICE<<"PropertyInterface::copyPropertyObjectFromObject() Not Supported yet."<<std::endl;
osgDB::BaseSerializer::Type sourceType;
osgDB::BaseSerializer* serializer = getSerializer(object, propertyName, sourceType);
if (serializer)
{
if (areTypesCompatible(valueType, sourceType))
{
OSG_NOTICE<<"Calling get"<<std::endl;
return serializer->get(*object, valuePtr);
}
else
{
OSG_NOTICE<<"PropertyInterface::copyPropertyObjectFromObject() Types are not compatible, valueType = "<<valueType<<", destinationType="<<sourceType<<std::endl;
return false; return false;
}
}
else
{
OSG_NOTICE<<"PropertyInterface::copyPropertyObjectFromObject() no serializer available."<<std::endl;
return false;
}
} }
bool PropertyInterface::copyPropertyObjectToObject(osg::Object* object, const std::string& propertyName, const void* valuePtr, unsigned int valueSize, osgDB::BaseSerializer::Type valueType) bool PropertyInterface::copyPropertyObjectToObject(osg::Object* object, const std::string& propertyName, const void* valuePtr, unsigned int valueSize, osgDB::BaseSerializer::Type valueType)
{ {
OSG_NOTICE<<"PropertyInterface::copyPropertyObjectToObject() Not Supported yet."<<std::endl; OSG_NOTICE<<"PropertyInterface::copyPropertyObjectToObject() Not Supported yet."<<std::endl;
osgDB::BaseSerializer::Type destinationType;
osgDB::BaseSerializer* serializer = getSerializer(object, propertyName, destinationType);
if (serializer)
{
if (areTypesCompatible(valueType, destinationType))
{
OSG_NOTICE<<"Calling set"<<std::endl;
return serializer->set(*object, const_cast<void*>(valuePtr));
}
else
{
OSG_NOTICE<<"PropertyInterface::copyPropertyObjectToObject() Types are not compatible, valueType = "<<valueType<<", destinationType="<<destinationType<<std::endl;
return false; return false;
}
}
else
{
OSG_NOTICE<<"PropertyInterface::copyPropertyObjectToObject() no serializer available."<<std::endl;
return false;
}
} }