mirror of
https://github.com/RPCS3/cereal.git
synced 2024-11-27 05:00:38 +00:00
Added macro guard for restricting serialization type
This commit is contained in:
parent
e66e6d38df
commit
618b9c5815
@ -1,6 +1,7 @@
|
||||
#ifndef CEREAL_BINARY_ARCHIVE_TUPLE_HPP_
|
||||
#define CEREAL_BINARY_ARCHIVE_TUPLE_HPP_
|
||||
|
||||
#include <cereal/details/traits.hpp>
|
||||
#include <cereal/binary_archive/binary_archive.hpp>
|
||||
#include <tuple>
|
||||
|
||||
@ -24,7 +25,8 @@ namespace cereal
|
||||
|
||||
//! Serializing for std::tuple to binary
|
||||
template <class Archive, class ... Types> inline
|
||||
void serialize( Archive & ar, std::tuple<Types...> & tuple )
|
||||
CEREAL_ARCHIVE_RESTRICT_SERIALIZE(BinaryInputArchive, BinaryOutputArchive)
|
||||
serialize( Archive & ar, std::tuple<Types...> & tuple )
|
||||
{
|
||||
tuple_size::serialize<std::tuple_size<std::tuple<Types...>>>( ar, tuple );
|
||||
}
|
||||
|
@ -8,7 +8,8 @@ namespace cereal
|
||||
{
|
||||
//! Serializing for std::pair to binary
|
||||
template <class Archive, class T1, class T2> inline
|
||||
void serialize( Archive & ar, std::pair<T1, T2> & pair )
|
||||
CEREAL_ARCHIVE_RESTRICT_SERIALIZE(BinaryInputArchive, BinaryOutputArchive)
|
||||
serialize( Archive & ar, std::pair<T1, T2> & pair )
|
||||
{
|
||||
ar & pair.first;
|
||||
ar & pair.second;
|
||||
|
@ -105,6 +105,28 @@ namespace cereal
|
||||
{
|
||||
return rank == 0 ? 1 : std::extent<T>::value * sizeofArray<typename std::remove_extent<T>::type>( rank - 1 );
|
||||
}
|
||||
|
||||
// ######################################################################
|
||||
//! A macro to use to restrict which types of archives your serialize function will work for.
|
||||
/*! This requires you to have a template class parameter named Archive and replaces the void return
|
||||
type for your serialize function.
|
||||
|
||||
INTYPE refers to the input archive type you wish to restrict on.
|
||||
OUTTYPE refers to the output archive type you wish to restrict on.
|
||||
|
||||
For example, if we want to limit a serialize to only work with binary serialization:
|
||||
|
||||
@code{.cpp}
|
||||
template <class Archive>
|
||||
CEREAL_ARCHIVE_RESTRICT_SERIALIZE(BinaryInputArchive, BinaryOutputArchive)
|
||||
serialize( Archive & ar, MyCoolType & m )
|
||||
{
|
||||
ar & m;
|
||||
}
|
||||
@endcode
|
||||
*/
|
||||
#define CEREAL_ARCHIVE_RESTRICT_SERIALIZE(INTYPE, OUTTYPE) \
|
||||
typename std::enable_if<std::is_same<Archive, INTYPE>::value || std::is_same<Archive, OUTTYPE>::value, void>::type
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user