From 7ef5a9311bc1245fc98f5352a254aba895bcf492 Mon Sep 17 00:00:00 2001 From: Shane Grant Date: Sat, 21 Dec 2013 21:22:46 -0800 Subject: [PATCH] Making some changes on vs2013, replacing some typedefs with using statements now that those are cool --- include/cereal/access.hpp | 7 +- include/cereal/details/helpers.hpp | 40 ++-- unittests.cpp | 94 ++++++++ vs2013/performance/performance.vcxproj | 274 +++++++++++------------ vs2013/sandbox_vs/sandbox_vs.vcxproj | 12 +- vs2013/unittests/unittests.vcxproj | 289 +++++++++++++------------ 6 files changed, 407 insertions(+), 309 deletions(-) diff --git a/include/cereal/access.hpp b/include/cereal/access.hpp index 101c6d43..c4bfb4cd 100644 --- a/include/cereal/access.hpp +++ b/include/cereal/access.hpp @@ -126,24 +126,25 @@ namespace cereal static auto member_load(Archive & ar, T & t) -> decltype(t.load(ar)) { t.load(ar); } - /*! @name Boost Transition Layer */ - //! @{ + // versioned member serialize template inline static auto member_serialize(Archive & ar, T & t, const std::uint32_t version ) -> decltype(t.serialize(ar, version)) { t.serialize(ar, version); } + // versioned member save template inline static auto member_save(Archive & ar, T const & t, const std::uint32_t version ) -> decltype(t.save(ar, version)) { t.save(ar, version); } + // versioned member save (non const) template inline static auto member_save_non_const(Archive & ar, T & t, const std::uint32_t version ) -> decltype(t.save(ar, version)) { t.save(ar, version); } + // versioned member load template inline static auto member_load(Archive & ar, T & t, const std::uint32_t version ) -> decltype(t.load(ar, version)) { t.load(ar, version); } - //! @} template static void load_and_allocate(...) diff --git a/include/cereal/details/helpers.hpp b/include/cereal/details/helpers.hpp index aef7a121..0aa5099d 100644 --- a/include/cereal/details/helpers.hpp +++ b/include/cereal/details/helpers.hpp @@ -43,7 +43,7 @@ namespace 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 * machine. */ - typedef uint64_t size_type; + using size_type = uint64_t; // forward decls class BinaryOutputArchive; @@ -126,12 +126,12 @@ namespace cereal // otherwise, we store a reference. If we were passed an array, don't // decay the type - keep it as an array, and then proceed as normal // with the RValue business - typedef typename std::conditional::type>::value, - typename std::remove_cv::type, - typename std::decay::type>::type DT; - typedef typename std::conditional::value, - DT, - typename std::add_lvalue_reference
::type>::type Type; + using DT = typename std::conditional::type>::value, + typename std::remove_cv::type, + typename std::decay::type>::type; + using Type = typename std::conditional::value, + DT, + typename std::add_lvalue_reference
::type>::type; // prevent nested nvps static_assert( !std::is_base_of::value, "Cannot pair a name to a NameValuePair" ); @@ -195,9 +195,9 @@ namespace cereal { //! Internally store the pointer as a void *, keeping const if created with //! a const pointer - typedef typename std::conditional::type>::value, - const void *, - void *>::type PT; + using PT = typename std::conditional::type>::value, + const void *, + void *>::type; BinaryData( T && d, uint64_t s ) : data(d), size(s) {} @@ -236,10 +236,10 @@ namespace cereal private: // If we get passed an RValue, we'll just make a local copy if it here // otherwise, we store a reference - typedef typename std::decay::type DT; - typedef typename std::conditional::value, - DT, - typename std::add_lvalue_reference
::type>::type Type; + using DT = typename std::decay::type; + using Type = typename std::conditional::value, + DT, + typename std::add_lvalue_reference
::type>::type; public: SizeTag( T && sz ) : size(const_cast(sz)) {} @@ -271,17 +271,17 @@ namespace cereal template struct MapItem { - typedef typename std::decay::type DecayKey; - typedef typename std::conditional< + using DecayKey = typename std::decay::type; + using KeyType = typename std::conditional< std::is_rvalue_reference::value, DecayKey, - typename std::add_lvalue_reference::type>::type KeyType; + typename std::add_lvalue_reference::type>::type; - typedef typename std::decay::type DecayValue; - typedef typename std::conditional< + using DecayValue = typename std::decay::type; + using ValueType = typename std::conditional< std::is_rvalue_reference::value, DecayValue, - typename std::add_lvalue_reference::type>::type ValueType; + typename std::add_lvalue_reference::type>::type; //! Construct a MapItem from a key and a value /*! @internal */ diff --git a/unittests.cpp b/unittests.cpp index c1e8a9ee..32135a2e 100644 --- a/unittests.cpp +++ b/unittests.cpp @@ -3134,3 +3134,97 @@ BOOST_AUTO_TEST_CASE( json_unordered_loads ) { test_unordered_loads(); } + +// ###################################################################### +struct VersionStructMS +{ + bool x; + std::uint32_t v; + template + void serialize( Archive & ar, std::uint32_t const version ) + { + ar( x ); + std::cerr << "VersionStructMS " << version << std::endl; + v = version; + } +}; + +struct VersionStructMSP +{ + uint8_t x; + std::uint32_t v; + template + void save( Archive & ar, std::uint32_t const version ) const + { + ar( x ); + std::cerr << "VersionStructMSP Save " << version << std::endl; + } + + template + void load( Archive & ar, std::uint32_t const version ) + { + ar( x ); + v = version; + std::cerr << "VersionStructMSP Load " << version << std::endl; + } +}; + +CEREAL_CLASS_VERSION( VersionStructMSP, 33 ) + +template +void test_versioning() +{ + std::random_device rd; + std::mt19937 gen(rd()); + + for(size_t i=0; i<100; ++i) + { + VersionStructMS o_MS = {random_value(gen) % 2 ? true : false, -1}; + VersionStructMSP o_MSP = {random_value(gen), -1}; + + std::ostringstream os; + { + OArchive oar(os); + OArchive oar2(std::cout); + oar( o_MS ); + oar( o_MSP ); + oar2( o_MS ); + oar2( o_MSP ); + } + + decltype(o_MS) i_MS; + decltype(o_MSP) i_MSP; + + std::istringstream is(os.str()); + { + IArchive iar(is); + iar( i_MS ); + iar( i_MSP ); + } + + BOOST_CHECK_EQUAL(o_MS.x, i_MS.x); + BOOST_CHECK_EQUAL(i_MS.v, 0); + BOOST_CHECK_EQUAL(o_MSP.x, i_MSP.x); + BOOST_CHECK_EQUAL(i_MSP.v, 33); + } +} + +BOOST_AUTO_TEST_CASE( binary_versioning ) +{ + test_versioning(); +} + +BOOST_AUTO_TEST_CASE( portable_binary_versioning ) +{ + test_versioning(); +} + +BOOST_AUTO_TEST_CASE( xml_versioning ) +{ + test_versioning(); +} + +BOOST_AUTO_TEST_CASE( json_versioning ) +{ + test_versioning(); +} \ No newline at end of file diff --git a/vs2013/performance/performance.vcxproj b/vs2013/performance/performance.vcxproj index 6a312712..0db8ba91 100644 --- a/vs2013/performance/performance.vcxproj +++ b/vs2013/performance/performance.vcxproj @@ -1,138 +1,138 @@ - - - - - Debug - Win32 - - - Debug - x64 - - - Release - Win32 - - - Release - x64 - - - - {2F374733-FCA8-4CBB-91A0-2B0B34393D86} - performance - - - - Application - true - v120 - MultiByte - - - Application - true - v120 - MultiByte - - - Application - false - v120 - true - MultiByte - - - Application - false - v120 - true - MultiByte - - - - - - - - - - - - - - - - - - - $(SolutionDir)\..\include;C:\Boost\include\boost-1_55;$(IncludePath) - C:\Boost\lib;$(LibraryPath) - - - $(SolutionDir)\..\include;C:\Boost\include\boost-1_55;$(IncludePath) - C:\Boost\lib\x64;$(LibraryPath) - - - $(SolutionDir)\..\include;C:\Boost\include\boost-1_55;$(IncludePath) - C:\Boost\lib;$(LibraryPath) - - - $(SolutionDir)\..\include;C:\Boost\include\boost-1_55;$(IncludePath) - C:\Boost\lib\x64;$(LibraryPath) - - - - Level3 - Disabled - true - - - true - - - - - Level3 - Disabled - true - - - true - - - - - Level3 - MaxSpeed - true - true - true - - - true - true - true - - - - - Level3 - MaxSpeed - true - true - true - - - true - true - true - - - - - - - - + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {2F374733-FCA8-4CBB-91A0-2B0B34393D86} + performance + + + + Application + true + v120 + MultiByte + + + Application + true + v120 + MultiByte + + + Application + false + v120 + true + MultiByte + + + Application + false + v120 + true + MultiByte + + + + + + + + + + + + + + + + + + + $(SolutionDir)\..\include;E:\Boost\include\boost-1_55;$(IncludePath) + E:\Boost\lib;$(LibraryPath) + + + $(SolutionDir)\..\include;E:\Boost\include\boost-1_55;$(IncludePath) + E:\Boost\lib\x64;$(LibraryPath) + + + $(SolutionDir)\..\include;E:\Boost\include\boost-1_55;$(IncludePath) + E:\Boost\lib;$(LibraryPath) + + + $(SolutionDir)\..\include;E:\Boost\include\boost-1_55;$(IncludePath) + E:\Boost\lib\x64;$(LibraryPath) + + + + Level3 + Disabled + true + + + true + + + + + Level3 + Disabled + true + + + true + + + + + Level3 + MaxSpeed + true + true + true + + + true + true + true + + + + + Level3 + MaxSpeed + true + true + true + + + true + true + true + + + + + + + + \ No newline at end of file diff --git a/vs2013/sandbox_vs/sandbox_vs.vcxproj b/vs2013/sandbox_vs/sandbox_vs.vcxproj index dbb41bce..aa4f133b 100644 --- a/vs2013/sandbox_vs/sandbox_vs.vcxproj +++ b/vs2013/sandbox_vs/sandbox_vs.vcxproj @@ -66,18 +66,18 @@ - $(SolutionDir)\..\include;C:\Boost\include\boost-1_55;$(IncludePath) - C:\Boost\lib;$(LibraryPath) + $(SolutionDir)\..\include;E:\Boost\include\boost-1_55;$(IncludePath) + E:\Boost\lib;$(LibraryPath) - $(SolutionDir)\..\include;C:\Boost\include\boost-1_55;$(IncludePath) + $(SolutionDir)\..\include;E:\Boost\include\boost-1_55;$(IncludePath) - $(SolutionDir)\..\include;C:\Boost\include\boost-1_55;$(IncludePath) - C:\Boost\lib;$(LibraryPath) + $(SolutionDir)\..\include;E:\Boost\include\boost-1_55;$(IncludePath) + E:\Boost\lib;$(LibraryPath) - $(SolutionDir)\..\include;C:\Boost\include\boost-1_55;$(IncludePath) + $(SolutionDir)\..\include;E:\Boost\include\boost-1_55;$(IncludePath) diff --git a/vs2013/unittests/unittests.vcxproj b/vs2013/unittests/unittests.vcxproj index 337b4b2f..3c56f288 100644 --- a/vs2013/unittests/unittests.vcxproj +++ b/vs2013/unittests/unittests.vcxproj @@ -1,144 +1,147 @@ - - - - - Debug - Win32 - - - Debug - x64 - - - Release - Win32 - - - Release - x64 - - - - {D447E13A-97A4-4907-9F61-A9BCCDB91EF7} - unittests - - - - Application - true - v120 - MultiByte - - - Application - true - v120 - MultiByte - - - Application - false - v120 - true - MultiByte - - - Application - false - v120 - true - MultiByte - - - - - - - - - - - - - - - - - - - $(SolutionDir)\..\include;C:\Boost\include\boost-1_55;$(IncludePath) - C:\Boost\lib;$(LibraryPath) - - - $(SolutionDir)\..\include;C:\Boost\include\boost-1_55;$(IncludePath) - C:\Boost\lib\x64;$(LibraryPath) - - - $(SolutionDir)\..\include;C:\Boost\include\boost-1_55;$(IncludePath) - C:\Boost\lib;$(LibraryPath) - - - $(SolutionDir)\..\include;C:\Boost\include\boost-1_55;$(IncludePath) - C:\Boost\lib\x64;$(LibraryPath) - - - - Level3 - Disabled - true - true - - - true - %(AdditionalDependencies) - NotSet - Console - - - - - Level3 - Disabled - true - /bigobj %(AdditionalOptions) - - - true - - - - - Level3 - MaxSpeed - true - true - true - - - true - true - true - %(AdditionalDependencies) - - - - - Level3 - MaxSpeed - true - true - true - - - true - true - true - - - - - - - - + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {D447E13A-97A4-4907-9F61-A9BCCDB91EF7} + unittests + + + + Application + true + v120 + MultiByte + + + Application + true + v120 + MultiByte + + + Application + false + v120 + true + MultiByte + + + Application + false + v120 + true + MultiByte + + + + + + + + + + + + + + + + + + + $(SolutionDir)\..\include;E:\Boost\include\boost-1_55;$(IncludePath) + E:\Boost\lib;$(LibraryPath) + + + $(SolutionDir)\..\include;E:\Boost\include\boost-1_55;$(IncludePath) + E:\Boost\lib\x64;$(LibraryPath) + + + $(SolutionDir)\..\include;E:\Boost\include\boost-1_55;$(IncludePath) + E:\Boost\lib;$(LibraryPath) + + + $(SolutionDir)\..\include;E:\Boost\include\boost-1_55;$(IncludePath) + E:\Boost\lib\x64;$(LibraryPath) + + + + Level3 + Disabled + true + true + /bigobj %(AdditionalOptions) + + + true + %(AdditionalDependencies) + NotSet + Console + + + + + Level3 + Disabled + true + /bigobj %(AdditionalOptions) + + + true + + + + + Level3 + MaxSpeed + true + true + true + /bigobj %(AdditionalOptions) + + + true + true + true + %(AdditionalDependencies) + + + + + Level3 + MaxSpeed + true + true + true + /bigobj %(AdditionalOptions) + + + true + true + true + + + + + + + + \ No newline at end of file