From de040e44a0f95d27f418e7a8f343f8fc76c2e229 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 16 May 2011 08:50:59 +0000 Subject: [PATCH] From Rafa Gata, I've been playing around with serializers in order to use it as a "generic" property mechanism for osg::Object. The main problem I have found is that InputStream and OutputStream only takes the stream when you call start method, and in that case it attaches to the stream buffer some stuff, useful for files but not for runtime/gui usage. I have added a simple setInputIterator and setOutputIterator to the classes so now you can easily serialize values without version and other stuff. Writing matrix: osgDB::OutputStream os(0); std::stringstream sstream; os.setOutputIterator(new AsciiOutputIterator(&sstream)); os << matrix; std::string value = sstream.str(); Reading matrix: osgDB::InputStream is(0); std::stringstream sstream(value); is.setInputIterator(new AsciiInputIterator(&sstream)); osg::Matrixf mat2; is >> mat2; From Robert Osfield, added doxygen comments to clarify the role of the methods. --- include/osgDB/InputStream | 7 ++++++- include/osgDB/OutputStream | 5 +++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/include/osgDB/InputStream b/include/osgDB/InputStream index 0b0c70817..af431f46c 100644 --- a/include/osgDB/InputStream +++ b/include/osgDB/InputStream @@ -139,8 +139,13 @@ public: osg::Image* readImage(bool readFromExternal=true); osg::Object* readObject( osg::Object* existingObj=0 ); osg::Object* readObjectFields( const std::string& className, osg::Object* existingObj=0); - + + /// set an input iterator, used directly when not using InputStream with a traditional file releated stream. + void setInputIterator( InputIterator* ii ) { _in = ii; } + + /// start reading from InputStream treating it as a traditional file releated stream, handles headers and versioning ReadType start( InputIterator* ); + void decompress(); // Schema handlers diff --git a/include/osgDB/OutputStream b/include/osgDB/OutputStream index 275840462..21baa0fb0 100644 --- a/include/osgDB/OutputStream +++ b/include/osgDB/OutputStream @@ -149,7 +149,12 @@ public: void writeObject( const osg::Object* obj ); void writeObjectFields( const osg::Object* obj ); + /// set an output iterator, used directly when not using OutputStream with a traditional file releated stream. + void setOutputIterator( OutputIterator* oi ) { _out = oi; } + + /// start writing to OutputStream treating it as a traditional file releated stream, handles headers and versioning void start( OutputIterator* outIterator, WriteType type ); + void compress( std::ostream* ostream ); // Schema handlers