From f1b660997beea54056121873de960559fe1fe3dd Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 28 Oct 2010 14:04:07 +0000 Subject: [PATCH] Added FinishedObjectReadCallback to ObjectWrapper which allows wrappers to register their own handling of post processing of objects once they have been read. --- include/osgDB/ObjectWrapper | 10 ++++++++++ src/osgDB/ObjectWrapper.cpp | 8 ++++++++ 2 files changed, 18 insertions(+) diff --git a/include/osgDB/ObjectWrapper b/include/osgDB/ObjectWrapper index c78c95163..0e8a94b6a 100644 --- a/include/osgDB/ObjectWrapper +++ b/include/osgDB/ObjectWrapper @@ -37,10 +37,16 @@ protected: std::string _name; }; +struct FinishedObjectReadCallback : public osg::Referenced +{ + virtual void objectRead(osgDB::InputStream& is, osg::Object& obj) = 0; +}; + class OSGDB_EXPORT ObjectWrapper : public osg::Referenced { public: typedef std::vector< osg::ref_ptr > SerializerList; + typedef std::vector< osg::ref_ptr > FinishedObjectReadCallbackList; ObjectWrapper( osg::Object* proto, const std::string& name, const std::string& associates ); @@ -50,6 +56,9 @@ public: const StringList& getAssociates() const { return _associates; } void addSerializer( BaseSerializer* s ) { _serializers.push_back(s); } + void addFinishedObjectReadCallback ( FinishedObjectReadCallback* forc) { _finishedObjectReadCallbacks.push_back(forc); } + + bool read( InputStream&, osg::Object& ); bool write( OutputStream&, const osg::Object& ); @@ -67,6 +76,7 @@ protected: StringList _associates; SerializerList _serializers; SerializerList _backupSerializers; + FinishedObjectReadCallbackList _finishedObjectReadCallbacks; }; class Registry; diff --git a/src/osgDB/ObjectWrapper.cpp b/src/osgDB/ObjectWrapper.cpp index 58766dc28..39cb75096 100644 --- a/src/osgDB/ObjectWrapper.cpp +++ b/src/osgDB/ObjectWrapper.cpp @@ -102,6 +102,14 @@ bool ObjectWrapper::read( InputStream& is, osg::Object& obj ) << _name << "::" << (*itr)->getName() << std::endl; readOK = false; } + + for ( FinishedObjectReadCallbackList::iterator itr=_finishedObjectReadCallbacks.begin(); + itr!=_finishedObjectReadCallbacks.end(); + ++itr ) + { + (*itr)->objectRead(is, obj); + } + return readOK; }