1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
// Copyright (C) 2016 EDF
// All Rights Reserved
// This code is published under the GNU Lesser General Public License (GNU LGPL)
#ifndef STDSHAREDPTRSERIALIZATION_H
#define STDSHAREDPTRSERIALIZATION_H
#include <boost/serialization/split_free.hpp>
#include <boost/unordered_map.hpp>
//---/ Wrapper for std::shared_ptr<> /------------------------------------------
namespace boost
{
namespace serialization
{
template<class Archive, class Type>
void save(Archive &archive, const std::shared_ptr<Type> &value, const unsigned int /*version*/)
{
Type *data = value.get();
archive << data;
}
template<class Archive, class Type>
void load(Archive &archive, std::shared_ptr<Type> &value, const unsigned int /*version*/)
{
Type *data;
archive >> data;
typedef std::weak_ptr<Type> WeakPtr;
static boost::unordered_map<void *, WeakPtr> hash;
if (hash[data].expired())
{
value = std::shared_ptr<Type>(data);
hash[data] = value;
}
else value = hash[data].lock();
}
template<class Archive, class Type>
inline void serialize(Archive &archive, std::shared_ptr<Type> &value, const unsigned int version)
{
split_free(archive, value, version);
}
}
}
#endif
|