Show
Ignore:
Timestamp:
03/21/12 18:36:20 (2 years ago)
Author:
robert
Message:

Ran script to remove trailing spaces and tabs

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/src/osgPlugins/osga/OSGA_Archive.cpp

    r12642 r13041  
    1111/* 
    1212Functions to convert between 
    13     std::streampos ( typedef'ed as iostream::pos_type  
     13    std::streampos ( typedef'ed as iostream::pos_type 
    1414              used as seekp,seekg argument and tellp,tellg return value ) 
    15 and  
     15and 
    1616    OSGA_Archive::pos_type (64 bit file position index) 
    1717 
     
    2222    and is returned as result from iostream tellp and tellg methods. 
    2323 
    24     std::streampos can be implicitly cast from/to std::streamoff as  
     24    std::streampos can be implicitly cast from/to std::streamoff as 
    2525    std::streampos class defines appropriate constructor and cast operator. 
    2626 
    27     Since std::streamoff is usually defined as simple int,  
     27    Since std::streamoff is usually defined as simple int, 
    2828    it is possible to call seekp( ), seekg( ) with int argument and 
    2929    assign tellp(), tellg() result to int type. 
    3030 
    31     But this implicit methods fail when std::streamoff is 32 bit and  
     31    But this implicit methods fail when std::streamoff is 32 bit and 
    3232    std::streampos actually points past 32 bit addressable range (2 GiB). 
    3333 
    3434    Even if std::streamoff is 32 bit and incapable of representing 64 bit file 
    3535    positions, original std::streampos may be prefectly able to handle them. 
    36     
    37     But, when such situation occurs more elaborate conversion methods from/to    
    38     std::streampos are needed. Functions below employ such methods.  
    39      
    40     I made this fix for use with 32 bit Windows OSG. Acutally this  
    41     solution is not dependent on OS but standard C++ library.  
    42     Microsoft SDKs always use some version of Dinkumware libs.  
    43  
    44     Practically this tweak is made for Dinkumware C++ libs. I hope it can  
     36 
     37    But, when such situation occurs more elaborate conversion methods from/to 
     38    std::streampos are needed. Functions below employ such methods. 
     39 
     40    I made this fix for use with 32 bit Windows OSG. Acutally this 
     41    solution is not dependent on OS but standard C++ library. 
     42    Microsoft SDKs always use some version of Dinkumware libs. 
     43 
     44    Practically this tweak is made for Dinkumware C++ libs. I hope it can 
    4545    be easily extended to other 32bit systems supporting 64bit files, provided 
    4646    their std::streampos implementations are similar. 
    4747 
    4848    I based my solution on a small portion of boost iostreams code. 
    49     For additional reference look at:  
     49    For additional reference look at: 
    5050        http://boost.org/boost/iostreams/positioning.hpp 
    5151*/ 
    5252 
    53 /*  
    54     Recognize Dinkumware std C++ lib implementation. Its used by Microsoft,  
     53/* 
     54    Recognize Dinkumware std C++ lib implementation. Its used by Microsoft, 
    5555    but method is more generic - should work in all Dinkumware environments. 
    5656 
    57     Complex condition below was taken from  
     57    Complex condition below was taken from 
    5858        http://boost.org/boost/iostreams/positioning.hpp 
    5959 
     
    6565 
    6666inline std::streampos STREAM_POS( const OSGA_Archive::pos_type pos ) 
    67 {  
     67{ 
    6868    return std::streampos( std::mbstate_t(), pos ); 
    6969} 
    7070 
    7171inline OSGA_Archive::pos_type ARCHIVE_POS( const std::streampos & pos ) 
    72 {  
     72{ 
    7373#if defined(_CPPLIB_VER)//newer Dinkumware(eg: one included with VC++ 2003,2005) 
    7474    fpos_t position = pos.seekpos(); 
     
    8080    return OSGA_Archive::pos_type( position + offset ); 
    8181} 
    82 #else // non Dinkumware std C++ lib implementations  
     82#else // non Dinkumware std C++ lib implementations 
    8383// do the old school streampos <-> streamoff casts 
    8484inline std::streampos STREAM_POS( const OSGA_Archive::pos_type pos ) 
    85 {  
     85{ 
    8686    return std::streampos( pos ); 
    8787} 
    8888 
    8989inline OSGA_Archive::pos_type ARCHIVE_POS( const std::streampos & pos ) 
    90 {  
     90{ 
    9191    return OSGA_Archive::pos_type( pos ); 
    9292} 
    93 #endif // Dinkumware std C++ lib  
     93#endif // Dinkumware std C++ lib 
    9494//////////////////////////////////////////////////////////////////////////////// 
    9595float OSGA_Archive::s_currentSupportedVersion = 0.0; 
     
    118118    { 
    119119        _blockSize = blockSize; 
    120          
     120 
    121121        // initialize the array 
    122122        char* end = _data + _blockSize; 
     
    138138    in.read(reinterpret_cast<char*>(&indexBlock->_filePositionNextIndexBlock), sizeof(indexBlock->_filePositionNextIndexBlock)); 
    139139    in.read(reinterpret_cast<char*>(&indexBlock->_offsetOfNextAvailableSpace), sizeof(indexBlock-> _offsetOfNextAvailableSpace)); 
    140      
     140 
    141141    if (doEndianSwap) 
    142142    { 
     
    161161            while (ptr<end_ptr) 
    162162            { 
    163                 osg::swapBytes(ptr,sizeof(pos_type));  
     163                osg::swapBytes(ptr,sizeof(pos_type)); 
    164164                ptr += sizeof(pos_type); 
    165165 
    166                 osg::swapBytes(ptr,sizeof(size_type));  
     166                osg::swapBytes(ptr,sizeof(size_type)); 
    167167                ptr += sizeof(size_type); 
    168168 
    169                 osg::swapBytes(ptr,sizeof(unsigned int));  
     169                osg::swapBytes(ptr,sizeof(unsigned int)); 
    170170                unsigned int filename_size; // = *(reinterpret_cast<unsigned int*>(ptr)); 
    171171                _read(ptr, filename_size); 
     
    185185 
    186186    OSG_INFO<<"Read index block"<<std::endl; 
    187      
     187 
    188188    return indexBlock.release(); 
    189      
     189 
    190190} 
    191191 
     
    214214{ 
    215215    if (!_data || _offsetOfNextAvailableSpace==0) return false; 
    216      
     216 
    217217    bool valuesAdded = false; 
    218      
     218 
    219219    char* ptr = _data; 
    220220    char* end_ptr = _data + _offsetOfNextAvailableSpace; 
    221221    while (ptr<end_ptr) 
    222222    { 
    223         pos_type position; // = *(reinterpret_cast<pos_type*>(ptr));  
     223        pos_type position; // = *(reinterpret_cast<pos_type*>(ptr)); 
    224224        _read(ptr, position); 
    225225        ptr += sizeof(pos_type); 
    226          
    227         size_type size; // = *(reinterpret_cast<size_type*>(ptr));  
     226 
     227        size_type size; // = *(reinterpret_cast<size_type*>(ptr)); 
    228228        _read(ptr, size); 
    229229        ptr += sizeof(size_type); 
     
    232232        _read(ptr, filename_size); 
    233233        ptr += sizeof(unsigned int); 
    234          
     234 
    235235        std::string filename(ptr, ptr+filename_size); 
    236          
    237         // record this entry into the FileNamePositionMap.  
     236 
     237        // record this entry into the FileNamePositionMap. 
    238238        // Requests for files will be in unix style even on Win32 so need unix style keys in map. 
    239239        indexMap[osgDB::convertFileNameToUnixStyle(filename)] = PositionSizePair(position,size); 
    240          
     240 
    241241        ptr += filename_size; 
    242          
     242 
    243243        valuesAdded = true; 
    244244    } 
     
    267267    out.write(reinterpret_cast<char*>(_data),_blockSize); 
    268268 
    269     if( _filePosition < currentPos ) // move file ptr to the end of file  
     269    if( _filePosition < currentPos ) // move file ptr to the end of file 
    270270        out.seekp( STREAM_POS( currentPos ) ); 
    271      
     271 
    272272    OSG_INFO<<"OSGA_Archive::IndexBlock::write() end"<<std::endl; 
    273273} 
     
    279279    { 
    280280        char* ptr = _data+_offsetOfNextAvailableSpace; 
    281          
    282         //*(reinterpret_cast<pos_type*>(ptr)) = position;  
     281 
     282        //*(reinterpret_cast<pos_type*>(ptr)) = position; 
    283283        _write(ptr, position); 
    284284        ptr += sizeof(pos_type); 
    285          
    286         //*(reinterpret_cast<size_type*>(ptr)) = size;  
     285 
     286        //*(reinterpret_cast<size_type*>(ptr)) = size; 
    287287        _write(ptr, size); 
    288288        ptr += sizeof(size_type); 
    289          
     289 
    290290        //*(reinterpret_cast<unsigned int*>(ptr)) = filename.size(); 
    291291        _write(ptr, static_cast<unsigned int>(filename.size())); 
    292292        ptr += sizeof(unsigned int); 
    293          
     293 
    294294        for(unsigned int i=0;i<filename.size();++i, ++ptr) 
    295295        { 
    296296            *ptr = filename[i]; 
    297297        } 
    298          
     298 
    299299        _offsetOfNextAvailableSpace = ptr-_data; 
    300          
     300 
    301301        _requiresWrite = true; 
    302302 
    303303        OSG_INFO<<"OSGA_Archive::IndexBlock::addFileReference("<<(unsigned int)position<<", "<<filename<<")"<<std::endl; 
    304          
     304 
    305305        return true; 
    306306    } 
     
    346346            pos_type file_size( 0 ); 
    347347            _input.seekg( 0, std::ios_base::end ); 
    348             file_size = ARCHIVE_POS( _input.tellg() );  
     348            file_size = ARCHIVE_POS( _input.tellg() ); 
    349349            if( _input.is_open() && file_size <= 0 ) 
    350             {   // compute end of file postition manually ...  
     350            {   // compute end of file postition manually ... 
    351351                // seekp( 0, ios::end ), tellp( ) fails in 32 bit windows with files > 4 GiB 
    352                 size_t BlockHeaderSize =  
    353                     sizeof( unsigned int /*_blockSize*/ ) +  
     352                size_t BlockHeaderSize = 
     353                    sizeof( unsigned int /*_blockSize*/ ) + 
    354354                    sizeof( pos_type /*_filePositionNextIndexBlock*/ ) + 
    355355                    sizeof( unsigned int /*_offsetOfNextAvailableSpace*/ ); 
    356            
     356 
    357357                for(IndexBlockList::iterator itr=_indexBlockList.begin(); 
    358358                    itr!=_indexBlockList.end(); 
     
    378378            OSG_INFO<<"File position after open = "<<ARCHIVE_POS( _output.tellp() )<<" is_open "<<_output.is_open()<<std::endl; 
    379379 
    380             // place write position at end of file.  
     380            // place write position at end of file. 
    381381            _output.seekp( STREAM_POS( file_size ) ); 
    382382 
     
    408408            return true; 
    409409        } 
    410          
     410 
    411411    } 
    412412} 
     
    431431 
    432432        bool validArchive = (identifier[0]=='o' && identifier[1]=='s' && identifier[2]=='g' && identifier[3]=='a'); 
    433         if (validArchive)  
     433        if (validArchive) 
    434434        { 
    435435 
     
    458458 
    459459            // now need to build the filename map. 
    460             _indexMap.clear();                 
     460            _indexMap.clear(); 
    461461 
    462462            if (!_indexBlockList.empty()) 
     
    491491 
    492492    _input.close(); 
    493      
     493 
    494494    if (_status==WRITE) 
    495495    { 
     
    557557        return false; 
    558558    } 
    559      
     559 
    560560    if (!_output) 
    561561    { 
     
    563563        return false; 
    564564    } 
    565      
    566      
     565 
     566 
    567567    // if the masterFileName isn't set yet use this fileName 
    568568    if (_masterFileName.empty()) _masterFileName = fileName; 
     
    583583    } 
    584584 
    585     // if not one available create a new block.     
     585    // if not one available create a new block. 
    586586    if (!indexBlock) 
    587587    { 
    588588        if (previousBlock.valid()) previousBlock->setPositionNextIndexBlock( ARCHIVE_POS( _output.tellp() ) ); 
    589      
     589 
    590590        indexBlock = new IndexBlock(blockSize); 
    591591        indexBlock->write(_output); 
    592592        _indexBlockList.push_back(indexBlock.get()); 
    593593    } 
    594      
     594 
    595595    if (indexBlock.valid()) 
    596596    { 
     
    605605{ 
    606606   public: 
    607     
     607 
    608608      proxy_streambuf(std::streambuf* streambuf, unsigned int numChars): 
    609609        _streambuf(streambuf), 
     
    611611            setg(&oneChar, (&oneChar)+1, (&oneChar)+1); 
    612612    } 
    613     
     613 
    614614      /// Destructor deallocates no buffer space. 
    615615      virtual ~proxy_streambuf()  {} 
     
    619619    protected: 
    620620 
    621       unsigned int _numChars;       
     621      unsigned int _numChars; 
    622622      char_type oneChar; 
    623        
     623 
    624624      virtual int_type underflow() 
    625625      { 
    626626     if ( gptr() == &oneChar ) return traits_type::to_int_type(oneChar); 
    627          
    628          if ( _numChars==0 ) return traits_type::eof();          
     627 
     628         if ( _numChars==0 ) return traits_type::eof(); 
    629629         --_numChars; 
    630630 
    631631           int_type next_value = _streambuf->sbumpc(); 
    632       
     632 
    633633         if ( !traits_type::eq_int_type(next_value,traits_type::eof()) ) 
    634634     { 
     
    636636            oneChar = traits_type::to_char_type(next_value); 
    637637     } 
    638      
     638 
    639639         return next_value; 
    640640      } 
     
    644644{ 
    645645    ReadObjectFunctor(const std::string& filename, const ReaderWriter::Options* options):ReadFunctor(filename,options) {} 
    646     virtual ReaderWriter::ReadResult doRead(ReaderWriter& rw, std::istream& input) const { return rw.readObject(input, _options); }     
     646    virtual ReaderWriter::ReadResult doRead(ReaderWriter& rw, std::istream& input) const { return rw.readObject(input, _options); } 
    647647}; 
    648648 
     
    650650{ 
    651651   ReadImageFunctor(const std::string& filename, const ReaderWriter::Options* options):ReadFunctor(filename,options) {} 
    652     virtual ReaderWriter::ReadResult doRead(ReaderWriter& rw, std::istream& input)const  { return rw.readImage(input, _options); }     
     652    virtual ReaderWriter::ReadResult doRead(ReaderWriter& rw, std::istream& input)const  { return rw.readImage(input, _options); } 
    653653}; 
    654654 
     
    656656{ 
    657657    ReadHeightFieldFunctor(const std::string& filename, const ReaderWriter::Options* options):ReadFunctor(filename,options) {} 
    658     virtual ReaderWriter::ReadResult doRead(ReaderWriter& rw, std::istream& input) const { return rw.readHeightField(input, _options); }     
     658    virtual ReaderWriter::ReadResult doRead(ReaderWriter& rw, std::istream& input) const { return rw.readHeightField(input, _options); } 
    659659}; 
    660660 
     
    675675    SERIALIZER(); 
    676676 
    677     if (_status!=READ)  
     677    if (_status!=READ) 
    678678    { 
    679679        OSG_INFO<<"OSGA_Archive::readObject(obj, "<<readFunctor._filename<<") failed, archive opened as write only."<<std::endl; 
    680680        return ReadResult(ReadResult::FILE_NOT_HANDLED); 
    681681    } 
    682      
     682 
    683683    FileNamePositionMap::const_iterator itr = _indexMap.find(readFunctor._filename); 
    684684    if (itr==_indexMap.end()) 
     
    687687        return ReadResult(ReadResult::FILE_NOT_FOUND); 
    688688    } 
    689      
     689 
    690690    ReaderWriter* rw = osgDB::Registry::instance()->getReaderWriterForExtension(getLowerCaseFileExtension(readFunctor._filename)); 
    691691    if (!rw) 
     
    694694        return ReadResult(ReadResult::FILE_NOT_HANDLED); 
    695695    } 
    696      
     696 
    697697    OSG_INFO<<"OSGA_Archive::readObject(obj, "<<readFunctor._filename<<")"<<std::endl; 
    698      
     698 
    699699    _input.seekg( STREAM_POS( itr->second.first ) ); 
    700700 
     
    707707 
    708708    ins.rdbuf(mystreambuf._streambuf); 
    709      
     709 
    710710    return result; 
    711711} 
     
    743743        _object(object) {} 
    744744    const osg::Object& _object; 
    745      
    746     virtual ReaderWriter::WriteResult doWrite(ReaderWriter& rw, std::ostream& output) const { return rw.writeObject(_object, output, _options); }  
     745 
     746    virtual ReaderWriter::WriteResult doWrite(ReaderWriter& rw, std::ostream& output) const { return rw.writeObject(_object, output, _options); } 
    747747}; 
    748748 
     
    754754    const osg::Image& _object; 
    755755 
    756     virtual ReaderWriter::WriteResult doWrite(ReaderWriter& rw, std::ostream& output) const { return rw.writeImage(_object, output, _options); }     
     756    virtual ReaderWriter::WriteResult doWrite(ReaderWriter& rw, std::ostream& output) const { return rw.writeImage(_object, output, _options); } 
    757757}; 
    758758 
     
    764764    const osg::HeightField& _object; 
    765765 
    766     virtual ReaderWriter::WriteResult doWrite(ReaderWriter& rw, std::ostream& output) const { return rw.writeHeightField(_object, output, _options); }     
     766    virtual ReaderWriter::WriteResult doWrite(ReaderWriter& rw, std::ostream& output) const { return rw.writeHeightField(_object, output, _options); } 
    767767}; 
    768768 
     
    791791    SERIALIZER(); 
    792792 
    793     if (_status!=WRITE)  
     793    if (_status!=WRITE) 
    794794    { 
    795795        OSG_INFO<<"OSGA_Archive::write(obj, "<<writeFunctor._filename<<") failed, archive opened as read only."<<std::endl; 
     
    803803        return WriteResult(WriteResult::FILE_NOT_HANDLED); 
    804804    } 
    805      
     805 
    806806    OSG_INFO<<"OSGA_Archive::write(obj, "<<writeFunctor._filename<<")"<<std::endl; 
    807      
     807 
    808808    pos_type position = ARCHIVE_POS( _output.tellp() ); 
    809      
     809 
    810810    WriteResult result = writeFunctor.doWrite(*rw,_output); 
    811      
     811 
    812812    pos_type final_position = ARCHIVE_POS( _output.tellp() ); 
    813813    size_type size = size_type( final_position-position ); 
    814814 
    815815    if (result.success()) addFileReference(position, size, writeFunctor._filename); 
    816      
     816 
    817817    return result; 
    818818}