29#ifndef CEREAL_ACCESS_HPP_
30#define CEREAL_ACCESS_HPP_
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();
A class that can be made a friend to give cereal access to non public functions.
Definition: access.hpp:241
Used to construct types with no default constructor.
Definition: access.hpp:165
T * ptr()
Returns a raw pointer to the initialized underlying object.
Definition: access.hpp:201
void operator()(Args &&... args)
Construct and initialize the type T with the given arguments.
Definition: access.hpp:340
T * operator->()
Get a reference to the initialized underlying object.
Definition: access.hpp:185
Internal helper functionality.
Preprocessor macros that can customise the cereal library.
Serialization disambiguation.
An exception class thrown when things go wrong at runtime.
Definition: helpers.hpp:49
A class that allows cereal to load smart pointers to types that have no default constructor.
Definition: access.hpp:109