diff --git a/include/osgDB/StreamOperator b/include/osgDB/StreamOperator index f808d2d7d..2813f017c 100644 --- a/include/osgDB/StreamOperator +++ b/include/osgDB/StreamOperator @@ -8,6 +8,9 @@ namespace osgDB { +// forward declare +class InputStream; + class OSGDB_EXPORT OutputIterator : public osg::Referenced { public: @@ -64,12 +67,16 @@ protected: class OSGDB_EXPORT InputIterator : public osg::Referenced { public: - InputIterator() : _in(0), _failed(false) {} + InputIterator() : _in(0), _inputStream(0), _failed(false) {} virtual ~InputIterator() {} void setStream( std::istream* istream ) { _in = istream; } std::istream* getStream() { return _in; } const std::istream* getStream() const { return _in; } + + void setInputStream( InputStream* inputStream) { _inputStream = inputStream; } + InputStream* getInputStream() { return _inputStream; } + const InputStream* getInputStream() const { return _inputStream; } void checkStream() const { if (_in->rdstate()&_in->failbit) _failed = true; } bool isFailed() const { return _failed; } @@ -100,9 +107,12 @@ public: virtual bool matchString( const std::string& /*str*/ ) { return false; } virtual void advanceToCurrentEndBracket() {} - + + void throwException( const std::string& msg ); + protected: - std::istream* _in; + std::istream* _in; + osgDB::InputStream* _inputStream; mutable bool _failed; }; diff --git a/src/osgDB/InputStream.cpp b/src/osgDB/InputStream.cpp index b24917b0e..a86820bfe 100644 --- a/src/osgDB/InputStream.cpp +++ b/src/osgDB/InputStream.cpp @@ -692,6 +692,8 @@ InputStream::ReadType InputStream::start( InputIterator* inIterator ) if ( !_in ) throwException( "InputStream: Null stream specified." ); if ( getException() ) return type; + + _in->setInputStream(this); // Check OSG header information unsigned int version = 0; diff --git a/src/osgPlugins/osg/BinaryStreamOperator.h b/src/osgPlugins/osg/BinaryStreamOperator.h index 77541444d..b8f140141 100644 --- a/src/osgPlugins/osg/BinaryStreamOperator.h +++ b/src/osgPlugins/osg/BinaryStreamOperator.h @@ -145,11 +145,15 @@ public: virtual void readString( std::string& s ) { int size = 0; readInt( size ); - if ( size ) + if ( size>0 ) { s.resize( size ); _in->read( (char*)s.c_str(), size ); } + else if ( size<0 ) + { + throwException( "InputStream::readString() error, negative string size read." ); + } } virtual void readStream( std::istream& (*fn)(std::istream&) ) {}