1 // Copyright (C) 2007-2021 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : SMESH_BoostTxtArchive.cxx
23 // Created : Thu Aug 5 21:19:31 2021
24 // Author : Edward AGAPOV (eap)
26 #include "SMESH_BoostTxtArchive.hxx"
30 #include <boost/archive/text_oarchive.hpp>
33 using namespace SMESHUtils;
35 BoostTxtArchive::BoostTxtArchive( const std::string& s ):
36 myArchiveReader( nullptr ),
38 myStringFixed( false ),
42 myStream = new std::istringstream( myString );
46 BoostTxtArchive::BoostTxtArchive( std::istream& stream ):
47 myArchiveReader( nullptr ),
48 myStringFixed( false ),
52 if ( std::istringstream * sstrm = dynamic_cast< std::istringstream* >( &stream ))
53 myString = sstrm->str();
58 BoostTxtArchive::~BoostTxtArchive()
60 delete myArchiveReader; myArchiveReader = nullptr;
65 void BoostTxtArchive::makeReader()
67 myArchiveReader = nullptr;
70 myArchiveReader = new boost::archive::text_iarchive( *myStream );
77 myArchiveReader = new boost::archive::text_iarchive( *myStream );
81 myArchiveReader = nullptr;
88 //================================================================================
90 * \brief Return archive created by current version of boost::archive
92 //================================================================================
94 std::string getCurrentVersionArchive( BoostTxtArchive & bta)
96 std::ostringstream strm;
97 boost::archive::text_oarchive archive( strm );
103 //================================================================================
105 * \brief Change boost::archive library version in myString to be equal to
106 * the current library version
107 * \return bool - return true if the version is changed
109 //================================================================================
111 bool BoostTxtArchive::fixString()
115 myStringFixed = true;
117 const char* sub = "serialization::archive ";
118 const size_t subLen = 23;
120 size_t where1 = myString.find( sub );
121 if ( where1 == std::string::npos )
124 std::string nowString = getCurrentVersionArchive( *this );
125 size_t where2 = nowString.find( sub );
126 if ( where2 == std::string::npos )
129 bool sameVersion = true;
130 for ( size_t i1 = where1 + subLen, i2 = where2 + subLen;
131 i2 < nowString.size();
134 if ( myString[ i1 ] != nowString[ i2 ] )
137 myString[ i1 ] = nowString[ i2 ];
139 if ( isspace( myString[ i1 ]))
147 myStream = new std::istringstream( myString );