NDDEM
Public Member Functions | Private Member Functions | Private Attributes | List of all members
cereal::OutputArchive< ArchiveType, Flags > Class Template Reference

The base output archive class. More...

#include <cereal.hpp>

+ Inheritance diagram for cereal::OutputArchive< ArchiveType, Flags >:

Public Member Functions

 OutputArchive (ArchiveType *const derived)
 Construct the output archive. More...
 
OutputArchiveoperator= (OutputArchive const &)=delete
 
template<class ... Types>
ArchiveType & operator() (Types &&... args)
 Serializes all passed in data. More...
 
void serializeDeferments ()
 Serializes any data marked for deferment using defer. More...
 
std::uint32_t registerSharedPointer (const std::shared_ptr< const void > &sharedPointer)
 Registers a shared pointer with the archive. More...
 
std::uint32_t registerPolymorphicType (char const *name)
 Registers a polymorphic type name with the archive. More...
 
- Public Member Functions inherited from cereal::detail::OutputArchiveBase
 OutputArchiveBase ()=default
 
 OutputArchiveBase (OutputArchiveBase &&) CEREAL_NOEXCEPT
 
OutputArchiveBaseoperator= (OutputArchiveBase &&) CEREAL_NOEXCEPT
 
virtual ~OutputArchiveBase () CEREAL_NOEXCEPT=default
 

Private Member Functions

template<class T >
void process (T &&head)
 Serializes data after calling prologue, then calls epilogue. More...
 
template<class T , class ... Other>
void process (T &&head, Other &&... tail)
 Unwinds to process all data. More...
 
template<class T >
ArchiveType & processImpl (virtual_base_class< T > const &b)
 Serialization of a virtual_base_class wrapper. More...
 
template<class T >
ArchiveType & processImpl (base_class< T > const &b)
 Serialization of a base_class wrapper. More...
 
template<class T >
ArchiveType & processImpl (DeferredData< T > const &d)
 
template<class T , PROCESS_IF(member_serialize) >
ArchiveType & processImpl (T const &t)
 Member serialization. More...
 
template<class T , PROCESS_IF(non_member_serialize) >
ArchiveType & processImpl (T const &t)
 Non member serialization. More...
 
template<class T , PROCESS_IF(member_save) >
ArchiveType & processImpl (T const &t)
 Member split (save) More...
 
template<class T , PROCESS_IF(non_member_save) >
ArchiveType & processImpl (T const &t)
 Non member split (save) More...
 
template<class T , PROCESS_IF(member_save_minimal) >
ArchiveType & processImpl (T const &t)
 Member split (save_minimal) More...
 
template<class T , PROCESS_IF(non_member_save_minimal) >
ArchiveType & processImpl (T const &t)
 Non member split (save_minimal) More...
 
template<class T , traits::EnableIf<(Flags &AllowEmptyClassElision), !traits::is_output_serializable< T, ArchiveType >::value, std::is_empty< T >::value > = traits::sfinae>
ArchiveType & processImpl (T const &)
 Empty class specialization. More...
 
template<class T , traits::EnableIf< traits::has_invalid_output_versioning< T, ArchiveType >::value||(!traits::is_output_serializable< T, ArchiveType >::value &&(!(Flags &AllowEmptyClassElision)||((Flags &AllowEmptyClassElision) &&!std::is_empty< T >::value)))> = traits::sfinae>
ArchiveType & processImpl (T const &)
 No matching serialization. More...
 
template<class T >
std::uint32_t registerClassVersion ()
 Registers a class version with the archive and serializes it if necessary. More...
 
template<class T , PROCESS_IF(member_versioned_serialize) >
ArchiveType & processImpl (T const &t)
 Member serialization. More...
 
template<class T , PROCESS_IF(non_member_versioned_serialize) >
ArchiveType & processImpl (T const &t)
 Non member serialization. More...
 
