root/OpenSceneGraph/trunk/include/osgDB/StreamOperator @ 11018

Revision 11018, 3.0 kB (checked in by robert, 4 years ago)

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."

Line 
1#ifndef OSGDB_STREAMOPERATOR
2#define OSGDB_STREAMOPERATOR
3
4#include <iostream>
5#include <sstream>
6#include <osgDB/DataTypes>
7
8namespace osgDB
9{
10
11class OSGDB_EXPORT OutputIterator : public osg::Referenced
12{
13public:
14    OutputIterator() : _out(0) {}
15    virtual ~OutputIterator() {}
16   
17    void setStream( std::ostream* ostream ) { _out = ostream; }
18    std::ostream* getStream() { return _out; }
19    const std::ostream* getStream() const { return _out; }
20   
21    virtual bool isBinary() const = 0;
22   
23    virtual void writeBool( bool b ) = 0;
24    virtual void writeChar( char c ) = 0;
25    virtual void writeUChar( unsigned char c ) = 0;
26    virtual void writeShort( short s ) = 0;
27    virtual void writeUShort( unsigned short s ) = 0;
28    virtual void writeInt( int i ) = 0;
29    virtual void writeUInt( unsigned int i ) = 0;
30    virtual void writeLong( long l ) = 0;
31    virtual void writeULong( unsigned long l ) = 0;
32    virtual void writeFloat( float f ) = 0;
33    virtual void writeDouble( double d ) = 0;
34    virtual void writeString( const std::string& s ) = 0;
35    virtual void writeStream( std::ostream& (*fn)(std::ostream&) ) = 0;
36    virtual void writeBase( std::ios_base& (*fn)(std::ios_base&) ) = 0;
37   
38    virtual void writeGLenum( const ObjectGLenum& value ) = 0;
39    virtual void writeProperty( const ObjectProperty& prop ) = 0;
40    virtual void writeMark( const ObjectMark& mark ) = 0;
41    virtual void writeCharArray( const char* s, unsigned int size ) = 0;
42   
43protected:
44    std::ostream* _out;
45};
46
47class OSGDB_EXPORT InputIterator : public osg::Referenced
48{
49public:
50    InputIterator() : _in(0), _failed(false) {}
51    virtual ~InputIterator() {}
52   
53    void setStream( std::istream* istream ) { _in = istream; }
54    std::istream* getStream() { return _in; }
55    const std::istream* getStream() const { return _in; }
56   
57    void checkStream() const { if (_in->rdstate()&_in->failbit) _failed = true; }
58    bool isFailed() const { return _failed; }
59   
60    virtual bool isBinary() const = 0;
61   
62    virtual void readBool( bool& b ) = 0;
63    virtual void readChar( char& c ) = 0;
64    virtual void readSChar( signed char& c ) = 0;
65    virtual void readUChar( unsigned char& c ) = 0;
66    virtual void readShort( short& s ) = 0;
67    virtual void readUShort( unsigned short& s ) = 0;
68    virtual void readInt( int& i ) = 0;
69    virtual void readUInt( unsigned int& i ) = 0;
70    virtual void readLong( long& l ) = 0;
71    virtual void readULong( unsigned long& l ) = 0;
72    virtual void readFloat( float& f ) = 0;
73    virtual void readDouble( double& d ) = 0;
74    virtual void readString( std::string& s ) = 0;
75    virtual void readStream( std::istream& (*fn)(std::istream&) ) = 0;
76    virtual void readBase( std::ios_base& (*fn)(std::ios_base&) ) = 0;
77   
78    virtual void readGLenum( ObjectGLenum& value ) = 0;
79    virtual void readProperty( ObjectProperty& prop ) = 0;
80    virtual void readMark( ObjectMark& mark ) = 0;
81    virtual void readCharArray( char* s, unsigned int size ) = 0;
82   
83protected:
84    std::istream* _in;
85    mutable bool _failed;
86};
87
88}
89
90#endif
Note: See TracBrowser for help on using the browser.