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.
This commit is contained in:
Robert Osfield 2011-05-16 08:50:59 +00:00
parent c4dff10cb4
commit de040e44a0
2 changed files with 11 additions and 1 deletions

View File

@ -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

View File

@ -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