Show
Ignore:
Timestamp:
01/27/10 18:09:05 (5 years ago)
Author:
robert
Message:

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

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/src/osgDB/OutputStream.cpp

    r10986 r11018  
    2323 
    2424OutputStream::OutputStream( const osgDB::Options* options ) 
    25 :   _writeImageHint(WRITE_USE_IMAGE_HINT), 
    26     _out(0) 
     25:   _writeImageHint(WRITE_USE_IMAGE_HINT) 
    2726{ 
    2827    if ( !options ) return; 
     
    4443             
    4544            if ( keyAndValues[0]=="SchemaFile" ) 
    46             { 
    47                 osgDB::ofstream schemaStream( keyAndValues[1].c_str(), std::ios::out ); 
    48                 if ( !schemaStream.fail() ) writeSchema( schemaStream ); 
    49                 schemaStream.close(); 
    50             } 
     45                _schemaName = keyAndValues[1]; 
    5146            else if ( keyAndValues[0]=="Compressor" ) 
    5247                _compressorName = keyAndValues[1]; 
     
    137132} 
    138133 
     134void OutputStream::writeWrappedString( const std::string& str ) 
     135{ 
     136    if ( !isBinary() ) 
     137    { 
     138        std::string wrappedStr; 
     139        unsigned int size = str.size(); 
     140        for ( unsigned int i=0; i<size; ++i ) 
     141        { 
     142            char ch = str[i]; 
     143            if ( ch=='\"' ) wrappedStr += '\\'; 
     144            else if ( ch=='\\' ) wrappedStr += '\\'; 
     145            wrappedStr += ch; 
     146        } 
     147         
     148        wrappedStr.insert( 0, 1, '\"' ); 
     149        wrappedStr += '\"'; 
     150        *this << wrappedStr; 
     151    } 
     152    else 
     153        *this << str; 
     154} 
     155 
    139156void OutputStream::writeArray( const osg::Array* a ) 
    140157{ 
     
    236253        break; 
    237254    default: 
    238         throw OutputException(_currentField, "OutputStream::writeArray(): Unsupported array type."); 
     255        throwException( "OutputStream::writeArray(): Unsupported array type." ); 
    239256    } 
    240257} 
     
    287304        break; 
    288305    default: 
    289         throw OutputException(_currentField, "OutputStream::writePrimitiveSet(): Unsupported primitive type."); 
     306        throwException( "OutputStream::writePrimitiveSet(): Unsupported primitive type." ); 
    290307    } 
    291308} 
     
    297314    *this << PROPERTY("FileName"); writeWrappedString(img->getFileName()); *this << std::endl; 
    298315    *this << PROPERTY("WriteHint") << (int)img->getWriteHint(); 
     316    if ( getException() ) return; 
    299317     
    300318    int decision = IMAGE_EXTERNAL; 
     
    368386                    char* data = new char[size]; 
    369387                    if ( !data ) 
    370                         throw OutputException(_currentField, "OutputStream::writeImage(): Out of memory."); 
     388                        throwException( "OutputStream::writeImage(): Out of memory." ); 
     389                    if ( getException() ) return; 
     390                     
    371391                    infile.seekg( 0, std::ios::beg ); 
    372392                    infile.read( data, size ); 
     
    389409        break; 
    390410    } 
    391      
    392411    writeObject( img ); 
    393412} 
     
    403422    *this << name << BEGIN_BRACKET << std::endl;       // Write object name 
    404423    *this << PROPERTY("UniqueID") << id << std::endl;  // Write object ID 
     424    if ( getException() ) return; 
    405425     
    406426    // Check whether this is a shared object or not 
     
    415435            return; 
    416436        } 
     437        _fields.push_back( name ); 
    417438         
    418439        const StringList& associates = wrapper->getAssociates(); 
     
    426447                continue; 
    427448            } 
     449            _fields.push_back( assocWrapper->getName() ); 
    428450             
    429             _currentField = assocWrapper->getName(); 
    430451            assocWrapper->write( *this, *obj ); 
    431         } 
     452            if ( getException() ) return; 
     453             
     454            _fields.pop_back(); 
     455        } 
     456        _fields.pop_back(); 
    432457    } 
    433458    *this << END_BRACKET << std::endl; 
     
    436461void OutputStream::start( OutputIterator* outIterator, OutputStream::WriteType type ) 
    437462{ 
    438     _currentField = "Header"; 
     463    _fields.clear(); 
     464    _fields.push_back( "Start" ); 
     465     
    439466    _out = outIterator; 
    440467    if ( !_out ) 
    441         throw OutputException(_currentField, "OutputStream: Null stream specified."); 
     468        throwException( "OutputStream: Null stream specified." ); 
     469    if ( getException() ) return; 
    442470     
    443471    if ( isBinary() ) 
    444472    { 
    445         *this << (unsigned int)OSG_HEADER_LOW << (unsigned int)OSG_HEADER_HIGH 
    446               << (unsigned int)type << (unsigned int)PLUGIN_VERSION; 
     473        *this << (unsigned int)type << (unsigned int)PLUGIN_VERSION; 
    447474         
    448475        if ( sizeof(osg::Matrix::value_type)==FLOAT_SIZE ) *this << (unsigned int)0; 
     
    477504        } 
    478505         
    479         *this << PROPERTY("#Ascii") << typeString << std::endl; 
     506        *this << typeString << std::endl; 
    480507        *this << PROPERTY("#Version") << (unsigned int)PLUGIN_VERSION << std::endl; 
    481508        *this << PROPERTY("#Generator") << std::string("OpenSceneGraph") 
     
    483510        *this << std::endl; 
    484511    } 
     512    _fields.pop_back(); 
    485513} 
    486514 
    487515void OutputStream::compress( std::ostream* ostream ) 
    488516{ 
    489     _currentField = "Compression"; 
     517    _fields.clear(); 
     518    _fields.push_back( "Compression" ); 
    490519    if ( _compressorName.empty() || !isBinary() ) return; 
    491520     
     
    494523     
    495524    if ( !compressor->compress(*ostream, _compressSource.str()) ) 
    496         throw OutputException(_currentField, "OutputStream: Failed to compress stream."); 
    497 } 
    498  
    499 // PROTECTED METHODS 
     525        throwException( "OutputStream: Failed to compress stream." ); 
     526    _fields.pop_back(); 
     527} 
    500528 
    501529void OutputStream::writeSchema( std::ostream& fout ) 
     
    522550} 
    523551 
     552// PROTECTED METHODS 
     553 
    524554template<typename T> 
    525555void OutputStream::writeArrayImplementation( const T* a, int writeSize, unsigned int numInRow )