template<class T , PROCESS_IF(member_versioned_save) >
ArchiveType & processImpl (T const &t)
 Member split (save) More...
 
template<class T , PROCESS_IF(non_member_versioned_save) >
ArchiveType & processImpl (T const &t)
 Non member split (save) More...
 
template<class T , PROCESS_IF(member_versioned_save_minimal) >
ArchiveType & processImpl (T const &t)
 Member split (save_minimal) More...
 
template<class T , PROCESS_IF(non_member_versioned_save_minimal) >
ArchiveType & processImpl (T const &t)
 Non member split (save_minimal) More...
 

Private Attributes

std::vector< std::function< void(void)> > itsDeferments
 
ArchiveType *const self
 
std::unordered_set< traits::detail::base_class_id, traits::detail::base_class_id_hashitsBaseClassSet
 A set of all base classes that have been serialized. More...
 
std::unordered_map< void const *, std::uint32_titsSharedPointerMap
 Maps from addresses to pointer ids. More...
 
std::vector< std::shared_ptr< const void > > itsSharedPointerStorage
 Copy of shared pointers used in itsSharedPointerMap to make sure they are kept alive. More...
 
std::uint32_t itsCurrentPointerId
 The id to be given to the next pointer. More...
 
std::unordered_map< char const *, std::uint32_titsPolymorphicTypeMap
 Maps from polymorphic type name strings to ids. More...
 
std::uint32_t itsCurrentPolymorphicTypeId
 The id to be given to the next polymorphic type name. More...
 
std::unordered_set< size_typeitsVersionedTypes
 Keeps track of classes that have versioning information associated with them. More...
 

Boost Transition Layer

Functionality that mirrors the syntax for Boost. This is useful if you are transitioning a large project from Boost to cereal. The preferred interface for cereal is using operator().

using is_loading = std::false_type
 Indicates this archive is not intended for loading. More...
 
using is_saving = std::true_type
 Indicates this archive is intended for saving. More...
 
template<class T >
ArchiveType & operator& (T &&arg)
 Serializes passed in data. More...
 
template<class T >
ArchiveType & operator<< (T &&arg)
 Serializes passed in data. More...
 

Detailed Description

template<class ArchiveType, std::uint32_t Flags = 0>
class cereal::OutputArchive< ArchiveType, Flags >

The base output archive class.

This is the base output archive for all output archives. If you create a custom archive class, it should derive from this, passing itself as a template parameter for the ArchiveType.

The base class provides all of the functionality necessary to properly forward data to the correct serialization functions.

Individual archives should use a combination of prologue and epilogue functions together with specializations of serialize, save, and load to alter the functionality of their serialization.

Template Parameters
ArchiveTypeThe archive type that derives from OutputArchive
FlagsFlags to control advanced functionality. See the Flags enum for more information.

Member Typedef Documentation

◆ is_loading

template<class ArchiveType , std::uint32_t Flags = 0>
using cereal::OutputArchive< ArchiveType, Flags >::is_loading = std::false_type

Indicates this archive is not intended for loading.

This ensures compatibility with boost archive types. If you are transitioning from boost, you can check this value within a member or external serialize function (i.e., Archive::is_loading::value) to disable behavior specific to loading, until you can transition to split save/load or save_minimal/load_minimal functions

◆ is_saving

template<class ArchiveType , std::uint32_t Flags = 0>
using cereal::OutputArchive< ArchiveType, Flags >::is_saving = std::true_type

Indicates this archive is intended for saving.

This ensures compatibility with boost archive types. If you are transitioning from boost, you can check this value within a member or external serialize function (i.e., Archive::is_saving::value) to enable behavior specific to loading, until you can transition to split save/load or save_minimal/load_minimal functions

Constructor & Destructor Documentation

◆ OutputArchive()

template<class ArchiveType , std::uint32_t Flags = 0>
cereal::OutputArchive< ArchiveType, Flags >::OutputArchive ( ArchiveType *const  derived)
inline

