From 725258ea541aec77c68b1fd661d7c6050b7c9a66 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 10 Feb 2010 19:36:31 +0000 Subject: [PATCH] replaced reading and writing of std::container.size() using InputStream::readSize() and OutputStream::writeSize() to make the type writing more explictly tied to the size type, with use of unsigned int as the default size. This approach ensures that we get the same results under 32 and 64bit builds. --- .../serializers/osg/AnimationPath.cpp | 4 ++-- src/osgWrappers/serializers/osg/Billboard.cpp | 6 ++++-- src/osgWrappers/serializers/osg/Camera.cpp | 4 ++-- .../serializers/osg/ConvexPlanarOccluder.cpp | 8 ++++---- .../serializers/osg/FragmentProgram.cpp | 8 ++++---- src/osgWrappers/serializers/osg/Geometry.cpp | 4 ++-- .../serializers/osg/ImageSequence.cpp | 6 +++--- src/osgWrappers/serializers/osg/LOD.cpp | 4 ++-- src/osgWrappers/serializers/osg/Node.cpp | 4 ++-- src/osgWrappers/serializers/osg/Program.cpp | 8 ++++---- src/osgWrappers/serializers/osg/Shader.cpp | 4 ++-- src/osgWrappers/serializers/osg/StateSet.cpp | 20 +++++++++---------- .../serializers/osg/TransferFunction1D.cpp | 4 ++-- .../serializers/osg/VertexProgram.cpp | 8 ++++---- 14 files changed, 47 insertions(+), 45 deletions(-) diff --git a/src/osgWrappers/serializers/osg/AnimationPath.cpp b/src/osgWrappers/serializers/osg/AnimationPath.cpp index f16ee054b..687398d3e 100644 --- a/src/osgWrappers/serializers/osg/AnimationPath.cpp +++ b/src/osgWrappers/serializers/osg/AnimationPath.cpp @@ -13,7 +13,7 @@ static bool checkTimeControlPointMap( const osg::AnimationPath& path ) static bool readTimeControlPointMap( osgDB::InputStream& is, osg::AnimationPath& path ) { - unsigned int size = 0; is >> size; + unsigned int size = is.readSize(); if ( size>0 ) { is >> osgDB::BEGIN_BRACKET; @@ -37,7 +37,7 @@ static bool readTimeControlPointMap( osgDB::InputStream& is, osg::AnimationPath& static bool writeTimeControlPointMap( osgDB::OutputStream& os, const osg::AnimationPath& path ) { const osg::AnimationPath::TimeControlPointMap& map = path.getTimeControlPointMap(); - os << map.size(); + os.writeSize(map.size()); if ( map.size()>0 ) { os << osgDB::BEGIN_BRACKET << std::endl; diff --git a/src/osgWrappers/serializers/osg/Billboard.cpp b/src/osgWrappers/serializers/osg/Billboard.cpp index 3ed585463..075eccb16 100644 --- a/src/osgWrappers/serializers/osg/Billboard.cpp +++ b/src/osgWrappers/serializers/osg/Billboard.cpp @@ -10,7 +10,8 @@ static bool checkPositionList( const osg::Billboard& node ) static bool readPositionList( osgDB::InputStream& is, osg::Billboard& node ) { - unsigned int size = 0; is >> size >> osgDB::BEGIN_BRACKET; + unsigned int size = is.readSize(); + is >> osgDB::BEGIN_BRACKET; for ( unsigned int i=0; i> pos; @@ -23,7 +24,8 @@ static bool readPositionList( osgDB::InputStream& is, osg::Billboard& node ) static bool writePositionList( osgDB::OutputStream& os, const osg::Billboard& node ) { const osg::Billboard::PositionList& posList = node.getPositionList(); - os << posList.size() << osgDB::BEGIN_BRACKET << std::endl; + os.writeSize(posList.size()); + os<< osgDB::BEGIN_BRACKET << std::endl; for ( osg::Billboard::PositionList::const_iterator itr=posList.begin(); itr!=posList.end(); ++itr ) { diff --git a/src/osgWrappers/serializers/osg/Camera.cpp b/src/osgWrappers/serializers/osg/Camera.cpp index 0fc20d3c8..7dd69aff2 100644 --- a/src/osgWrappers/serializers/osg/Camera.cpp +++ b/src/osgWrappers/serializers/osg/Camera.cpp @@ -182,7 +182,7 @@ static bool checkBufferAttachmentMap( const osg::Camera& node ) static bool readBufferAttachmentMap( osgDB::InputStream& is, osg::Camera& node ) { - unsigned int size = 0; is >> size >> osgDB::BEGIN_BRACKET; + unsigned int size = is.readSize(); is >> osgDB::BEGIN_BRACKET; for ( unsigned int i=0; i> osgDB::PROPERTY("Attachment"); @@ -215,7 +215,7 @@ static bool readBufferAttachmentMap( osgDB::InputStream& is, osg::Camera& node ) static bool writeBufferAttachmentMap( osgDB::OutputStream& os, const osg::Camera& node ) { const osg::Camera::BufferAttachmentMap& map = node.getBufferAttachmentMap(); - os << map.size() << osgDB::BEGIN_BRACKET << std::endl; + os.writeSize(map.size()); os<< osgDB::BEGIN_BRACKET << std::endl; for ( osg::Camera::BufferAttachmentMap::const_iterator itr=map.begin(); itr!=map.end(); ++itr ) { diff --git a/src/osgWrappers/serializers/osg/ConvexPlanarOccluder.cpp b/src/osgWrappers/serializers/osg/ConvexPlanarOccluder.cpp index 3546be1d7..f9420bfe9 100644 --- a/src/osgWrappers/serializers/osg/ConvexPlanarOccluder.cpp +++ b/src/osgWrappers/serializers/osg/ConvexPlanarOccluder.cpp @@ -5,7 +5,7 @@ static void readConvexPlanarPolygon( osgDB::InputStream& is, osg::ConvexPlanarPolygon& polygon ) { - unsigned int size = 0; is >> size >> osgDB::BEGIN_BRACKET; + unsigned int size = is.readSize(); is >> osgDB::BEGIN_BRACKET; for ( unsigned int i=0; i> vertex; @@ -17,7 +17,7 @@ static void readConvexPlanarPolygon( osgDB::InputStream& is, osg::ConvexPlanarPo static void writeConvexPlanarPolygon( osgDB::OutputStream& os, const osg::ConvexPlanarPolygon& polygon ) { const osg::ConvexPlanarPolygon::VertexList& vertices = polygon.getVertexList(); - os << vertices.size() << osgDB::BEGIN_BRACKET << std::endl; + os.writeSize(vertices.size()); os<< osgDB::BEGIN_BRACKET << std::endl; for ( osg::ConvexPlanarPolygon::VertexList::const_iterator itr=vertices.begin(); itr!=vertices.end(); ++itr ) { @@ -54,7 +54,7 @@ static bool checkHoles( const osg::ConvexPlanarOccluder& obj ) static bool readHoles( osgDB::InputStream& is, osg::ConvexPlanarOccluder& obj ) { - unsigned int size = 0; is >> size >> osgDB::BEGIN_BRACKET; + unsigned int size = is.readSize(); is >> osgDB::BEGIN_BRACKET; for ( unsigned int i=0; i> size >> osgDB::BEGIN_BRACKET; + unsigned int size = is.readSize(); is >> osgDB::BEGIN_BRACKET; for ( unsigned int i=0; i> size >> osgDB::BEGIN_BRACKET; + unsigned int size = is.readSize(); is >> osgDB::BEGIN_BRACKET; for ( unsigned int i=0; i0; } \ static bool read##PROP( osgDB::InputStream& is, osg::Geometry& geom ) { \ - unsigned int size = 0; is >> size >> osgDB::BEGIN_BRACKET; \ + unsigned int size = is.readSize(); is >> osgDB::BEGIN_BRACKET; \ for ( unsigned int i=0; i> osgDB::PROPERTY("Data") >> osgDB::BEGIN_BRACKET; \ @@ -84,7 +84,7 @@ ADD_ARRAYDATA_FUNCTIONS( FogCoordData ) } \ static bool write##PROP( osgDB::OutputStream& os, const osg::Geometry& geom ) { \ const osg::Geometry::ArrayDataList& LISTNAME = geom.get##LISTNAME(); \ - os << LISTNAME.size() << osgDB::BEGIN_BRACKET << std::endl; \ + os.writeSize(LISTNAME.size()); os << osgDB::BEGIN_BRACKET << std::endl; \ for ( osg::Geometry::ArrayDataList::const_iterator itr=LISTNAME.begin(); \ itr!=LISTNAME.end(); ++itr ) { \ os << osgDB::PROPERTY("Data") << osgDB::BEGIN_BRACKET << std::endl; \ diff --git a/src/osgWrappers/serializers/osg/ImageSequence.cpp b/src/osgWrappers/serializers/osg/ImageSequence.cpp index 0c2c5e0ae..ab7806c7a 100644 --- a/src/osgWrappers/serializers/osg/ImageSequence.cpp +++ b/src/osgWrappers/serializers/osg/ImageSequence.cpp @@ -24,7 +24,7 @@ static bool readFileNames( osgDB::InputStream& is, osg::ImageSequence& image ) static bool writeFileNames( osgDB::OutputStream& os, const osg::ImageSequence& image ) { const osg::ImageSequence::FileNames& files = image.getFileNames(); - os << files.size() << osgDB::BEGIN_BRACKET << std::endl; + os.writeSize(files.size()); os << osgDB::BEGIN_BRACKET << std::endl; for ( osg::ImageSequence::FileNames::const_iterator itr=files.begin(); itr!=files.end(); ++itr ) { @@ -43,7 +43,7 @@ static bool checkImages( const osg::ImageSequence& image ) static bool readImages( osgDB::InputStream& is, osg::ImageSequence& image ) { - unsigned int images = 0; is >> images >> osgDB::BEGIN_BRACKET; + unsigned int images = is.readSize(); is >> osgDB::BEGIN_BRACKET; for ( unsigned int i=0; i( is.readObject() ); @@ -56,7 +56,7 @@ static bool readImages( osgDB::InputStream& is, osg::ImageSequence& image ) static bool writeImages( osgDB::OutputStream& os, const osg::ImageSequence& image ) { const osg::ImageSequence::Images& images = image.getImages(); - os << images.size() << osgDB::BEGIN_BRACKET << std::endl; + os.writeSize(images.size()); os << osgDB::BEGIN_BRACKET << std::endl; for ( osg::ImageSequence::Images::const_iterator itr=images.begin(); itr!=images.end(); ++itr ) { diff --git a/src/osgWrappers/serializers/osg/LOD.cpp b/src/osgWrappers/serializers/osg/LOD.cpp index 965358a0d..47b0d10d8 100644 --- a/src/osgWrappers/serializers/osg/LOD.cpp +++ b/src/osgWrappers/serializers/osg/LOD.cpp @@ -31,7 +31,7 @@ static bool checkRangeList( const osg::LOD& node ) static bool readRangeList( osgDB::InputStream& is, osg::LOD& node ) { - unsigned int size = 0; is >> size >> osgDB::BEGIN_BRACKET; + unsigned int size = is.readSize(); is >> osgDB::BEGIN_BRACKET; for ( unsigned int i=0; i> size >> osgDB::BEGIN_BRACKET; + unsigned int size = is.readSize(); is >> osgDB::BEGIN_BRACKET; for ( unsigned int i=0; i0; } \ static bool read##PROP(osgDB::InputStream& is, osg::Program& attr) { \ - unsigned int size = 0; is >> size >> osgDB::BEGIN_BRACKET; \ + unsigned int size = is.readSize(); is >> osgDB::BEGIN_BRACKET; \ for ( unsigned int i=0; i> key >> value; attr.add##DATA(key, value); \ @@ -18,7 +18,7 @@ static bool write##PROP( osgDB::OutputStream& os, const osg::Program& attr ) \ { \ const osg::Program::TYPE& plist = attr.get##TYPE(); \ - os << plist.size() << osgDB::BEGIN_BRACKET << std::endl; \ + os.writeSize(plist.size()); os << osgDB::BEGIN_BRACKET << std::endl; \ for ( osg::Program::TYPE::const_iterator itr=plist.begin(); \ itr!=plist.end(); ++itr ) { \ os << itr->first << itr->second << std::endl; \ @@ -55,7 +55,7 @@ static bool checkShaders( const osg::Program& attr ) static bool readShaders( osgDB::InputStream& is, osg::Program& attr ) { - unsigned int size = 0; is >> size >> osgDB::BEGIN_BRACKET; + unsigned int size = is.readSize(); is >> osgDB::BEGIN_BRACKET; for ( unsigned int i=0; i( is.readObject() ); @@ -68,7 +68,7 @@ static bool readShaders( osgDB::InputStream& is, osg::Program& attr ) static bool writeShaders( osgDB::OutputStream& os, const osg::Program& attr ) { unsigned int size = attr.getNumShaders(); - os << size << osgDB::BEGIN_BRACKET << std::endl; + os.writeSize(size); os << osgDB::BEGIN_BRACKET << std::endl; for ( unsigned int i=0; i> size >> osgDB::BEGIN_BRACKET; + unsigned int size = is.readSize(); is >> osgDB::BEGIN_BRACKET; for ( unsigned int i=0; i::const_iterator itr=lines.begin(); itr!=lines.end(); ++itr ) { diff --git a/src/osgWrappers/serializers/osg/StateSet.cpp b/src/osgWrappers/serializers/osg/StateSet.cpp index be40343af..60c69eff0 100644 --- a/src/osgWrappers/serializers/osg/StateSet.cpp +++ b/src/osgWrappers/serializers/osg/StateSet.cpp @@ -29,7 +29,7 @@ static int readValue( osgDB::InputStream& is ) static void readModes( osgDB::InputStream& is, osg::StateSet::ModeList& modes ) { - unsigned int size = 0; is >> size; + unsigned int size = is.readSize(); if ( size>0 ) { is >> osgDB::BEGIN_BRACKET; @@ -45,7 +45,7 @@ static void readModes( osgDB::InputStream& is, osg::StateSet::ModeList& modes ) static void readAttributes( osgDB::InputStream& is, osg::StateSet::AttributeList& attrs ) { - unsigned int size = 0; is >> size; + unsigned int size = is.readSize(); if ( size>0 ) { is >> osgDB::BEGIN_BRACKET; @@ -84,7 +84,7 @@ static void writeValue( osgDB::OutputStream& os, int value ) static void writeModes( osgDB::OutputStream& os, const osg::StateSet::ModeList& modes ) { - os << modes.size(); + os.writeSize(modes.size()); if ( modes.size()>0 ) { os << osgDB::BEGIN_BRACKET << std::endl; @@ -102,7 +102,7 @@ static void writeModes( osgDB::OutputStream& os, const osg::StateSet::ModeList& static void writeAttributes( osgDB::OutputStream& os, const osg::StateSet::AttributeList& attrs ) { - os << attrs.size(); + os.writeSize(attrs.size()); if ( attrs.size()>0 ) { os << osgDB::BEGIN_BRACKET << std::endl; @@ -173,7 +173,7 @@ static bool checkTextureModeList( const osg::StateSet& ss ) static bool readTextureModeList( osgDB::InputStream& is, osg::StateSet& ss ) { - unsigned int size = 0; is >> size >> osgDB::BEGIN_BRACKET; + unsigned int size = is.readSize(); is >> osgDB::BEGIN_BRACKET; osg::StateSet::ModeList modes; for ( unsigned int i=0; i> size >> osgDB::BEGIN_BRACKET; + unsigned int size = is.readSize(); is >> osgDB::BEGIN_BRACKET; osg::StateSet::AttributeList attrs; for ( unsigned int i=0; i> size >> osgDB::BEGIN_BRACKET; + unsigned int size = is.readSize(); is >> osgDB::BEGIN_BRACKET; for ( unsigned int i=0; i( is.readObject() ); @@ -267,7 +267,7 @@ static bool readUniformList( osgDB::InputStream& is, osg::StateSet& ss ) static bool writeUniformList( osgDB::OutputStream& os, const osg::StateSet& ss ) { const osg::StateSet::UniformList& ul = ss.getUniformList(); - os << ul.size() << osgDB::BEGIN_BRACKET << std::endl; + os.writeSize(ul.size()); os << osgDB::BEGIN_BRACKET << std::endl; for ( osg::StateSet::UniformList::const_iterator itr=ul.begin(); itr!=ul.end(); ++itr ) { diff --git a/src/osgWrappers/serializers/osg/TransferFunction1D.cpp b/src/osgWrappers/serializers/osg/TransferFunction1D.cpp index be3d2da44..50e7372b7 100644 --- a/src/osgWrappers/serializers/osg/TransferFunction1D.cpp +++ b/src/osgWrappers/serializers/osg/TransferFunction1D.cpp @@ -10,7 +10,7 @@ static bool checkColorMap( const osg::TransferFunction1D& func ) static bool readColorMap( osgDB::InputStream& is, osg::TransferFunction1D& func ) { - unsigned int size = 0; is >> size >> osgDB::BEGIN_BRACKET; + unsigned int size = is.readSize(); is >> osgDB::BEGIN_BRACKET; for ( unsigned int i=0; i> size >> osgDB::BEGIN_BRACKET; + unsigned int size = is.readSize(); is >> osgDB::BEGIN_BRACKET; for ( unsigned int i=0; i> size >> osgDB::BEGIN_BRACKET; + unsigned int size = is.readSize(); is >> osgDB::BEGIN_BRACKET; for ( unsigned int i=0; i