OpenSceneGraph/include/osgDB/StreamOperator
Robert Osfield 0a9263d50e From Wang Rui, "Changes:
1. Rewrite the reading/writing exception handlers to work like the ive
plugin exceptions.
2. Write a header writing/checking function in ReaderWriterOSG2.cpp,
which may help decide if the stream is ascii or binary. The
readInputIterator() function will return null pointer if the input
file is nither osgb nor osgt format, which indicates that the old .osg
format could be used here, in case we've merged the two plugins
together.
3. Add a new ForceReadingImage option in the InputStream, which will
allocate an empty image object with the filename if specifed external
image file is missed. It may be useful for format converting in some
cases.
4. Add new osgParticle wrappers, as well as some modification to the
osgParticle headers, for instance, change isEnabled() to getEnabled().
5. Some fixes to the osg serialization wrappers."
2010-01-27 17:09:05 +00:00

91 lines
3.0 KiB
Plaintext

#ifndef OSGDB_STREAMOPERATOR
#define OSGDB_STREAMOPERATOR
#include <iostream>
#include <sstream>
#include <osgDB/DataTypes>
namespace osgDB
{
class OSGDB_EXPORT OutputIterator : public osg::Referenced
{
public:
OutputIterator() : _out(0) {}
virtual ~OutputIterator() {}
void setStream( std::ostream* ostream ) { _out = ostream; }
std::ostream* getStream() { return _out; }
const std::ostream* getStream() const { return _out; }
virtual bool isBinary() const = 0;
virtual void writeBool( bool b ) = 0;
virtual void writeChar( char c ) = 0;
virtual void writeUChar( unsigned char c ) = 0;
virtual void writeShort( short s ) = 0;
virtual void writeUShort( unsigned short s ) = 0;
virtual void writeInt( int i ) = 0;
virtual void writeUInt( unsigned int i ) = 0;
virtual void writeLong( long l ) = 0;
virtual void writeULong( unsigned long l ) = 0;
virtual void writeFloat( float f ) = 0;
virtual void writeDouble( double d ) = 0;
virtual void writeString( const std::string& s ) = 0;
virtual void writeStream( std::ostream& (*fn)(std::ostream&) ) = 0;
virtual void writeBase( std::ios_base& (*fn)(std::ios_base&) ) = 0;
virtual void writeGLenum( const ObjectGLenum& value ) = 0;
virtual void writeProperty( const ObjectProperty& prop ) = 0;
virtual void writeMark( const ObjectMark& mark ) = 0;
virtual void writeCharArray( const char* s, unsigned int size ) = 0;
protected:
std::ostream* _out;
};
class OSGDB_EXPORT InputIterator : public osg::Referenced
{
public:
InputIterator() : _in(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 checkStream() const { if (_in->rdstate()&_in->failbit) _failed = true; }
bool isFailed() const { return _failed; }
virtual bool isBinary() const = 0;
virtual void readBool( bool& b ) = 0;
virtual void readChar( char& c ) = 0;
virtual void readSChar( signed char& c ) = 0;
virtual void readUChar( unsigned char& c ) = 0;
virtual void readShort( short& s ) = 0;
virtual void readUShort( unsigned short& s ) = 0;
virtual void readInt( int& i ) = 0;
virtual void readUInt( unsigned int& i ) = 0;
virtual void readLong( long& l ) = 0;
virtual void readULong( unsigned long& l ) = 0;
virtual void readFloat( float& f ) = 0;
virtual void readDouble( double& d ) = 0;
virtual void readString( std::string& s ) = 0;
virtual void readStream( std::istream& (*fn)(std::istream&) ) = 0;
virtual void readBase( std::ios_base& (*fn)(std::ios_base&) ) = 0;
virtual void readGLenum( ObjectGLenum& value ) = 0;
virtual void readProperty( ObjectProperty& prop ) = 0;
virtual void readMark( ObjectMark& mark ) = 0;
virtual void readCharArray( char* s, unsigned int size ) = 0;
protected:
std::istream* _in;
mutable bool _failed;
};
}
#endif