Construct the output archive.

Parameters
derivedA pointer to the derived ArchiveType (pass this from the derived archive)

Member Function Documentation

◆ operator&()

template<class ArchiveType , std::uint32_t Flags = 0>
template<class T >
ArchiveType& cereal::OutputArchive< ArchiveType, Flags >::operator& ( T &&  arg)
inline

Serializes passed in data.

This is a boost compatability layer and is not the preferred way of using cereal. If you are transitioning from boost, use this until you can transition to the operator() overload

◆ operator()()

template<class ArchiveType , std::uint32_t Flags = 0>
template<class ... Types>
ArchiveType& cereal::OutputArchive< ArchiveType, Flags >::operator() ( Types &&...  args)
inline

Serializes all passed in data.

This is the primary interface for serializing data with an archive

◆ operator<<()

template<class ArchiveType , std::uint32_t Flags = 0>
template<class T >
ArchiveType& cereal::OutputArchive< ArchiveType, Flags >::operator<< ( T &&  arg)
inline

Serializes passed in data.

This is a boost compatability layer and is not the preferred way of using cereal. If you are transitioning from boost, use this until you can transition to the operator() overload

◆ operator=()

template<class ArchiveType , std::uint32_t Flags = 0>
OutputArchive& cereal::OutputArchive< ArchiveType, Flags >::operator= ( OutputArchive< ArchiveType, Flags > const )
delete

◆ process() [1/2]

template<class ArchiveType , std::uint32_t Flags = 0>
template<class T >
void cereal::OutputArchive< ArchiveType, Flags >::process ( T &&  head)
inlineprivate

Serializes data after calling prologue, then calls epilogue.

◆ process() [2/2]

template<class ArchiveType , std::uint32_t Flags = 0>
template<class T , class ... Other>
void cereal::OutputArchive< ArchiveType, Flags >::process ( T &&  head,
Other &&...  tail 
)
inlineprivate

Unwinds to process all data.

◆ processImpl() [1/17]

template<class ArchiveType , std::uint32_t Flags = 0>
template<class T >
ArchiveType& cereal::OutputArchive< ArchiveType, Flags >::processImpl ( base_class< T > const b)
inlineprivate

Serialization of a base_class wrapper.

See also
base_class

◆ processImpl() [2/17]

template<class ArchiveType , std::uint32_t Flags = 0>
template<class T >
ArchiveType& cereal::OutputArchive< ArchiveType, Flags >::processImpl ( DeferredData< T > const d)
inlineprivate

◆ processImpl() [3/17]

template<class ArchiveType , std::uint32_t Flags = 0>
template<class T , traits::EnableIf<(Flags &AllowEmptyClassElision), !traits::is_output_serializable< T, ArchiveType >::value, std::is_empty< T >::value > = traits::sfinae>
ArchiveType& cereal::OutputArchive< ArchiveType, Flags >::processImpl ( T const )
inlineprivate

Empty class specialization.

◆ processImpl() [4/17]

template<class ArchiveType , std::uint32_t Flags = 0>
template<class T , traits::EnableIf< traits::has_invalid_output_versioning< T, ArchiveType >::value||(!traits::is_output_serializable< T, ArchiveType >::value &&(!(Flags &AllowEmptyClassElision)||((Flags &AllowEmptyClassElision) &&!std::is_empty< T >::value)))> = traits::sfinae>
ArchiveType& cereal::OutputArchive< ArchiveType, Flags >::processImpl ( T const )
inlineprivate

No matching serialization.

Invalid if we have invalid output versioning or we are not output serializable, and either don't allow empty class ellision or allow it but are not serializing an empty class

◆ processImpl() [5/17]

template<class ArchiveType , std::uint32_t Flags = 0>
template<class T , PROCESS_IF(member_serialize) >
ArchiveType& cereal::OutputArchive< ArchiveType, Flags >::processImpl ( T const t)
inlineprivate

