Merge pull request #1462

07b9138c support importing unportable outputs (kenshi84)
2ac80075 also use portable serializer for boost_serialization_helper.h and net_node.inl, completely adandon boost/archive/binary_oarchive.hpp (kenshi84)
d1d6e27a moved boost cpp into hpp since they're supposed to be header only (kenshi84)
66e6af89 added experimental boost::archive::portable_binary_{i|o}archive (kenshi84)
This commit is contained in:
Riccardo Spagni 2016-12-20 17:40:11 +02:00
commit b9b9028e50
No known key found for this signature in database
GPG key ID: 55432DF31CCD4FCD
12 changed files with 783 additions and 34 deletions

View file

@ -30,8 +30,9 @@
#pragma once
#include <boost/archive/binary_oarchive.hpp>
#include <boost/archive/binary_iarchive.hpp>
#include <boost/archive/portable_binary_oarchive.hpp>
#include <boost/archive/portable_binary_iarchive.hpp>
namespace tools
@ -75,7 +76,7 @@ namespace tools
return false;
#endif
boost::archive::binary_oarchive a(data_file);
boost::archive::portable_binary_oarchive a(data_file);
a << obj;
if (data_file.fail())
return false;
@ -99,9 +100,23 @@ namespace tools
data_file.open( file_path, std::ios_base::binary | std::ios_base::in);
if(data_file.fail())
return false;
boost::archive::binary_iarchive a(data_file);
a >> obj;
try
{
// first try reading in portable mode
boost::archive::portable_binary_iarchive a(data_file);
a >> obj;
}
catch(...)
{
// if failed, try reading in unportable mode
boost::filesystem::copy_file(file_path, file_path + ".unportable", boost::filesystem::copy_option::overwrite_if_exists);
data_file.close();
data_file.open( file_path, std::ios_base::binary | std::ios_base::in);
if(data_file.fail())
return false;
boost::archive::binary_iarchive a(data_file);
a >> obj;
}
return !data_file.fail();
CATCH_ENTRY_L0("unserialize_obj_from_file", false);
}