mirror of
https://git.salome-platform.org/gitpub/modules/smesh.git
synced 2025-01-26 16:50:34 +05:00
Bug: boost::archive::text_iarchive fails if archive created by newer version
of boost::archive library
This commit is contained in:
parent
cd4aa39efa
commit
ce0f1ae8e9
@ -61,6 +61,7 @@ SET(SMESHUtils_HEADERS
|
|||||||
SMESH_ControlPnt.hxx
|
SMESH_ControlPnt.hxx
|
||||||
SMESH_Delaunay.hxx
|
SMESH_Delaunay.hxx
|
||||||
SMESH_Indexer.hxx
|
SMESH_Indexer.hxx
|
||||||
|
SMESH_BoostTxtArchive.hxx
|
||||||
)
|
)
|
||||||
|
|
||||||
# --- sources ---
|
# --- sources ---
|
||||||
@ -84,6 +85,7 @@ SET(SMESHUtils_SOURCES
|
|||||||
SMESH_Offset.cxx
|
SMESH_Offset.cxx
|
||||||
SMESH_Slot.cxx
|
SMESH_Slot.cxx
|
||||||
SMESH_PolyLine.cxx
|
SMESH_PolyLine.cxx
|
||||||
|
SMESH_BoostTxtArchive.cxx
|
||||||
)
|
)
|
||||||
|
|
||||||
# --- rules ---
|
# --- rules ---
|
||||||
|
152
src/SMESHUtils/SMESH_BoostTxtArchive.cxx
Normal file
152
src/SMESHUtils/SMESH_BoostTxtArchive.cxx
Normal file
@ -0,0 +1,152 @@
|
|||||||
|
// Copyright (C) 2007-2021 CEA/DEN, EDF R&D, OPEN CASCADE
|
||||||
|
//
|
||||||
|
// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
|
||||||
|
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
|
||||||
|
//
|
||||||
|
// This library is free software; you can redistribute it and/or
|
||||||
|
// modify it under the terms of the GNU Lesser General Public
|
||||||
|
// License as published by the Free Software Foundation; either
|
||||||
|
// version 2.1 of the License, or (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This library is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
// Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public
|
||||||
|
// License along with this library; if not, write to the Free Software
|
||||||
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
//
|
||||||
|
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
|
||||||
|
//
|
||||||
|
// File : SMESH_BoostTxtArchive.cxx
|
||||||
|
// Created : Thu Aug 5 21:19:31 2021
|
||||||
|
// Author : Edward AGAPOV (eap)
|
||||||
|
|
||||||
|
#include "SMESH_BoostTxtArchive.hxx"
|
||||||
|
|
||||||
|
#include <cctype>
|
||||||
|
#include <sstream>
|
||||||
|
#include <boost/archive/text_oarchive.hpp>
|
||||||
|
|
||||||
|
|
||||||
|
using namespace SMESHUtils;
|
||||||
|
|
||||||
|
BoostTxtArchive::BoostTxtArchive( const std::string& s ):
|
||||||
|
myArchiveReader( nullptr ),
|
||||||
|
myString( s ),
|
||||||
|
myStringFixed( false ),
|
||||||
|
myStream( nullptr ),
|
||||||
|
myOwnStream( true )
|
||||||
|
{
|
||||||
|
myStream = new std::istringstream( myString );
|
||||||
|
makeReader();
|
||||||
|
}
|
||||||
|
|
||||||
|
BoostTxtArchive::BoostTxtArchive( std::istream& stream ):
|
||||||
|
myArchiveReader( nullptr ),
|
||||||
|
myStringFixed( false ),
|
||||||
|
myStream( &stream ),
|
||||||
|
myOwnStream( false )
|
||||||
|
{
|
||||||
|
if ( std::istringstream * sstrm = dynamic_cast< std::istringstream* >( &stream ))
|
||||||
|
myString = sstrm->str();
|
||||||
|
|
||||||
|
makeReader();
|
||||||
|
}
|
||||||
|
|
||||||
|
BoostTxtArchive::~BoostTxtArchive()
|
||||||
|
{
|
||||||
|
delete myArchiveReader; myArchiveReader = nullptr;
|
||||||
|
if ( myOwnStream )
|
||||||
|
delete myStream;
|
||||||
|
}
|
||||||
|
|
||||||
|
void BoostTxtArchive::makeReader()
|
||||||
|
{
|
||||||
|
myArchiveReader = nullptr;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
myArchiveReader = new boost::archive::text_iarchive( *myStream );
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
if ( fixString() )
|
||||||
|
try
|
||||||
|
{
|
||||||
|
myArchiveReader = new boost::archive::text_iarchive( *myStream );
|
||||||
|
}
|
||||||
|
catch(...)
|
||||||
|
{
|
||||||
|
myArchiveReader = nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
//================================================================================
|
||||||
|
/*!
|
||||||
|
* \brief Return archive created by current version of boost::archive
|
||||||
|
*/
|
||||||
|
//================================================================================
|
||||||
|
|
||||||
|
std::string getCurrentVersionArchive( BoostTxtArchive & bta)
|
||||||
|
{
|
||||||
|
std::ostringstream strm;
|
||||||
|
boost::archive::text_oarchive archive( strm );
|
||||||
|
archive << bta;
|
||||||
|
return strm.str();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//================================================================================
|
||||||
|
/*!
|
||||||
|
* \brief Change boost::archive library version in myString to be equal to
|
||||||
|
* the current library version
|
||||||
|
* \return bool - return true if the version is changed
|
||||||
|
*/
|
||||||
|
//================================================================================
|
||||||
|
|
||||||
|
bool BoostTxtArchive::fixString()
|
||||||
|
{
|
||||||
|
if ( myStringFixed )
|
||||||
|
return false;
|
||||||
|
myStringFixed = true;
|
||||||
|
|
||||||
|
const char* sub = "serialization::archive ";
|
||||||
|
const size_t subLen = 23;
|
||||||
|
|
||||||
|
size_t where1 = myString.find( sub );
|
||||||
|
if ( where1 == std::string::npos )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
std::string nowString = getCurrentVersionArchive( *this );
|
||||||
|
size_t where2 = nowString.find( sub );
|
||||||
|
if ( where2 == std::string::npos )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
bool sameVersion = true;
|
||||||
|
for ( size_t i1 = where1 + subLen, i2 = where2 + subLen;
|
||||||
|
i2 < nowString.size();
|
||||||
|
++i1, ++i2 )
|
||||||
|
{
|
||||||
|
if ( myString[ i1 ] != nowString[ i2 ] )
|
||||||
|
{
|
||||||
|
sameVersion = false;
|
||||||
|
myString[ i1 ] = nowString[ i2 ];
|
||||||
|
}
|
||||||
|
if ( isspace( myString[ i1 ]))
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !sameVersion )
|
||||||
|
{
|
||||||
|
if ( myOwnStream )
|
||||||
|
delete myStream;
|
||||||
|
myStream = new std::istringstream( myString );
|
||||||
|
myOwnStream = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return !sameVersion;
|
||||||
|
}
|
95
src/SMESHUtils/SMESH_BoostTxtArchive.hxx
Normal file
95
src/SMESHUtils/SMESH_BoostTxtArchive.hxx
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
// Copyright (C) 2007-2021 CEA/DEN, EDF R&D, OPEN CASCADE
|
||||||
|
//
|
||||||
|
// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
|
||||||
|
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
|
||||||
|
//
|
||||||
|
// This library is free software; you can redistribute it and/or
|
||||||
|
// modify it under the terms of the GNU Lesser General Public
|
||||||
|
// License as published by the Free Software Foundation; either
|
||||||
|
// version 2.1 of the License, or (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This library is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
// Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public
|
||||||
|
// License along with this library; if not, write to the Free Software
|
||||||
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
//
|
||||||
|
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
|
||||||
|
//
|
||||||
|
// File : SMESH_BoostTxtArchive.hxx
|
||||||
|
// Created : Thu Aug 5 19:10:24 2021
|
||||||
|
// Author : Edward AGAPOV (eap)
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef __SMESH_BoostTxtArchive_HXX__
|
||||||
|
#define __SMESH_BoostTxtArchive_HXX__
|
||||||
|
|
||||||
|
#include "SMESH_Utils.hxx"
|
||||||
|
|
||||||
|
#include <boost/archive/text_iarchive.hpp>
|
||||||
|
|
||||||
|
namespace SMESHUtils
|
||||||
|
{
|
||||||
|
/*!
|
||||||
|
* \brief Load an object from a string created by boost::archive::text_oarchive.
|
||||||
|
*
|
||||||
|
* Try to workaround the issue that loading fails if the archive string
|
||||||
|
* is created by a newer version of boost::archive library.
|
||||||
|
*
|
||||||
|
* Usage: ObjType obj; BoostTxtArchive( arcString ) >> obj;
|
||||||
|
*/
|
||||||
|
class SMESHUtils_EXPORT BoostTxtArchive
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
BoostTxtArchive( const std::string& s );
|
||||||
|
BoostTxtArchive( std::istream& stream );
|
||||||
|
~BoostTxtArchive();
|
||||||
|
|
||||||
|
template< class T >
|
||||||
|
BoostTxtArchive & operator>>( T & t )
|
||||||
|
{
|
||||||
|
if ( myArchiveReader )
|
||||||
|
try
|
||||||
|
{
|
||||||
|
(*myArchiveReader) >> t;
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
if ( fixString() )
|
||||||
|
try
|
||||||
|
{
|
||||||
|
(*myArchiveReader) >> t;
|
||||||
|
}
|
||||||
|
catch(...)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
void makeReader();
|
||||||
|
bool fixString();
|
||||||
|
|
||||||
|
boost::archive::text_iarchive* myArchiveReader;
|
||||||
|
std::string myString; // archive to read
|
||||||
|
bool myStringFixed; // is archive version changed
|
||||||
|
std::istream* myStream; // stream holding myString
|
||||||
|
bool myOwnStream; // is myStream created by me
|
||||||
|
|
||||||
|
// persistence used to create a current version archive
|
||||||
|
friend class boost::serialization::access;
|
||||||
|
template<class Archive>
|
||||||
|
void serialize(Archive & /*ar*/, const unsigned int /*version*/)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
@ -102,6 +102,7 @@
|
|||||||
#include "SMESH_PreMeshInfo.hxx"
|
#include "SMESH_PreMeshInfo.hxx"
|
||||||
#include "SMESH_PythonDump.hxx"
|
#include "SMESH_PythonDump.hxx"
|
||||||
#include "SMESH_ControlsDef.hxx"
|
#include "SMESH_ControlsDef.hxx"
|
||||||
|
#include <SMESH_BoostTxtArchive.hxx>
|
||||||
|
|
||||||
// to pass CORBA exception through SMESH_TRY
|
// to pass CORBA exception through SMESH_TRY
|
||||||
#define SMY_OWN_CATCH catch( SALOME::SALOME_Exception& se ) { throw se; }
|
#define SMY_OWN_CATCH catch( SALOME::SALOME_Exception& se ) { throw se; }
|
||||||
@ -5995,13 +5996,8 @@ bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent,
|
|||||||
aDataset->ReadFromDisk((char*) dataString.data() );
|
aDataset->ReadFromDisk((char*) dataString.data() );
|
||||||
aDataset->CloseOnDisk();
|
aDataset->CloseOnDisk();
|
||||||
|
|
||||||
std::istringstream istream( dataString.data() );
|
|
||||||
boost::archive::text_iarchive archive( istream );
|
|
||||||
std::list< std::list< std::string > > orderEntryLists;
|
std::list< std::list< std::string > > orderEntryLists;
|
||||||
try {
|
SMESHUtils::BoostTxtArchive( dataString ) >> orderEntryLists;
|
||||||
archive >> orderEntryLists;
|
|
||||||
}
|
|
||||||
catch (...) {}
|
|
||||||
|
|
||||||
TListOfListOfInt anOrderIds;
|
TListOfListOfInt anOrderIds;
|
||||||
for ( const std::list< std::string >& entryList : orderEntryLists )
|
for ( const std::list< std::string >& entryList : orderEntryLists )
|
||||||
|
@ -26,14 +26,15 @@
|
|||||||
|
|
||||||
#include "StdMeshers_BlockRenumber.hxx"
|
#include "StdMeshers_BlockRenumber.hxx"
|
||||||
|
|
||||||
#include "SMDS_EdgePosition.hxx"
|
#include <SMDS_EdgePosition.hxx>
|
||||||
#include "SMDS_FacePosition.hxx"
|
#include <SMDS_FacePosition.hxx>
|
||||||
#include "SMESHDS_Mesh.hxx"
|
#include <SMESHDS_Mesh.hxx>
|
||||||
#include "SMESHDS_SubMesh.hxx"
|
#include <SMESHDS_SubMesh.hxx>
|
||||||
#include "SMESH_Algo.hxx"
|
#include <SMESH_Algo.hxx>
|
||||||
#include "SMESH_Mesh.hxx"
|
#include <SMESH_Mesh.hxx>
|
||||||
#include "SMESH_MesherHelper.hxx"
|
#include <SMESH_MesherHelper.hxx>
|
||||||
#include "SMESH_TryCatch.hxx"
|
#include <SMESH_TryCatch.hxx>
|
||||||
|
#include <SMESH_BoostTxtArchive.hxx>
|
||||||
|
|
||||||
#include <BRep_Tool.hxx>
|
#include <BRep_Tool.hxx>
|
||||||
#include <TopExp_Explorer.hxx>
|
#include <TopExp_Explorer.hxx>
|
||||||
@ -41,7 +42,6 @@
|
|||||||
#include <TopoDS.hxx>
|
#include <TopoDS.hxx>
|
||||||
|
|
||||||
#include <boost/archive/text_oarchive.hpp>
|
#include <boost/archive/text_oarchive.hpp>
|
||||||
#include <boost/archive/text_iarchive.hpp>
|
|
||||||
|
|
||||||
//=============================================================================
|
//=============================================================================
|
||||||
/*!
|
/*!
|
||||||
@ -203,11 +203,11 @@ TopoDS_Vertex StdMeshers_RenumberHelper::GetVertex000( const TopTools_MapOfShape
|
|||||||
}
|
}
|
||||||
|
|
||||||
//=======================================================================
|
//=======================================================================
|
||||||
//function : GetVertex000
|
//function : GetVertexAtPoint
|
||||||
//purpose : Find default vertex at (0,0,0) local position
|
//purpose : Return the VERTEX of solid at given point
|
||||||
//=======================================================================
|
//=======================================================================
|
||||||
|
|
||||||
TopoDS_Vertex StdMeshers_RenumberHelper::GetVertexAtPoint( const TopoDS_Shape& solid,
|
TopoDS_Vertex StdMeshers_RenumberHelper::GetVertexAtPoint( const TopoDS_Shape& solid,
|
||||||
const TopoDS_Shape& point )
|
const TopoDS_Shape& point )
|
||||||
{
|
{
|
||||||
if ( !solid.IsNull() && !point.IsNull() && point.ShapeType() == TopAbs_VERTEX )
|
if ( !solid.IsNull() && !point.IsNull() && point.ShapeType() == TopAbs_VERTEX )
|
||||||
@ -296,8 +296,7 @@ istream & StdMeshers_BlockRenumber::LoadFrom(istream & load)
|
|||||||
{
|
{
|
||||||
SMESH_TRY;
|
SMESH_TRY;
|
||||||
|
|
||||||
boost::archive::text_iarchive archive( load );
|
SMESHUtils::BoostTxtArchive( load ) >> *this;
|
||||||
archive >> *this;
|
|
||||||
|
|
||||||
SMESH_CATCH( SMESH::doNothing );
|
SMESH_CATCH( SMESH::doNothing );
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user