Member serialization.

◆ processImpl() [6/17]

template<class ArchiveType , std::uint32_t Flags = 0>
template<class T , PROCESS_IF(non_member_serialize) >
ArchiveType& cereal::OutputArchive< ArchiveType, Flags >::processImpl ( T const t)
inlineprivate

Non member serialization.

◆ processImpl() [7/17]

template<class ArchiveType , std::uint32_t Flags = 0>
template<class T , PROCESS_IF(member_save) >
ArchiveType& cereal::OutputArchive< ArchiveType, Flags >::processImpl ( T const t)
inlineprivate

Member split (save)

◆ processImpl() [8/17]

template<class ArchiveType , std::uint32_t Flags = 0>
template<class T , PROCESS_IF(non_member_save) >
ArchiveType& cereal::OutputArchive< ArchiveType, Flags >::processImpl ( T const t)
inlineprivate

Non member split (save)

◆ processImpl() [9/17]

template<class ArchiveType , std::uint32_t Flags = 0>
template<class T , PROCESS_IF(member_save_minimal) >
ArchiveType& cereal::OutputArchive< ArchiveType, Flags >::processImpl ( T const t)
inlineprivate

Member split (save_minimal)

◆ processImpl() [10/17]

template<class ArchiveType , std::uint32_t Flags = 0>
template<class T , PROCESS_IF(non_member_save_minimal) >
ArchiveType& cereal::OutputArchive< ArchiveType, Flags >::processImpl ( T const t)
inlineprivate

Non member split (save_minimal)

◆ processImpl() [11/17]

template<class ArchiveType , std::uint32_t Flags = 0>
template<class T , PROCESS_IF(member_versioned_serialize) >
ArchiveType& cereal::OutputArchive< ArchiveType, Flags >::processImpl ( T const t)
inlineprivate

Member serialization.

Versioning implementation

◆ processImpl() [12/17]

template<class ArchiveType , std::uint32_t Flags = 0>
template<class T , PROCESS_IF(non_member_versioned_serialize) >
ArchiveType& cereal::OutputArchive< ArchiveType, Flags >::processImpl ( T const t)
inlineprivate

Non member serialization.

Versioning implementation

◆ processImpl() [13/17]

template<class ArchiveType , std::uint32_t Flags = 0>
template<class T , PROCESS_IF(member_versioned_save) >
ArchiveType& cereal::OutputArchive< ArchiveType, Flags >::processImpl ( T const t)
inlineprivate

Member split (save)

Versioning implementation

◆ processImpl() [14/17]

template<class ArchiveType , std::uint32_t Flags = 0>
template<class T , PROCESS_IF(non_member_versioned_save) >
ArchiveType& cereal::OutputArchive< ArchiveType, Flags >::processImpl ( T const t)
inlineprivate

Non member split (save)

Versioning implementation

◆ processImpl() [15/17]

template<class ArchiveType , std::uint32_t Flags = 0>
template<class T , PROCESS_IF(member_versioned_save_minimal) >
ArchiveType& cereal::OutputArchive< ArchiveType, Flags >::processImpl ( T const t)
inlineprivate

Member split (save_minimal)

Versioning implementation

◆ processImpl() [16/17]

template<class ArchiveType , std::uint32_t Flags = 0>
template<class T , PROCESS_IF(non_member_versioned_save_minimal) >
ArchiveType& cereal::OutputArchive< ArchiveType, Flags >::processImpl ( T const t)
inlineprivate

Non member split (save_minimal)

Versioning implementation

◆ processImpl() [17/17]

template<class ArchiveType , std::uint32_t Flags = 0>
template<class T >
ArchiveType& cereal::OutputArchive< ArchiveType, Flags >::processImpl ( virtual_base_class< T > const b)
inlineprivate

Serialization of a virtual_base_class wrapper.

See also
virtual_base_class

