Changeset 11018 for OpenSceneGraph/trunk/src/osgDB/OutputStream.cpp
- Timestamp:
- 01/27/10 18:09:05 (3 years ago)
- Files:
-
- 1 modified
-
OpenSceneGraph/trunk/src/osgDB/OutputStream.cpp (modified) (16 diffs)
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/src/osgDB/OutputStream.cpp
r10986 r11018 23 23 24 24 OutputStream::OutputStream( const osgDB::Options* options ) 25 : _writeImageHint(WRITE_USE_IMAGE_HINT), 26 _out(0) 25 : _writeImageHint(WRITE_USE_IMAGE_HINT) 27 26 { 28 27 if ( !options ) return; … … 44 43 45 44 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]; 51 46 else if ( keyAndValues[0]=="Compressor" ) 52 47 _compressorName = keyAndValues[1]; … … 137 132 } 138 133 134 void 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 139 156 void OutputStream::writeArray( const osg::Array* a ) 140 157 { … … 236 253 break; 237 254 default: 238 throw OutputException(_currentField, "OutputStream::writeArray(): Unsupported array type.");255 throwException( "OutputStream::writeArray(): Unsupported array type." ); 239 256 } 240 257 } … … 287 304 break; 288 305 default: 289 throw OutputException(_currentField, "OutputStream::writePrimitiveSet(): Unsupported primitive type.");306 throwException( "OutputStream::writePrimitiveSet(): Unsupported primitive type." ); 290 307 } 291 308 } … … 297 314 *this << PROPERTY("FileName"); writeWrappedString(img->getFileName()); *this << std::endl; 298 315 *this << PROPERTY("WriteHint") << (int)img->getWriteHint(); 316 if ( getException() ) return; 299 317 300 318 int decision = IMAGE_EXTERNAL; … … 368 386 char* data = new char[size]; 369 387 if ( !data ) 370 throw OutputException(_currentField, "OutputStream::writeImage(): Out of memory."); 388 throwException( "OutputStream::writeImage(): Out of memory." ); 389 if ( getException() ) return; 390 371 391 infile.seekg( 0, std::ios::beg ); 372 392 infile.read( data, size ); … … 389 409 break; 390 410 } 391 392 411 writeObject( img ); 393 412 } … … 403 422 *this << name << BEGIN_BRACKET << std::endl; // Write object name 404 423 *this << PROPERTY("UniqueID") << id << std::endl; // Write object ID 424 if ( getException() ) return; 405 425 406 426 // Check whether this is a shared object or not … … 415 435 return; 416 436 } 437 _fields.push_back( name ); 417 438 418 439 const StringList& associates = wrapper->getAssociates(); … … 426 447 continue; 427 448 } 449 _fields.push_back( assocWrapper->getName() ); 428 450 429 _currentField = assocWrapper->getName();430 451 assocWrapper->write( *this, *obj ); 431 } 452 if ( getException() ) return; 453 454 _fields.pop_back(); 455 } 456 _fields.pop_back(); 432 457 } 433 458 *this << END_BRACKET << std::endl; … … 436 461 void OutputStream::start( OutputIterator* outIterator, OutputStream::WriteType type ) 437 462 { 438 _currentField = "Header"; 463 _fields.clear(); 464 _fields.push_back( "Start" ); 465 439 466 _out = outIterator; 440 467 if ( !_out ) 441 throw OutputException(_currentField, "OutputStream: Null stream specified."); 468 throwException( "OutputStream: Null stream specified." ); 469 if ( getException() ) return; 442 470 443 471 if ( isBinary() ) 444 472 { 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; 447 474 448 475 if ( sizeof(osg::Matrix::value_type)==FLOAT_SIZE ) *this << (unsigned int)0; … … 477 504 } 478 505 479 *this << PROPERTY("#Ascii") <<typeString << std::endl;506 *this << typeString << std::endl; 480 507 *this << PROPERTY("#Version") << (unsigned int)PLUGIN_VERSION << std::endl; 481 508 *this << PROPERTY("#Generator") << std::string("OpenSceneGraph") … … 483 510 *this << std::endl; 484 511 } 512 _fields.pop_back(); 485 513 } 486 514 487 515 void OutputStream::compress( std::ostream* ostream ) 488 516 { 489 _currentField = "Compression"; 517 _fields.clear(); 518 _fields.push_back( "Compression" ); 490 519 if ( _compressorName.empty() || !isBinary() ) return; 491 520 … … 494 523 495 524 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 } 500 528 501 529 void OutputStream::writeSchema( std::ostream& fout ) … … 522 550 } 523 551 552 // PROTECTED METHODS 553 524 554 template<typename T> 525 555 void OutputStream::writeArrayImplementation( const T* a, int writeSize, unsigned int numInRow )
