From 5b1ca779e44d17e65a292eb3ff598f98d7f97635 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 10 Feb 2010 17:03:09 +0000 Subject: [PATCH] Added OutputStream::writeSize and InputStream::readSize methods to help out with ensure that 32bit and 64bit builds all use the same 32bit type for sizes. --- include/osgDB/InputStream | 7 +++++-- include/osgDB/OutputStream | 8 ++++++-- src/osgDB/InputStream.cpp | 6 +++--- src/osgDB/OutputStream.cpp | 10 +++++----- 4 files changed, 19 insertions(+), 12 deletions(-) diff --git a/include/osgDB/InputStream b/include/osgDB/InputStream index fab7843cb..915776b32 100644 --- a/include/osgDB/InputStream +++ b/include/osgDB/InputStream @@ -126,7 +126,10 @@ public: void advanceToCurrentEndBracket(); void readWrappedString( std::string& str ); void readCharArray( char* s, unsigned int size ) { _in->readCharArray(s, size); } - + + // readSize() use unsigned int for all sizes. + unsigned int readSize() { unsigned int size; *this>>size; return size; } + // Global reading functions osg::Array* readArray(); osg::PrimitiveSet* readPrimitiveSet(); @@ -149,7 +152,7 @@ protected: void setWrapperSchema( const std::string& name, const std::string& properties ); template - void readArrayImplementation( T* a, int readSize, bool useByteSwap=false ); + void readArrayImplementation( T* a, int read_size, bool useByteSwap=false ); ArrayMap _arrayMap; IdentifierMap _identifierMap; diff --git a/include/osgDB/OutputStream b/include/osgDB/OutputStream index 66fb57653..85758b48b 100644 --- a/include/osgDB/OutputStream +++ b/include/osgDB/OutputStream @@ -134,7 +134,11 @@ public: // Convenient methods for writing void writeWrappedString( const std::string& str ); void writeCharArray( const char* s, unsigned int size ) { _out->writeCharArray(s, size); } - + + // method for converting all data structure sizes to unsigned int to ensure architecture portability. + template + void writeSize(T size) { *this<(size); } + // Global writing functions void writeArray( const osg::Array* a ); void writePrimitiveSet( const osg::PrimitiveSet* p ); @@ -153,7 +157,7 @@ public: protected: template - void writeArrayImplementation( const T*, int writeSize, unsigned int numInRow=1 ); + void writeArrayImplementation( const T*, int write_size, unsigned int numInRow=1 ); unsigned int findOrCreateArrayID( const osg::Array* array ); unsigned int findOrCreateObjectID( const osg::Object* obj ); diff --git a/src/osgDB/InputStream.cpp b/src/osgDB/InputStream.cpp index dd5732079..741887e3a 100644 --- a/src/osgDB/InputStream.cpp +++ b/src/osgDB/InputStream.cpp @@ -763,7 +763,7 @@ void InputStream::resetSchema() } template -void InputStream::readArrayImplementation( T* a, int readSize, bool useByteSwap ) +void InputStream::readArrayImplementation( T* a, int read_size, bool useByteSwap ) { int size = 0; *this >> size >> BEGIN_BRACKET; @@ -772,11 +772,11 @@ void InputStream::readArrayImplementation( T* a, int readSize, bool useByteSwap a->resize( size ); if ( isBinary() ) { - _in->getStream()->read( (char*)&((*a)[0]), readSize*size ); checkStream(); + _in->getStream()->read( (char*)&((*a)[0]), read_size*size ); checkStream(); if ( useByteSwap && _byteSwap ) { for ( int i=0; igetMipmapLevels(); - *this << levels.size(); + writeSize(levels.size()); for ( osg::Image::MipmapDataType::const_iterator itr=levels.begin(); itr!=levels.end(); ++itr ) { @@ -552,12 +552,12 @@ void OutputStream::writeSchema( std::ostream& fout ) // PROTECTED METHODS template -void OutputStream::writeArrayImplementation( const T* a, int writeSize, unsigned int numInRow ) +void OutputStream::writeArrayImplementation( const T* a, int write_size, unsigned int numInRow ) { - *this << writeSize << BEGIN_BRACKET; + *this << write_size << BEGIN_BRACKET; if ( numInRow>1 ) { - for ( int i=0; i