Skip to content

Commit

Permalink
Add is_loading and is_saving values to cereal::{Input,Output}Archive
Browse files Browse the repository at this point in the history
This provides compatibility for asymmetric serialize routines when transitioning from boost serialization and associated archive types.

See: USCiLab#360

Example:
```
    template <typename Archive>
    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;
    }
```
  • Loading branch information
headupinclouds committed Nov 25, 2016
1 parent 72d7936 commit 2e96b99
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions include/cereal/cereal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2e96b99

Please sign in to comment.