construct.h
1 // Copyright 2020 Citra Emulator Project 2 // Licensed under GPLv2 or any later version 3 // Refer to the license.txt file included. 4 5 #pragma once 6 7 #include <boost/serialization/serialization.hpp> 8 9 /// Allows classes to define `save_construct` and `load_construct` methods for serialization 10 /// This is used where we don't call the default constructor during deserialization, as a shortcut 11 /// instead of using load_construct_data directly 12 class construct_access { 13 public: 14 template <class Archive, class T> 15 static void save_construct(Archive& ar, const T* t, const unsigned int file_version) { 16 t->save_construct(ar, file_version); 17 } 18 template <class Archive, class T> 19 static void load_construct(Archive& ar, T* t, const unsigned int file_version) { 20 T::load_construct(ar, t, file_version); 21 } 22 }; 23 24 #define BOOST_SERIALIZATION_CONSTRUCT(T) \ 25 namespace boost::serialization { \ 26 template <class Archive> \ 27 void save_construct_data(Archive& ar, const T* t, const unsigned int file_version) { \ 28 construct_access::save_construct(ar, t, file_version); \ 29 } \ 30 template <class Archive> \ 31 void load_construct_data(Archive& ar, T* t, const unsigned int file_version) { \ 32 construct_access::load_construct(ar, t, file_version); \ 33 } \ 34 }