2020-03-28 15:21:10 +00:00
|
|
|
// Copyright 2020 Citra Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2020-01-02 00:45:58 +00:00
|
|
|
#pragma once
|
2020-03-28 15:21:10 +00:00
|
|
|
|
2019-12-24 17:49:56 +00:00
|
|
|
#include <boost/serialization/serialization.hpp>
|
|
|
|
|
2020-03-29 15:14:36 +00:00
|
|
|
/// 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
|
2019-12-24 17:49:56 +00:00
|
|
|
class construct_access {
|
|
|
|
public:
|
2019-12-27 21:07:29 +00:00
|
|
|
template <class Archive, class T>
|
2020-03-29 15:14:36 +00:00
|
|
|
static void save_construct(Archive& ar, const T* t, const unsigned int file_version) {
|
2019-12-24 17:49:56 +00:00
|
|
|
t->save_construct(ar, file_version);
|
|
|
|
}
|
2019-12-27 21:07:29 +00:00
|
|
|
template <class Archive, class T>
|
2020-03-29 15:14:36 +00:00
|
|
|
static void load_construct(Archive& ar, T* t, const unsigned int file_version) {
|
2019-12-24 17:49:56 +00:00
|
|
|
T::load_construct(ar, t, file_version);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-12-27 21:07:29 +00:00
|
|
|
#define BOOST_SERIALIZATION_CONSTRUCT(T) \
|
2020-03-29 15:14:36 +00:00
|
|
|
namespace boost::serialization { \
|
2019-12-27 21:07:29 +00:00
|
|
|
template <class Archive> \
|
2020-03-29 15:14:36 +00:00
|
|
|
void save_construct_data(Archive& ar, const T* t, const unsigned int file_version) { \
|
2019-12-27 21:07:29 +00:00
|
|
|
construct_access::save_construct(ar, t, file_version); \
|
|
|
|
} \
|
|
|
|
template <class Archive> \
|
2020-03-29 15:14:36 +00:00
|
|
|
void load_construct_data(Archive& ar, T* t, const unsigned int file_version) { \
|
2019-12-27 21:07:29 +00:00
|
|
|
construct_access::load_construct(ar, t, file_version); \
|
|
|
|
} \
|
|
|
|
}
|