◆ registerClassVersion()

template<class ArchiveType , std::uint32_t Flags = 0>
template<class T >
std::uint32_t cereal::OutputArchive< ArchiveType, Flags >::registerClassVersion ( )
inlineprivate

Registers a class version with the archive and serializes it if necessary.

If this is the first time this class has been serialized, we will record its version number and serialize that.

Template Parameters
TThe type of the class being serialized

◆ registerPolymorphicType()

template<class ArchiveType , std::uint32_t Flags = 0>
std::uint32_t cereal::OutputArchive< ArchiveType, Flags >::registerPolymorphicType ( char const name)
inline

Registers a polymorphic type name with the archive.

This function is used to track polymorphic types to prevent unnecessary saves of identifying strings used by the polymorphic support functionality.

◆ registerSharedPointer()

template<class ArchiveType , std::uint32_t Flags = 0>
std::uint32_t cereal::OutputArchive< ArchiveType, Flags >::registerSharedPointer ( const std::shared_ptr< const void > &  sharedPointer)
inline

Registers a shared pointer with the archive.

This function is used to track shared pointer targets to prevent unnecessary saves from taking place if multiple shared pointers point to the same data.

◆ serializeDeferments()

template<class ArchiveType , std::uint32_t Flags = 0>
void cereal::OutputArchive< ArchiveType, Flags >::serializeDeferments ( )
inline

Serializes any data marked for deferment using defer.

This will cause any data wrapped in DeferredData to be immediately serialized

Member Data Documentation

◆ itsBaseClassSet

template<class ArchiveType , std::uint32_t Flags = 0>
std::unordered_set<traits::detail::base_class_id, traits::detail::base_class_id_hash> cereal::OutputArchive< ArchiveType, Flags >::itsBaseClassSet
private

A set of all base classes that have been serialized.

◆ itsCurrentPointerId

template<class ArchiveType , std::uint32_t Flags = 0>
std::uint32_t cereal::OutputArchive< ArchiveType, Flags >::itsCurrentPointerId
private

The id to be given to the next pointer.

◆ itsCurrentPolymorphicTypeId

template<class ArchiveType , std::uint32_t Flags = 0>
std::uint32_t cereal::OutputArchive< ArchiveType, Flags >::itsCurrentPolymorphicTypeId
private

The id to be given to the next polymorphic type name.

◆ itsDeferments

template<class ArchiveType , std::uint32_t Flags = 0>
std::vector<std::function<void(void)> > cereal::OutputArchive< ArchiveType, Flags >::itsDeferments
private

◆ itsPolymorphicTypeMap

template<class ArchiveType , std::uint32_t Flags = 0>
std::unordered_map<char const *, std::uint32_t> cereal::OutputArchive< ArchiveType, Flags >::itsPolymorphicTypeMap
private

Maps from polymorphic type name strings to ids.

◆ itsSharedPointerMap

template<class ArchiveType , std::uint32_t Flags = 0>
std::unordered_map<void const *, std::uint32_t> cereal::OutputArchive< ArchiveType, Flags >::itsSharedPointerMap
private

Maps from addresses to pointer ids.

◆ itsSharedPointerStorage

template<class ArchiveType , std::uint32_t Flags = 0>
std::vector<std::shared_ptr<const void> > cereal::OutputArchive< ArchiveType, Flags >::itsSharedPointerStorage
private

Copy of shared pointers used in itsSharedPointerMap to make sure they are kept alive.

◆ itsVersionedTypes

template<class ArchiveType , std::uint32_t Flags = 0>
std::unordered_set<size_type> cereal::OutputArchive< ArchiveType, Flags >::itsVersionedTypes
private

Keeps track of classes that have versioning information associated with them.

◆ self

template<class ArchiveType , std::uint32_t Flags = 0>
ArchiveType* const cereal::OutputArchive< ArchiveType, Flags >::self
private

The documentation for this class was generated from the following file: