StreamOperator
Go to the documentation of this file.
#ifndef OSGDB_STREAMOPERATOR
#define OSGDB_STREAMOPERATOR
#include <iostream>
#include <sstream>
#include <osg/Referenced>
#include <osgDB/Export>
#include <osgDB/DataTypes>
namespace osgDB
{
// forward declare
class InputStream;
class OutputStream;
class OSGDB_EXPORT OutputIterator : public osg::Referenced
{
public:
OutputIterator() : _out(0), _outputStream(0), _supportBinaryBrackets(false) {}
virtual ~OutputIterator() {}
void setStream( std::ostream* ostream ) { _out = ostream; }
std::ostream* getStream() { return _out; }
const std::ostream* getStream() const { return _out; }
void setOutputStream( OutputStream* outputStream) { _outputStream = outputStream; }
OutputStream* getOutputStream() { return _outputStream; }
const OutputStream* getOutputStream() const { return _outputStream; }
void setSupportBinaryBrackets( bool b ) { _supportBinaryBrackets = b; }
bool getSupportBinaryBrackets() const { return _supportBinaryBrackets; }
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 writeInt64( GLint64 ll ) = 0;
virtual void writeUInt64( GLuint64 ull ) = 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;
virtual void writeWrappedString( const std::string& str ) = 0;
virtual void flush() { _out->flush(); }
protected:
// Return true if the manipulator is std::endl
bool isEndl( std::ostream& (*fn)(std::ostream&) )
{
#if defined (__sun) || (defined _WIN32 && !defined OSG_LIBRARY_STATIC)
// What a mess, but solaris does not like taking the address below
// windows std::endl is a template with different adresses in different dll's
std::stringstream ss;
ss << fn;
std::string s = ss.str();
return !s.empty() && s[0] == '\n';
#else
return fn==static_cast<std::ostream& (*)(std::ostream&)>(std::endl);
#endif
}
std::ostream* _out;
osgDB::OutputStream* _outputStream;
bool _supportBinaryBrackets;
};
class OSGDB_EXPORT InputIterator : public osg::Referenced
{
public:
InputIterator() : _in(0), _inputStream(0), _byteSwap(0), _supportBinaryBrackets(false), _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 setByteSwap(int byteSwap) { _byteSwap = byteSwap; }
int getByteSwap() const { return _byteSwap; }
void setSupportBinaryBrackets( bool b ) { _supportBinaryBrackets = b; }
bool getSupportBinaryBrackets() const { return _supportBinaryBrackets; }
void checkStream() const;
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;
virtual void readWrappedString( std::string& str ) = 0;
virtual bool matchString( const std::string& /*str*/ ) { return false; }
virtual void advanceToCurrentEndBracket() {}
void throwException( const std::string& msg );
void readComponentArray( char* s, unsigned int numElements, unsigned int numComponentsPerElements, unsigned int componentSizeInBytes);
protected:
std::istream* _in;
osgDB::InputStream* _inputStream;
int _byteSwap;
bool _supportBinaryBrackets;
mutable bool _failed;
};
}
#endif
DataTypes
Referenced
osgDB::InputIterator::_supportBinaryBrackets
bool _supportBinaryBrackets
Definition StreamOperator:140
osgDB::InputIterator::isFailed
bool isFailed() const
Definition StreamOperator:103
osgDB::InputIterator::getStream
std::istream * getStream()
Definition StreamOperator:89
osgDB::InputIterator::getByteSwap
int getByteSwap() const
Definition StreamOperator:97
osgDB::InputIterator::readProperty
virtual void readProperty(ObjectProperty &prop)=0
osgDB::InputIterator::readChar
virtual void readChar(char &c)=0
osgDB::InputIterator::readGLenum
virtual void readGLenum(ObjectGLenum &value)=0
osgDB::InputIterator::readULong
virtual void readULong(unsigned long &l)=0
osgDB::InputIterator::readComponentArray
void readComponentArray(char *s, unsigned int numElements, unsigned int numComponentsPerElements, unsigned int componentSizeInBytes)
osgDB::InputIterator::readUChar
virtual void readUChar(unsigned char &c)=0
osgDB::InputIterator::throwException
void throwException(const std::string &msg)
osgDB::InputIterator::getSupportBinaryBrackets
bool getSupportBinaryBrackets() const
Definition StreamOperator:100
osgDB::InputIterator::getStream
const std::istream * getStream() const
Definition StreamOperator:90
osgDB::InputIterator::readFloat
virtual void readFloat(float &f)=0
osgDB::InputIterator::setInputStream
void setInputStream(InputStream *inputStream)
Definition StreamOperator:92
osgDB::InputIterator::setByteSwap
void setByteSwap(int byteSwap)
Definition StreamOperator:96
osgDB::InputIterator::readShort
virtual void readShort(short &s)=0
osgDB::InputIterator::_in
std::istream * _in
Definition StreamOperator:137
osgDB::InputIterator::_byteSwap
int _byteSwap
Definition StreamOperator:139
osgDB::InputIterator::readString
virtual void readString(std::string &s)=0
osgDB::InputIterator::readStream
virtual void readStream(std::istream &(*fn)(std::istream &))=0
osgDB::InputIterator::readLong
virtual void readLong(long &l)=0
osgDB::InputIterator::readUInt
virtual void readUInt(unsigned int &i)=0
osgDB::InputIterator::readWrappedString
virtual void readWrappedString(std::string &str)=0
osgDB::InputIterator::readInt
virtual void readInt(int &i)=0
osgDB::InputIterator::setStream
void setStream(std::istream *istream)
Definition StreamOperator:88
osgDB::InputIterator::_inputStream
osgDB::InputStream * _inputStream
Definition StreamOperator:138
osgDB::InputIterator::isBinary
virtual bool isBinary() const =0
osgDB::InputIterator::getInputStream
InputStream * getInputStream()
Definition StreamOperator:93
osgDB::InputIterator::checkStream
void checkStream() const
osgDB::InputIterator::readUShort
virtual void readUShort(unsigned short &s)=0
osgDB::InputIterator::InputIterator
InputIterator()
Definition StreamOperator:85
osgDB::InputIterator::readSChar
virtual void readSChar(signed char &c)=0
osgDB::InputIterator::advanceToCurrentEndBracket
virtual void advanceToCurrentEndBracket()
Definition StreamOperator:130
osgDB::InputIterator::readCharArray
virtual void readCharArray(char *s, unsigned int size)=0
osgDB::InputIterator::_failed
bool _failed
Definition StreamOperator:141
osgDB::InputIterator::setSupportBinaryBrackets
void setSupportBinaryBrackets(bool b)
Definition StreamOperator:99
osgDB::InputIterator::~InputIterator
virtual ~InputIterator()
Definition StreamOperator:86
osgDB::InputIterator::readBase
virtual void readBase(std::ios_base &(*fn)(std::ios_base &))=0
osgDB::InputIterator::readMark
virtual void readMark(ObjectMark &mark)=0
osgDB::InputIterator::readBool
virtual void readBool(bool &b)=0
osgDB::InputIterator::getInputStream
const InputStream * getInputStream() const
Definition StreamOperator:94
osgDB::InputIterator::matchString
virtual bool matchString(const std::string &)
Definition StreamOperator:129
osgDB::InputIterator::readDouble
virtual void readDouble(double &d)=0
osgDB::InputStream
Definition InputStream:64
osgDB::ObjectMark
Definition DataTypes:129
osgDB::ObjectProperty
Definition DataTypes:105
osgDB::OutputIterator::writeString
virtual void writeString(const std::string &s)=0
osgDB::OutputIterator::isBinary
virtual bool isBinary() const =0
osgDB::OutputIterator::isEndl
bool isEndl(std::ostream &(*fn)(std::ostream &))
Definition StreamOperator:63
osgDB::OutputIterator::getOutputStream
OutputStream * getOutputStream()
Definition StreamOperator:28
osgDB::OutputIterator::writeInt64
virtual void writeInt64(GLint64 ll)=0
osgDB::OutputIterator::getStream
std::ostream * getStream()
Definition StreamOperator:24
osgDB::OutputIterator::writeWrappedString
virtual void writeWrappedString(const std::string &str)=0
osgDB::OutputIterator::writeGLenum
virtual void writeGLenum(const ObjectGLenum &value)=0
osgDB::OutputIterator::writeUShort
virtual void writeUShort(unsigned short s)=0
osgDB::OutputIterator::OutputIterator
OutputIterator()
Definition StreamOperator:20
osgDB::OutputIterator::_outputStream
osgDB::OutputStream * _outputStream
Definition StreamOperator:78
osgDB::OutputIterator::~OutputIterator
virtual ~OutputIterator()
Definition StreamOperator:21
osgDB::OutputIterator::writeChar
virtual void writeChar(char c)=0
osgDB::OutputIterator::writeMark
virtual void writeMark(const ObjectMark &mark)=0
osgDB::OutputIterator::writeUInt64
virtual void writeUInt64(GLuint64 ull)=0
osgDB::OutputIterator::getSupportBinaryBrackets
bool getSupportBinaryBrackets() const
Definition StreamOperator:32
osgDB::OutputIterator::flush
virtual void flush()
Definition StreamOperator:59
osgDB::OutputIterator::writeDouble
virtual void writeDouble(double d)=0
osgDB::OutputIterator::setOutputStream
void setOutputStream(OutputStream *outputStream)
Definition StreamOperator:27
osgDB::OutputIterator::writeBool
virtual void writeBool(bool b)=0
osgDB::OutputIterator::writeLong
virtual void writeLong(long l)=0
osgDB::OutputIterator::writeCharArray
virtual void writeCharArray(const char *s, unsigned int size)=0
osgDB::OutputIterator::_supportBinaryBrackets
bool _supportBinaryBrackets
Definition StreamOperator:79
osgDB::OutputIterator::writeUInt
virtual void writeUInt(unsigned int i)=0
osgDB::OutputIterator::writeShort
virtual void writeShort(short s)=0
osgDB::OutputIterator::writeBase
virtual void writeBase(std::ios_base &(*fn)(std::ios_base &))=0
osgDB::OutputIterator::writeFloat
virtual void writeFloat(float f)=0
osgDB::OutputIterator::writeStream
virtual void writeStream(std::ostream &(*fn)(std::ostream &))=0
osgDB::OutputIterator::setSupportBinaryBrackets
void setSupportBinaryBrackets(bool b)
Definition StreamOperator:31
osgDB::OutputIterator::writeULong
virtual void writeULong(unsigned long l)=0
osgDB::OutputIterator::writeUChar
virtual void writeUChar(unsigned char c)=0
osgDB::OutputIterator::writeInt
virtual void writeInt(int i)=0
osgDB::OutputIterator::getOutputStream
const OutputStream * getOutputStream() const
Definition StreamOperator:29
osgDB::OutputIterator::writeProperty
virtual void writeProperty(const ObjectProperty &prop)=0
osgDB::OutputIterator::getStream
const std::ostream * getStream() const
Definition StreamOperator:25
osgDB::OutputIterator::setStream
void setStream(std::ostream *ostream)
Definition StreamOperator:23
osgDB::OutputIterator::_out
std::ostream * _out
Definition StreamOperator:77
osgDB::OutputStream
Definition OutputStream:57
osg::Referenced
Definition Referenced:44
osgDB
Definition Archive:24
Export
OSGDB_EXPORT
#define OSGDB_EXPORT
Definition osgDB/Export:39
osgDB::ObjectGLenum
Definition DataTypes:94