30 #ifndef CEREAL_TYPES_SHARED_PTR_HPP_
31 #define CEREAL_TYPES_SHARED_PTR_HPP_
39 namespace memory_detail
56 template<
class T>
inline
59 return {std::forward<T>(t)};
66 template <
class Archive,
class T>
178 template <
class Archive,
class T>
inline
197 template <
class Archive,
class T>
inline
206 template <
class Archive,
class T>
inline
214 template <
class Archive,
class T>
inline
222 template <
class Archive,
class T>
inline
226 auto const sptr = ptr.lock();
231 template <
class Archive,
class T>
inline
235 std::shared_ptr<T> sptr;
241 template <
class Archive,
class T,
class D>
inline
249 template <
class Archive,
class T,
class D>
inline
261 template <
class Archive,
class T>
inline
264 auto & ptr = wrapper.ptr;
266 uint32_t id = ar.registerSharedPointer( ptr );
277 template <
class Archive,
class T>
inline
294 auto valid = std::make_shared<bool>(
false );
299 std::shared_ptr<NonConstT> ptr(
reinterpret_cast<NonConstT *
>(
new AlignedStorage()),
305 delete reinterpret_cast<AlignedStorage*
>( t );
309 ar.registerSharedPointer(
id, ptr );
316 wrapper.ptr = std::move(ptr);
319 wrapper.ptr = std::static_pointer_cast<T>(ar.getSharedPointer(
id));
324 template <
class Archive,
class T>
inline
336 ar.registerSharedPointer(
id, ptr );
338 wrapper.ptr = std::move(ptr);
341 wrapper.ptr = std::static_pointer_cast<T>(ar.getSharedPointer(
id));
346 template <
class Archive,
class T,
class D>
inline
349 auto & ptr = wrapper.ptr;
366 template <
class Archive,
class T,
class D>
inline
373 auto & ptr = wrapper.ptr;
380 using AlignedStorage =
typename std::aligned_storage<
sizeof(NonConstT),
CEREAL_ALIGNOF(NonConstT)>
::type;
384 std::unique_ptr<AlignedStorage> stPtr(
new AlignedStorage() );
393 ptr.reset(
reinterpret_cast<T *
>( stPtr.release() ) );
396 ptr.reset(
nullptr );
401 template <
class Archive,
class T,
class D>
inline
413 wrapper.ptr = std::move(ptr);
417 wrapper.ptr.reset(
nullptr );
Main cereal functionality.
Used to construct types with no default constructor.
Definition: access.hpp:165
Definition: memory.hpp:133
std::enable_shared_from_this< BaseType > ParentType
Definition: memory.hpp:136
bool itsRestored
Definition: memory.hpp:170
StorageType itsState
Definition: memory.hpp:169
~EnableSharedStateHelper()
Restores the state of the held pointer if not done previously.
Definition: memory.hpp:162
typename ::cereal::traits::get_shared_from_this_base< T >::type BaseType
Definition: memory.hpp:135
EnableSharedStateHelper(T *ptr)
Saves the state of some type inheriting from enable_shared_from_this.
Definition: memory.hpp:142
typename std::aligned_storage< sizeof(ParentType), CEREAL_ALIGNOF(ParentType)>::type StorageType
Definition: memory.hpp:137
ParentType * itsPtr
Definition: memory.hpp:168
void restore()
Restores the state of the held pointer (can only be done once)
Definition: memory.hpp:151
#define CEREAL_NVP_(name, value)
Convenience for creating a templated NVP.
Definition: helpers.hpp:201
#define CEREAL_ALIGNOF
Checks if C++14 is available.
Definition: macros.hpp:153
type
The type the bitset is encoded with.
Definition: bitset.hpp:44
static const uint32_t msb_32bit
Definition: helpers.hpp:298
PtrWrapper< T > make_ptr_wrapper(T &&t)
Make a PtrWrapper.
Definition: memory.hpp:57
void loadAndConstructSharedPtr(Archive &ar, T *ptr, std::true_type)
Definition: memory.hpp:179
in certain simple scenarios. They should probably not be used if maximizing performance is the main o...
Definition: access.hpp:42
std::enable_if< std::is_arithmetic< T >::value, void >::type CEREAL_LOAD_FUNCTION_NAME(BinaryInputArchive &ar, T &t)
Loading for POD types from binary.
Definition: binary.hpp:126
std::enable_if< std::is_arithmetic< T >::value, void >::type CEREAL_SAVE_FUNCTION_NAME(BinaryOutputArchive &ar, T const &t)
Saving for POD types to binary.
Definition: binary.hpp:118
Definition: json.hpp:5678
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1282
Support for pointers to polymorphic base classes.
unsigned int uint32_t
Definition: stdint.h:126
unsigned char uint8_t
Definition: stdint.h:124
Definition: traits.hpp:1339
static T * load_andor_construct(A &, construct< T > &)
Definition: traits.hpp:1344
A struct that acts as a wrapper around calling load_andor_construct.
Definition: memory.hpp:68
::cereal::construct< T > construct
Definition: memory.hpp:84
void CEREAL_SERIALIZE_FUNCTION_NAME(Archive &ar)
Definition: memory.hpp:79
LoadAndConstructLoadWrapper(T *ptr, F &&sharedFromThisFunc)
Constructor for embedding an early call for restoring shared_from_this.
Definition: memory.hpp:75
LoadAndConstructLoadWrapper(T *ptr)
Definition: memory.hpp:69
A wrapper class to notify cereal that it is ok to serialize the contained pointer.
Definition: memory.hpp:46
PtrWrapper(PtrWrapper const &)=default
PtrWrapper & operator=(PtrWrapper const &)=delete
PtrWrapper(T &&p)
Definition: memory.hpp:47
T & ptr
Definition: memory.hpp:48