Code review - general gardening

This commit is contained in:
Hamish Milne 2020-03-29 16:14:36 +01:00
parent 8f059ae398
commit 04aa351c40
10 changed files with 125 additions and 88 deletions

View file

@ -6,28 +6,29 @@
#include <boost/serialization/serialization.hpp>
/// Allows classes to define `save_construct` and `load_construct` methods for serialization
/// This is used where we don't call the default constructor during deserialization, as a shortcut
/// instead of using load_construct_data directly
class construct_access {
public:
template <class Archive, class T>
static inline void save_construct(Archive& ar, const T* t, const unsigned int file_version) {
static void save_construct(Archive& ar, const T* t, const unsigned int file_version) {
t->save_construct(ar, file_version);
}
template <class Archive, class T>
static inline void load_construct(Archive& ar, T* t, const unsigned int file_version) {
static void load_construct(Archive& ar, T* t, const unsigned int file_version) {
T::load_construct(ar, t, file_version);
}
};
#define BOOST_SERIALIZATION_CONSTRUCT(T) \
namespace boost { \
namespace serialization { \
namespace boost::serialization { \
template <class Archive> \
inline void save_construct_data(Archive& ar, const T* t, const unsigned int file_version) { \
void save_construct_data(Archive& ar, const T* t, const unsigned int file_version) { \
construct_access::save_construct(ar, t, file_version); \
} \
template <class Archive> \
inline void load_construct_data(Archive& ar, T* t, const unsigned int file_version) { \
void load_construct_data(Archive& ar, T* t, const unsigned int file_version) { \
construct_access::load_construct(ar, t, file_version); \
} \
} \
}