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

Revision 13041, 4.4 kB (checked in by robert, 2 years ago)

Ran script to remove trailing spaces and tabs

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1#ifndef OSGDB_STREAMOPERATOR
2#define OSGDB_STREAMOPERATOR
3
4#include <iostream>
5#include <sstream>
6#include <osg/Referenced>
7#include <osgDB/Export>
8#include <osgDB/DataTypes>
9
10namespace osgDB
11{
12
13// forward declare
14class InputStream;
15
16class OSGDB_EXPORT OutputIterator : public osg::Referenced
17{
18public:
19    OutputIterator() : _out(0) {}
20    virtual ~OutputIterator() {}
21
22    void setStream( std::ostream* ostream ) { _out = ostream; }
23    std::ostream* getStream() { return _out; }
24    const std::ostream* getStream() const { return _out; }
25
26    virtual bool isBinary() const = 0;
27
28    virtual void writeBool( bool b ) = 0;
29    virtual void writeChar( char c ) = 0;
30    virtual void writeUChar( unsigned char c ) = 0;
31    virtual void writeShort( short s ) = 0;
32    virtual void writeUShort( unsigned short s ) = 0;
33    virtual void writeInt( int i ) = 0;
34    virtual void writeUInt( unsigned int i ) = 0;
35    virtual void writeLong( long l ) = 0;
36    virtual void writeULong( unsigned long l ) = 0;
37    virtual void writeFloat( float f ) = 0;
38    virtual void writeDouble( double d ) = 0;
39    virtual void writeString( const std::string& s ) = 0;
40    virtual void writeStream( std::ostream& (*fn)(std::ostream&) ) = 0;
41    virtual void writeBase( std::ios_base& (*fn)(std::ios_base&) ) = 0;
42
43    virtual void writeGLenum( const ObjectGLenum& value ) = 0;
44    virtual void writeProperty( const ObjectProperty& prop ) = 0;
45    virtual void writeMark( const ObjectMark& mark ) = 0;
46    virtual void writeCharArray( const char* s, unsigned int size ) = 0;
47    virtual void writeWrappedString( const std::string& str ) = 0;
48
49    virtual void flush() { _out->flush(); }
50
51protected:
52    // Return true if the manipulator is std::endl
53    bool isEndl( std::ostream& (*fn)(std::ostream&) )
54    {
55#ifdef __sun
56        // What a mess, but solaris does not like taking the address below
57        std::stringstream ss;
58        ss << fn;
59        std::string s = ss.str();
60        return !s.empty() && s[0] == '\n';
61#else
62        return fn==static_cast<std::ostream& (*)(std::ostream&)>(std::endl);
63#endif
64    }
65
66    std::ostream* _out;
67};
68
69class OSGDB_EXPORT InputIterator : public osg::Referenced
70{
71public:
72    InputIterator() : _in(0), _inputStream(0), _byteSwap(0), _failed(false) {}
73    virtual ~InputIterator() {}
74
75    void setStream( std::istream* istream ) { _in = istream; }
76    std::istream* getStream() { return _in; }
77    const std::istream* getStream() const { return _in; }
78
79    void setInputStream( InputStream* inputStream) { _inputStream = inputStream; }
80    InputStream* getInputStream() { return _inputStream; }
81    const InputStream* getInputStream() const { return _inputStream; }
82
83    void setByteSwap(int byteSwap) { _byteSwap = byteSwap; }
84    int getByteSwap() const { return _byteSwap; }
85
86    void checkStream() const { if (_in->rdstate()&_in->failbit) _failed = true; }
87    bool isFailed() const { return _failed; }
88
89    virtual bool isBinary() const = 0;
90
91    virtual void readBool( bool& b ) = 0;
92    virtual void readChar( char& c ) = 0;
93    virtual void readSChar( signed char& c ) = 0;
94    virtual void readUChar( unsigned char& c ) = 0;
95    virtual void readShort( short& s ) = 0;
96    virtual void readUShort( unsigned short& s ) = 0;
97    virtual void readInt( int& i ) = 0;
98    virtual void readUInt( unsigned int& i ) = 0;
99    virtual void readLong( long& l ) = 0;
100    virtual void readULong( unsigned long& l ) = 0;
101    virtual void readFloat( float& f ) = 0;
102    virtual void readDouble( double& d ) = 0;
103    virtual void readString( std::string& s ) = 0;
104    virtual void readStream( std::istream& (*fn)(std::istream&) ) = 0;
105    virtual void readBase( std::ios_base& (*fn)(std::ios_base&) ) = 0;
106
107    virtual void readGLenum( ObjectGLenum& value ) = 0;
108    virtual void readProperty( ObjectProperty& prop ) = 0;
109    virtual void readMark( ObjectMark& mark ) = 0;
110    virtual void readCharArray( char* s, unsigned int size ) = 0;
111    virtual void readWrappedString( std::string& str ) = 0;
112
113    virtual bool matchString( const std::string& /*str*/ ) { return false; }
114    virtual void advanceToCurrentEndBracket() {}
115
116    void throwException( const std::string& msg );
117
118    void readComponentArray( char* s, unsigned int numElements, unsigned int numComponentsPerElements, unsigned int componentSizeInBytes);
119
120protected:
121    std::istream*       _in;
122    osgDB::InputStream* _inputStream;
123    int                 _byteSwap;
124    mutable bool        _failed;
125};
126
127}
128
129#endif
Note: See TracBrowser for help on using the browser.