From 2e96b9915e31fc2b90596e9df597e8fa0f930dee Mon Sep 17 00:00:00 2001 From: David Hirvonen Date: Fri, 25 Nov 2016 16:02:00 -0500 Subject: [PATCH 1/2] Add is_loading and is_saving values to cereal::{Input,Output}Archive This provides compatibility for asymmetric serialize routines when transitioning from boost serialization and associated archive types. See: https://github.com/USCiLab/cereal/issues/360 Example: ``` template void serialize(Archive &ar, const std::uint32_t version) { std::int16_t tmp = foo; if(Archive::is_loading::value) { ar & tmp; foo = tmp; // For illustration only } else { tmp = foo; // For illustration only ar & tmp; } ar & foo; } ``` --- include/cereal/cereal.hpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/include/cereal/cereal.hpp b/include/cereal/cereal.hpp index 4b9a9c11e..188acb8c6 100644 --- a/include/cereal/cereal.hpp +++ b/include/cereal/cereal.hpp @@ -255,6 +255,20 @@ namespace cereal a large project from Boost to cereal. The preferred interface for cereal is using operator(). */ //! @{ + //! 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 */ + using is_loading = std::false_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 */ + using is_saving = std::true_type; + //! 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 @@ -611,6 +625,20 @@ namespace cereal a large project from Boost to cereal. The preferred interface for cereal is using operator(). */ //! @{ + //! Indicates this archive is 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 enable behavior specific to loading, until + you can transition to split save/load or save_minimal/load_minimal functions */ +. using is_loading = std::true_type; + + //! Indicates this archive is not 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 disable behavior specific to loading, until + you can transition to split save/load or save_minimal/load_minimal functions */ + using is_saving = std::false_type; + //! 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 From 6e717666f36de74977cc1524a59222af75c70a19 Mon Sep 17 00:00:00 2001 From: David Hirvonen Date: Sat, 26 Nov 2016 12:31:56 -0500 Subject: [PATCH 2/2] Remove spurious character --- include/cereal/cereal.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/cereal/cereal.hpp b/include/cereal/cereal.hpp index 188acb8c6..a77701037 100644 --- a/include/cereal/cereal.hpp +++ b/include/cereal/cereal.hpp @@ -630,7 +630,7 @@ namespace cereal from boost, you can check this value within a member or external serialize function (i.e., Archive::is_loading::value) to enable behavior specific to loading, until you can transition to split save/load or save_minimal/load_minimal functions */ -. using is_loading = std::true_type; + using is_loading = std::true_type; //! Indicates this archive is not intended for saving /*! This ensures compatibility with boost archive types. If you are transitioning