diff --git a/.gitignore b/.gitignore index 430bb1c4..74b75a91 100644 --- a/.gitignore +++ b/.gitignore @@ -23,6 +23,7 @@ *.log *.tlog* +# misc files mostly used for testing out.txt ptr.txt test.txt @@ -30,9 +31,9 @@ unittests boost_serialize arr.txt performance -./sandbox -./sandbox_rtti -./sandbox_json +sandbox +sandbox_json +sandbox_rtti include_renamed .ycm_extra_conf.py* doc/html diff --git a/include/cereal/cereal.hpp b/include/cereal/cereal.hpp index 321915a8..3231c0db 100644 --- a/include/cereal/cereal.hpp +++ b/include/cereal/cereal.hpp @@ -384,6 +384,9 @@ namespace cereal //! The id to be given to the next polymorphic type name std::uint32_t itsCurrentPolymorphicTypeId; + + //! Keeps track of classes that have versioning information associated with them + std::unordered_set itsVersionedTypes; }; // class OutputArchive // ###################################################################### diff --git a/include/cereal/details/helpers.hpp b/include/cereal/details/helpers.hpp index 866faac4..df4571ab 100644 --- a/include/cereal/details/helpers.hpp +++ b/include/cereal/details/helpers.hpp @@ -36,7 +36,6 @@ namespace cereal { - //! The size type used by cereal /*! To ensure compatability between 32, 64, etc bit machines, we need to use * a fixed size type instead of size_t, which may vary from machine to @@ -305,6 +304,16 @@ namespace cereal { return {std::forward(key), std::forward(value)}; } + + //! Defines a class version for some type + /*! This is part of the Boost Transition Layer and is not the recommended way + of using cereal. This works identically to how it does in Boost serialization, + providing a version number associated with some type that is available by specifying + a second parameter to serialize, save, or load. */ + #define CEREAL_CLASS_VERSION(TYPE, VERSION_NUMBER) \ + namespace cereal { namespace detail { \ + template <> struct Version { static const std::uint32_t version = VERSION_NUMBER; };\ + } } // end namespaces } // namespace cereal #endif // CEREAL_DETAILS_HELPERS_HPP_ diff --git a/include/cereal/details/traits.hpp b/include/cereal/details/traits.hpp index f321176f..37c768b1 100644 --- a/include/cereal/details/traits.hpp +++ b/include/cereal/details/traits.hpp @@ -316,7 +316,6 @@ namespace cereal struct base_class_id_hash { size_t operator()(base_class_id const & id) const { return id.hash; } }; } // namespace detail - // ###################################################################### //! A macro to use to restrict which types of archives your function will work for. /*! This requires you to have a template class parameter named Archive and replaces the void return @@ -388,6 +387,9 @@ namespace cereal return LoadAndAllocate::load_and_allocate( ar ); } }; + + //! Version information class - used in Boost Transition Layer + template struct Version; } // namespace detail } // namespace cereal diff --git a/sandbox.cpp b/sandbox.cpp index fa092ffc..ec741c2f 100644 --- a/sandbox.cpp +++ b/sandbox.cpp @@ -656,3 +656,5 @@ int main() return 0; } + +CEREAL_CLASS_VERSION(std::vector, 1);