Changeset 11018 for OpenSceneGraph/trunk/src/osgDB/InputStream.cpp
- Timestamp:
- 01/27/10 18:09:05 (3 years ago)
- Files:
-
- 1 modified
-
OpenSceneGraph/trunk/src/osgDB/InputStream.cpp (modified) (17 diffs)
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/src/osgDB/InputStream.cpp
r10986 r11018 25 25 26 26 InputStream::InputStream( const osgDB::Options* options ) 27 : _byteSwap(0), _useFloatMatrix(false), 28 _in(0) 27 : _byteSwap(0), _useFloatMatrix(false), _forceReadingImage(false) 29 28 { 30 29 if ( !options ) return; … … 39 38 { 40 39 // Omit this 40 } 41 else if ( option=="ForceReadingImage" ) 42 { 43 _forceReadingImage = true; 41 44 } 42 45 else … … 158 161 } 159 162 163 bool InputStream::matchString( const std::string& str ) 164 { 165 if ( !isBinary() ) 166 { 167 std::string s; *this >> s; 168 if ( s==str ) return true; 169 else _in->getStream()->seekg( -(int)(s.length()), std::ios::cur ); 170 } 171 return false; 172 } 173 174 void InputStream::advanceToCurrentEndBracket() 175 { 176 if ( isBinary() ) 177 return; 178 179 std::string passString; 180 unsigned int blocks = 0; 181 while ( !_in->getStream()->eof() ) 182 { 183 passString.clear(); 184 *this >> passString; 185 186 if ( passString=="}" ) 187 { 188 if ( blocks<=0 ) return; 189 else blocks--; 190 } 191 else if ( passString=="{" ) 192 blocks++; 193 } 194 } 195 196 void InputStream::readWrappedString( std::string& str ) 197 { 198 *this >> str; 199 if ( !isBinary() ) 200 { 201 if ( str[0]=='\"' ) 202 { 203 if ( str.size()==1 || (*str.rbegin())!='\"' ) 204 { 205 char ch; 206 do 207 { 208 _in->getStream()->get( ch ); checkStream(); 209 if ( ch=='\\' ) 210 { 211 _in->getStream()->get( ch ); checkStream(); 212 if ( ch=='\"' ) 213 { 214 str += ch; ch = 0; 215 } 216 else if ( ch=='\\' ) 217 { 218 str += ch; 219 } 220 else 221 { 222 str += '\\'; str += ch; 223 } 224 } 225 else 226 str += ch; 227 } while ( ch!='\"' ); 228 } 229 str = str.substr(1, str.size()-2); 230 } 231 } 232 } 233 160 234 osg::Array* InputStream::readArray() 161 235 { … … 320 394 break; 321 395 default: 322 throw InputException(_currentField, "InputStream::readArray(): Unsupported array type."); 323 } 324 396 throwException( "InputStream::readArray(): Unsupported array type." ); 397 } 398 399 if ( getException() ) return NULL; 325 400 _arrayMap[id] = array; 326 401 return array.release(); … … 402 477 break; 403 478 default: 404 throw InputException(_currentField, "InputStream::readPrimitiveSet(): Unsupported array type."); 405 } 479 throwException( "InputStream::readPrimitiveSet(): Unsupported array type." ); 480 } 481 482 if ( getException() ) return NULL; 406 483 return primitive.release(); 407 484 } … … 413 490 *this >> PROPERTY("FileName"); readWrappedString(name); 414 491 *this >> PROPERTY("WriteHint") >> writeHint >> decision; 492 if ( getException() ) return NULL; 415 493 416 494 osg::ref_ptr<osg::Image> image = NULL; … … 437 515 char* data = new char[size]; 438 516 if ( !data ) 439 throw InputException(_currentField, "InputStream::readImage() Out of memory."); 517 throwException( "InputStream::readImage() Out of memory." ); 518 if ( getException() ) return NULL; 519 440 520 readCharArray( data, size ); 441 521 image->setOrigin( (osg::Image::Origin)origin ); … … 464 544 char* data = new char[size]; 465 545 if ( !data ) 466 throw InputException(_currentField, "InputStream::readImage(): Out of memory."); 546 throwException( "InputStream::readImage(): Out of memory." ); 547 if ( getException() ) return NULL; 467 548 readCharArray( data, size ); 468 549 … … 501 582 502 583 if ( readFromExternal ) 584 { 503 585 image = osgDB::readImageFile( name ); 586 if ( !image && _forceReadingImage ) image = new osg::Image; 587 } 504 588 if ( image.valid() ) 505 589 { … … 517 601 unsigned int id = 0; 518 602 *this >> className >> BEGIN_BRACKET >> PROPERTY("UniqueID") >> id; 603 if ( getException() ) return NULL; 519 604 520 605 IdentifierMap::iterator itr = _identifierMap.find( id ); … … 533 618 return NULL; 534 619 } 620 _fields.push_back( className ); 621 535 622 osg::ref_ptr<osg::Object> obj = existingObj ? existingObj : wrapper->getProto()->cloneType(); 536 623 if ( obj.valid() ) … … 548 635 continue; 549 636 } 637 _fields.push_back( assocWrapper->getName() ); 550 638 551 _currentField = assocWrapper->getName();552 639 assocWrapper->read( *this, *obj ); 640 if ( getException() ) return NULL; 641 642 _fields.pop_back(); 553 643 } 554 644 } 555 645 advanceToCurrentEndBracket(); 646 _fields.pop_back(); 556 647 return obj.release(); 557 648 } … … 576 667 InputStream::ReadType InputStream::start( InputIterator* inIterator ) 577 668 { 669 _fields.clear(); 670 _fields.push_back( "Start" ); 671 578 672 ReadType type = READ_UNKNOWN; 579 _currentField = "Header";580 673 _in = inIterator; 581 674 if ( !_in ) 582 throw InputException(_currentField, "InputStream: Null stream specified."); 675 throwException( "InputStream: Null stream specified." ); 676 if ( getException() ) return type; 583 677 584 678 // Check OSG header information … … 596 690 if ( !isBinary() ) 597 691 { 598 DEF_PROPERTY("#Ascii", header); *this >> header;599 if ( header._name!="#Ascii" ) return READ_UNKNOWN;600 601 692 std::string typeString; *this >> typeString; 602 693 if ( typeString=="Scene" ) type = READ_SCENE; … … 615 706 << PLUGIN_VERSION << std::endl; 616 707 } 708 _fields.pop_back(); 617 709 return type; 618 710 } … … 620 712 void InputStream::decompress() 621 713 { 622 _currentField = "Decompression"; 714 _fields.clear(); 715 _fields.push_back( "Decompression" ); 623 716 if ( !isBinary() ) return; 624 717 … … 635 728 std::string data; 636 729 if ( !compressor->decompress(*(_in->getStream()), data) ) 637 throw InputException(_currentField, "InputStream: Failed to decompress stream."); 730 throwException( "InputStream: Failed to decompress stream." ); 731 if ( getException() ) return; 732 638 733 _in->setStream( new std::stringstream(data) ); 734 _fields.pop_back(); 639 735 } 640 736
