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."
This commit is contained in:
@@ -31,11 +31,17 @@
|
||||
namespace osgDB
|
||||
{
|
||||
|
||||
class InputException
|
||||
class InputException : public osg::Referenced
|
||||
{
|
||||
public:
|
||||
InputException( const std::string& field, const std::string& err )
|
||||
: _field(field), _error(err) {}
|
||||
InputException( const std::vector<std::string>& fields, const std::string& err ) : _error(err)
|
||||
{
|
||||
for ( unsigned int i=0; i<fields.size(); ++i )
|
||||
{
|
||||
_field += fields[i];
|
||||
_field += " ";
|
||||
}
|
||||
}
|
||||
|
||||
const std::string& getField() const { return _field; }
|
||||
const std::string& getError() const { return _error; }
|
||||
@@ -65,25 +71,25 @@ public:
|
||||
bool getUseFloatMatrix() const { return _useFloatMatrix; }
|
||||
|
||||
// Serialization related functions
|
||||
InputStream& operator>>( bool& b ) { _in->readBool(b); return *this; }
|
||||
InputStream& operator>>( char& c ) { _in->readChar(c); return *this; }
|
||||
InputStream& operator>>( signed char& c ) { _in->readSChar(c); return *this; }
|
||||
InputStream& operator>>( unsigned char& c ) { _in->readUChar(c); return *this; }
|
||||
InputStream& operator>>( short& s ) { _in->readShort(s); return *this; }
|
||||
InputStream& operator>>( unsigned short& s ) { _in->readUShort(s); return *this; }
|
||||
InputStream& operator>>( int& i ) { _in->readInt(i); return *this; }
|
||||
InputStream& operator>>( unsigned int& i ) { _in->readUInt(i); return *this; }
|
||||
InputStream& operator>>( long& l ) { _in->readLong(l); return *this; }
|
||||
InputStream& operator>>( unsigned long& l ) { _in->readULong(l); return *this; }
|
||||
InputStream& operator>>( float& f ) { _in->readFloat(f); return *this; }
|
||||
InputStream& operator>>( double& d ) { _in->readDouble(d); return *this; }
|
||||
InputStream& operator>>( std::string& s ) { _in->readString(s); return *this; }
|
||||
InputStream& operator>>( std::istream& (*fn)(std::istream&) ) { _in->readStream(fn); return *this; }
|
||||
InputStream& operator>>( std::ios_base& (*fn)(std::ios_base&) ) { _in->readBase(fn); return *this; }
|
||||
InputStream& operator>>( bool& b ) { _in->readBool(b); checkStream(); return *this; }
|
||||
InputStream& operator>>( char& c ) { _in->readChar(c); checkStream(); return *this; }
|
||||
InputStream& operator>>( signed char& c ) { _in->readSChar(c); checkStream(); return *this; }
|
||||
InputStream& operator>>( unsigned char& c ) { _in->readUChar(c); checkStream(); return *this; }
|
||||
InputStream& operator>>( short& s ) { _in->readShort(s); checkStream(); return *this; }
|
||||
InputStream& operator>>( unsigned short& s ) { _in->readUShort(s); checkStream(); return *this; }
|
||||
InputStream& operator>>( int& i ) { _in->readInt(i); checkStream(); return *this; }
|
||||
InputStream& operator>>( unsigned int& i ) { _in->readUInt(i); checkStream(); return *this; }
|
||||
InputStream& operator>>( long& l ) { _in->readLong(l); checkStream(); return *this; }
|
||||
InputStream& operator>>( unsigned long& l ) { _in->readULong(l); checkStream(); return *this; }
|
||||
InputStream& operator>>( float& f ) { _in->readFloat(f); checkStream(); return *this; }
|
||||
InputStream& operator>>( double& d ) { _in->readDouble(d); checkStream(); return *this; }
|
||||
InputStream& operator>>( std::string& s ) { _in->readString(s); checkStream(); return *this; }
|
||||
InputStream& operator>>( std::istream& (*fn)(std::istream&) ) { _in->readStream(fn); checkStream(); return *this; }
|
||||
InputStream& operator>>( std::ios_base& (*fn)(std::ios_base&) ) { _in->readBase(fn); checkStream(); return *this; }
|
||||
|
||||
InputStream& operator>>( ObjectGLenum& value ) { _in->readGLenum(value); return *this; }
|
||||
InputStream& operator>>( ObjectProperty& prop ) { _in->readProperty(prop); return *this; }
|
||||
InputStream& operator>>( ObjectMark& mark ) { _in->readMark(mark); return *this; }
|
||||
InputStream& operator>>( ObjectGLenum& value ) { _in->readGLenum(value); checkStream(); return *this; }
|
||||
InputStream& operator>>( ObjectProperty& prop ) { _in->readProperty(prop); checkStream(); return *this; }
|
||||
InputStream& operator>>( ObjectMark& mark ) { _in->readMark(mark); checkStream(); return *this; }
|
||||
|
||||
InputStream& operator>>( osg::Vec2b& v );
|
||||
InputStream& operator>>( osg::Vec3b& v );
|
||||
@@ -116,9 +122,9 @@ public:
|
||||
{ ptr = static_cast<T*>(readObject()); return *this; }
|
||||
|
||||
// Convenient methods for reading
|
||||
inline bool matchString( const std::string& str );
|
||||
inline void advanceToCurrentEndBracket();
|
||||
inline void readWrappedString( std::string& str );
|
||||
bool matchString( const std::string& str );
|
||||
void advanceToCurrentEndBracket();
|
||||
void readWrappedString( std::string& str );
|
||||
void readCharArray( char* s, unsigned int size ) { _in->readCharArray(s, size); }
|
||||
|
||||
// Global reading functions
|
||||
@@ -134,8 +140,12 @@ public:
|
||||
void readSchema( std::istream& fin );
|
||||
void resetSchema();
|
||||
|
||||
// Exception handlers
|
||||
inline void throwException( const std::string& msg );
|
||||
const InputException* getException() const { return _exception.get(); }
|
||||
|
||||
protected:
|
||||
inline void checkStream() const;
|
||||
inline void checkStream();
|
||||
void setWrapperSchema( const std::string& name, const std::string& properties );
|
||||
|
||||
template<typename T>
|
||||
@@ -146,68 +156,22 @@ protected:
|
||||
|
||||
int _byteSwap;
|
||||
bool _useFloatMatrix;
|
||||
std::string _currentField;
|
||||
InputIterator* _in;
|
||||
bool _forceReadingImage;
|
||||
std::vector<std::string> _fields;
|
||||
osg::ref_ptr<InputIterator> _in;
|
||||
osg::ref_ptr<InputException> _exception;
|
||||
};
|
||||
|
||||
bool InputStream::matchString( const std::string& str )
|
||||
void InputStream::throwException( const std::string& msg )
|
||||
{
|
||||
if ( !isBinary() )
|
||||
{
|
||||
std::string s; *this >> s;
|
||||
if ( s==str ) return true;
|
||||
else _in->getStream()->seekg( -(int)(s.length()), std::ios::cur );
|
||||
}
|
||||
return false;
|
||||
_exception = new InputException(_fields, msg);
|
||||
}
|
||||
|
||||
void InputStream::advanceToCurrentEndBracket()
|
||||
{
|
||||
if ( isBinary() )
|
||||
return;
|
||||
|
||||
std::string passString;
|
||||
unsigned int blocks = 0;
|
||||
while ( !_in->getStream()->eof() )
|
||||
{
|
||||
passString.clear();
|
||||
*this >> passString;
|
||||
|
||||
if ( passString=="}" )
|
||||
{
|
||||
if ( blocks<=0 ) return;
|
||||
else blocks--;
|
||||
}
|
||||
else if ( passString=="{" )
|
||||
blocks++;
|
||||
}
|
||||
}
|
||||
|
||||
void InputStream::readWrappedString( std::string& str )
|
||||
{
|
||||
*this >> str;
|
||||
if ( !isBinary() )
|
||||
{
|
||||
if ( str[0]=='\"' )
|
||||
{
|
||||
if ( str.size()==1 || (*str.rbegin())!='\"' )
|
||||
{
|
||||
char ch;
|
||||
do
|
||||
{
|
||||
_in->getStream()->get( ch ); checkStream();
|
||||
str.append( 1, ch );
|
||||
} while ( ch!='\"' );
|
||||
}
|
||||
str = str.substr(1, str.size()-2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void InputStream::checkStream() const
|
||||
void InputStream::checkStream()
|
||||
{
|
||||
_in->checkStream();
|
||||
if ( _in->isFailed() )
|
||||
throw InputException(_currentField, "InputStream: Failed to read from stream.");
|
||||
throwException( "InputStream: Failed to read from stream." );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user