29 #ifndef CEREAL_ACCESS_HPP_
30 #define CEREAL_ACCESS_HPP_
32 #include <type_traits>
113 namespace memory_detail{
template <
class Ar,
class T>
struct LoadAndConstructLoadWrapper; }
114 namespace boost_variant_detail{
template <
class Ar,
class T>
struct LoadAndConstructLoadWrapper; }
176 template <
class ... Args>
188 throw Exception(
"Object must be initialized prior to accessing members");
207 template <
class Ar,
class TT>
friend struct ::cereal::memory_detail::LoadAndConstructLoadWrapper;
208 template <
class Ar,
class TT>
friend struct ::cereal::boost_variant_detail::LoadAndConstructLoadWrapper;
210 construct( T * p ) : itsPtr( p ), itsEnableSharedRestoreFunction( [](){} ), itsValid(
false ) {}
211 construct( T * p, std::function<
void()> enableSharedFunc ) :
212 itsPtr( p ), itsEnableSharedRestoreFunction( enableSharedFunc ), itsValid( false ) {}
213 construct( construct
const & ) =
delete;
214 construct & operator=( construct
const & ) =
delete;
217 std::function<void()> itsEnableSharedRestoreFunction;
244 template<
class Archive,
class T>
inline
245 static auto member_serialize(Archive & ar, T & t) -> decltype(t.CEREAL_SERIALIZE_FUNCTION_NAME(ar))
246 {
return t.CEREAL_SERIALIZE_FUNCTION_NAME(ar); }
248 template<
class Archive,
class T>
inline
249 static auto member_save(Archive & ar, T
const & t) -> decltype(t.CEREAL_SAVE_FUNCTION_NAME(ar))
250 {
return t.CEREAL_SAVE_FUNCTION_NAME(ar); }
252 template<
class Archive,
class T>
inline
253 static auto member_save_non_const(Archive & ar, T & t) -> decltype(t.CEREAL_SAVE_FUNCTION_NAME(ar))
254 {
return t.CEREAL_SAVE_FUNCTION_NAME(ar); }
256 template<
class Archive,
class T>
inline
257 static auto member_load(Archive & ar, T & t) -> decltype(t.CEREAL_LOAD_FUNCTION_NAME(ar))
258 {
return t.CEREAL_LOAD_FUNCTION_NAME(ar); }
260 template<
class Archive,
class T>
inline
261 static auto member_save_minimal(Archive
const & ar, T
const & t) -> decltype(t.CEREAL_SAVE_MINIMAL_FUNCTION_NAME(ar))
262 {
return t.CEREAL_SAVE_MINIMAL_FUNCTION_NAME(ar); }
264 template<
class Archive,
class T>
inline
265 static auto member_save_minimal_non_const(Archive
const & ar, T & t) -> decltype(t.CEREAL_SAVE_MINIMAL_FUNCTION_NAME(ar))
266 {
return t.CEREAL_SAVE_MINIMAL_FUNCTION_NAME(ar); }
268 template<
class Archive,
class T,
class U>
inline
269 static auto member_load_minimal(Archive
const & ar, T & t, U && u) -> decltype(t.CEREAL_LOAD_MINIMAL_FUNCTION_NAME(ar, std::forward<U>(u)))
270 {
return t.CEREAL_LOAD_MINIMAL_FUNCTION_NAME(ar, std::forward<U>(u)); }
273 template<
class Archive,
class T>
inline
274 static auto member_serialize(Archive & ar, T & t,
const std::uint32_t version ) -> decltype(t.CEREAL_SERIALIZE_FUNCTION_NAME(ar, version))
275 {
return t.CEREAL_SERIALIZE_FUNCTION_NAME(ar, version); }
277 template<
class Archive,
class T>
inline
278 static auto member_save(Archive & ar, T
const & t,
const std::uint32_t version ) -> decltype(t.CEREAL_SAVE_FUNCTION_NAME(ar, version))
279 {
return t.CEREAL_SAVE_FUNCTION_NAME(ar, version); }
281 template<
class Archive,
class T>
inline
282 static auto member_save_non_const(Archive & ar, T & t,
const std::uint32_t version ) -> decltype(t.CEREAL_SAVE_FUNCTION_NAME(ar, version))
283 {
return t.CEREAL_SAVE_FUNCTION_NAME(ar, version); }
285 template<
class Archive,
class T>
inline
286 static auto member_load(Archive & ar, T & t,
const std::uint32_t version ) -> decltype(t.CEREAL_LOAD_FUNCTION_NAME(ar, version))
287 {
return t.CEREAL_LOAD_FUNCTION_NAME(ar, version); }
289 template<
class Archive,
class T>
inline
290 static auto member_save_minimal(Archive
const & ar, T
const & t,
const std::uint32_t version) -> decltype(t.CEREAL_SAVE_MINIMAL_FUNCTION_NAME(ar, version))
291 {
return t.CEREAL_SAVE_MINIMAL_FUNCTION_NAME(ar, version); }
293 template<
class Archive,
class T>
inline
294 static auto member_save_minimal_non_const(Archive
const & ar, T & t,
const std::uint32_t version) -> decltype(t.CEREAL_SAVE_MINIMAL_FUNCTION_NAME(ar, version))
295 {
return t.CEREAL_SAVE_MINIMAL_FUNCTION_NAME(ar, version); }
297 template<
class Archive,
class T,
class U>
inline
298 static auto member_load_minimal(Archive
const & ar, T & t, U && u,
const std::uint32_t version) -> decltype(t.CEREAL_LOAD_MINIMAL_FUNCTION_NAME(ar, std::forward<U>(u), version))
299 {
return t.CEREAL_LOAD_MINIMAL_FUNCTION_NAME(ar, std::forward<U>(u), version); }
303 template <
class T>
inline
304 static auto shared_from_this(T & t) -> decltype(t.shared_from_this());
307 template <
class T,
class ... Args>
inline
308 static void construct( T *& ptr, Args && ... args )
310 new (ptr) T( std::forward<Args>( args )... );
314 template <
class T>
inline
320 template <
class T>
inline
321 static std::false_type load_and_construct(...)
322 {
return std::false_type(); }
324 template<
class T,
class Archive>
inline
330 template<
class T,
class Archive>
inline
333 T::load_and_construct( ar,
construct, version );
339 template <
class T>
template <
class ... Args>
inline
343 throw Exception(
"Attempting to construct an already initialized object");
345 ::cereal::access::construct( itsPtr, std::forward<Args>( args )... );
346 itsEnableSharedRestoreFunction();
351 #endif // CEREAL_ACCESS_HPP_