Making some changes on vs2013, replacing some typedefs with using statements now that those are cool

This commit is contained in:
Shane Grant
2013-12-21 21:22:46 -08:00
parent f9b3eb5bd6
commit 7ef5a9311b
6 changed files with 407 additions and 309 deletions

View File

@@ -126,24 +126,25 @@ namespace cereal
static auto member_load(Archive & ar, T & t) -> decltype(t.load(ar)) static auto member_load(Archive & ar, T & t) -> decltype(t.load(ar))
{ t.load(ar); } { t.load(ar); }
/*! @name Boost Transition Layer */ // versioned member serialize
//! @{
template<class Archive, class T> inline template<class Archive, class T> inline
static auto member_serialize(Archive & ar, T & t, const std::uint32_t version ) -> decltype(t.serialize(ar, version)) static auto member_serialize(Archive & ar, T & t, const std::uint32_t version ) -> decltype(t.serialize(ar, version))
{ t.serialize(ar, version); } { t.serialize(ar, version); }
// versioned member save
template<class Archive, class T> inline template<class Archive, class T> inline
static auto member_save(Archive & ar, T const & t, const std::uint32_t version ) -> decltype(t.save(ar, version)) static auto member_save(Archive & ar, T const & t, const std::uint32_t version ) -> decltype(t.save(ar, version))
{ t.save(ar, version); } { t.save(ar, version); }
// versioned member save (non const)
template<class Archive, class T> inline template<class Archive, class T> inline
static auto member_save_non_const(Archive & ar, T & t, const std::uint32_t version ) -> decltype(t.save(ar, version)) static auto member_save_non_const(Archive & ar, T & t, const std::uint32_t version ) -> decltype(t.save(ar, version))
{ t.save(ar, version); } { t.save(ar, version); }
// versioned member load
template<class Archive, class T> inline template<class Archive, class T> inline
static auto member_load(Archive & ar, T & t, const std::uint32_t version ) -> decltype(t.load(ar, version)) static auto member_load(Archive & ar, T & t, const std::uint32_t version ) -> decltype(t.load(ar, version))
{ t.load(ar, version); } { t.load(ar, version); }
//! @}
template <class T> template <class T>
static void load_and_allocate(...) static void load_and_allocate(...)

View File

@@ -43,7 +43,7 @@ namespace cereal
/*! To ensure compatability between 32, 64, etc bit machines, we need to use /*! 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 * a fixed size type instead of size_t, which may vary from machine to
* machine. */ * machine. */
typedef uint64_t size_type; using size_type = uint64_t;
// forward decls // forward decls
class BinaryOutputArchive; class BinaryOutputArchive;
@@ -126,12 +126,12 @@ namespace cereal
// otherwise, we store a reference. If we were passed an array, don't // 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 // decay the type - keep it as an array, and then proceed as normal
// with the RValue business // with the RValue business
typedef typename std::conditional<std::is_array<typename std::remove_reference<T>::type>::value, using DT = typename std::conditional<std::is_array<typename std::remove_reference<T>::type>::value,
typename std::remove_cv<T>::type, typename std::remove_cv<T>::type,
typename std::decay<T>::type>::type DT; typename std::decay<T>::type>::type;
typedef typename std::conditional<std::is_rvalue_reference<T>::value, using Type = typename std::conditional<std::is_rvalue_reference<T>::value,
DT, DT,
typename std::add_lvalue_reference<DT>::type>::type Type; typename std::add_lvalue_reference<DT>::type>::type;
// prevent nested nvps // prevent nested nvps
static_assert( !std::is_base_of<detail::NameValuePairCore, T>::value, static_assert( !std::is_base_of<detail::NameValuePairCore, T>::value,
"Cannot pair a name to a NameValuePair" ); "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 //! Internally store the pointer as a void *, keeping const if created with
//! a const pointer //! a const pointer
typedef typename std::conditional<std::is_const<typename std::remove_pointer<T>::type>::value, using PT = typename std::conditional<std::is_const<typename std::remove_pointer<T>::type>::value,
const void *, const void *,
void *>::type PT; void *>::type;
BinaryData( T && d, uint64_t s ) : data(d), size(s) {} BinaryData( T && d, uint64_t s ) : data(d), size(s) {}
@@ -236,10 +236,10 @@ namespace cereal
private: private:
// If we get passed an RValue, we'll just make a local copy if it here // If we get passed an RValue, we'll just make a local copy if it here
// otherwise, we store a reference // otherwise, we store a reference
typedef typename std::decay<T>::type DT; using DT = typename std::decay<T>::type;
typedef typename std::conditional<std::is_rvalue_reference<T>::value, using Type = typename std::conditional<std::is_rvalue_reference<T>::value,
DT, DT,
typename std::add_lvalue_reference<DT>::type>::type Type; typename std::add_lvalue_reference<DT>::type>::type;
public: public:
SizeTag( T && sz ) : size(const_cast<Type>(sz)) {} SizeTag( T && sz ) : size(const_cast<Type>(sz)) {}
@@ -271,17 +271,17 @@ namespace cereal
template <class Key, class Value> template <class Key, class Value>
struct MapItem struct MapItem
{ {
typedef typename std::decay<Key>::type DecayKey; using DecayKey = typename std::decay<Key>::type;
typedef typename std::conditional< using KeyType = typename std::conditional<
std::is_rvalue_reference<Key>::value, std::is_rvalue_reference<Key>::value,
DecayKey, DecayKey,
typename std::add_lvalue_reference<DecayKey>::type>::type KeyType; typename std::add_lvalue_reference<DecayKey>::type>::type;
typedef typename std::decay<Value>::type DecayValue; using DecayValue = typename std::decay<Value>::type;
typedef typename std::conditional< using ValueType = typename std::conditional<
std::is_rvalue_reference<Value>::value, std::is_rvalue_reference<Value>::value,
DecayValue, DecayValue,
typename std::add_lvalue_reference<DecayValue>::type>::type ValueType; typename std::add_lvalue_reference<DecayValue>::type>::type;
//! Construct a MapItem from a key and a value //! Construct a MapItem from a key and a value
/*! @internal */ /*! @internal */

View File

@@ -3134,3 +3134,97 @@ BOOST_AUTO_TEST_CASE( json_unordered_loads )
{ {
test_unordered_loads<cereal::JSONInputArchive, cereal::JSONOutputArchive>(); test_unordered_loads<cereal::JSONInputArchive, cereal::JSONOutputArchive>();
} }
// ######################################################################
struct VersionStructMS
{
bool x;
std::uint32_t v;
template <class Archive>
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 <class Archive>
void save( Archive & ar, std::uint32_t const version ) const
{
ar( x );
std::cerr << "VersionStructMSP Save " << version << std::endl;
}
template <class Archive>
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 <class IArchive, class OArchive>
void test_versioning()
{
std::random_device rd;
std::mt19937 gen(rd());
for(size_t i=0; i<100; ++i)
{
VersionStructMS o_MS = {random_value<uint8_t>(gen) % 2 ? true : false, -1};
VersionStructMSP o_MSP = {random_value<uint8_t>(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<cereal::BinaryInputArchive, cereal::BinaryOutputArchive>();
}
BOOST_AUTO_TEST_CASE( portable_binary_versioning )
{
test_versioning<cereal::PortableBinaryInputArchive, cereal::PortableBinaryOutputArchive>();
}
BOOST_AUTO_TEST_CASE( xml_versioning )
{
test_versioning<cereal::XMLInputArchive, cereal::XMLOutputArchive>();
}
BOOST_AUTO_TEST_CASE( json_versioning )
{
test_versioning<cereal::JSONInputArchive, cereal::JSONOutputArchive>();
}

View File

@@ -66,20 +66,20 @@
</ImportGroup> </ImportGroup>
<PropertyGroup Label="UserMacros" /> <PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<IncludePath>$(SolutionDir)\..\include;C:\Boost\include\boost-1_55;$(IncludePath)</IncludePath> <IncludePath>$(SolutionDir)\..\include;E:\Boost\include\boost-1_55;$(IncludePath)</IncludePath>
<LibraryPath>C:\Boost\lib;$(LibraryPath)</LibraryPath> <LibraryPath>E:\Boost\lib;$(LibraryPath)</LibraryPath>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<IncludePath>$(SolutionDir)\..\include;C:\Boost\include\boost-1_55;$(IncludePath)</IncludePath> <IncludePath>$(SolutionDir)\..\include;E:\Boost\include\boost-1_55;$(IncludePath)</IncludePath>
<LibraryPath>C:\Boost\lib\x64;$(LibraryPath)</LibraryPath> <LibraryPath>E:\Boost\lib\x64;$(LibraryPath)</LibraryPath>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<IncludePath>$(SolutionDir)\..\include;C:\Boost\include\boost-1_55;$(IncludePath)</IncludePath> <IncludePath>$(SolutionDir)\..\include;E:\Boost\include\boost-1_55;$(IncludePath)</IncludePath>
<LibraryPath>C:\Boost\lib;$(LibraryPath)</LibraryPath> <LibraryPath>E:\Boost\lib;$(LibraryPath)</LibraryPath>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<IncludePath>$(SolutionDir)\..\include;C:\Boost\include\boost-1_55;$(IncludePath)</IncludePath> <IncludePath>$(SolutionDir)\..\include;E:\Boost\include\boost-1_55;$(IncludePath)</IncludePath>
<LibraryPath>C:\Boost\lib\x64;$(LibraryPath)</LibraryPath> <LibraryPath>E:\Boost\lib\x64;$(LibraryPath)</LibraryPath>
</PropertyGroup> </PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile> <ClCompile>

View File

@@ -66,18 +66,18 @@
</ImportGroup> </ImportGroup>
<PropertyGroup Label="UserMacros" /> <PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<IncludePath>$(SolutionDir)\..\include;C:\Boost\include\boost-1_55;$(IncludePath)</IncludePath> <IncludePath>$(SolutionDir)\..\include;E:\Boost\include\boost-1_55;$(IncludePath)</IncludePath>
<LibraryPath>C:\Boost\lib;$(LibraryPath)</LibraryPath> <LibraryPath>E:\Boost\lib;$(LibraryPath)</LibraryPath>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<IncludePath>$(SolutionDir)\..\include;C:\Boost\include\boost-1_55;$(IncludePath)</IncludePath> <IncludePath>$(SolutionDir)\..\include;E:\Boost\include\boost-1_55;$(IncludePath)</IncludePath>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<IncludePath>$(SolutionDir)\..\include;C:\Boost\include\boost-1_55;$(IncludePath)</IncludePath> <IncludePath>$(SolutionDir)\..\include;E:\Boost\include\boost-1_55;$(IncludePath)</IncludePath>
<LibraryPath>C:\Boost\lib;$(LibraryPath)</LibraryPath> <LibraryPath>E:\Boost\lib;$(LibraryPath)</LibraryPath>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<IncludePath>$(SolutionDir)\..\include;C:\Boost\include\boost-1_55;$(IncludePath)</IncludePath> <IncludePath>$(SolutionDir)\..\include;E:\Boost\include\boost-1_55;$(IncludePath)</IncludePath>
</PropertyGroup> </PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile> <ClCompile>

View File

@@ -66,20 +66,20 @@
</ImportGroup> </ImportGroup>
<PropertyGroup Label="UserMacros" /> <PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<IncludePath>$(SolutionDir)\..\include;C:\Boost\include\boost-1_55;$(IncludePath)</IncludePath> <IncludePath>$(SolutionDir)\..\include;E:\Boost\include\boost-1_55;$(IncludePath)</IncludePath>
<LibraryPath>C:\Boost\lib;$(LibraryPath)</LibraryPath> <LibraryPath>E:\Boost\lib;$(LibraryPath)</LibraryPath>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<IncludePath>$(SolutionDir)\..\include;C:\Boost\include\boost-1_55;$(IncludePath)</IncludePath> <IncludePath>$(SolutionDir)\..\include;E:\Boost\include\boost-1_55;$(IncludePath)</IncludePath>
<LibraryPath>C:\Boost\lib\x64;$(LibraryPath)</LibraryPath> <LibraryPath>E:\Boost\lib\x64;$(LibraryPath)</LibraryPath>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<IncludePath>$(SolutionDir)\..\include;C:\Boost\include\boost-1_55;$(IncludePath)</IncludePath> <IncludePath>$(SolutionDir)\..\include;E:\Boost\include\boost-1_55;$(IncludePath)</IncludePath>
<LibraryPath>C:\Boost\lib;$(LibraryPath)</LibraryPath> <LibraryPath>E:\Boost\lib;$(LibraryPath)</LibraryPath>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<IncludePath>$(SolutionDir)\..\include;C:\Boost\include\boost-1_55;$(IncludePath)</IncludePath> <IncludePath>$(SolutionDir)\..\include;E:\Boost\include\boost-1_55;$(IncludePath)</IncludePath>
<LibraryPath>C:\Boost\lib\x64;$(LibraryPath)</LibraryPath> <LibraryPath>E:\Boost\lib\x64;$(LibraryPath)</LibraryPath>
</PropertyGroup> </PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile> <ClCompile>
@@ -87,6 +87,7 @@
<Optimization>Disabled</Optimization> <Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck> <SDLCheck>true</SDLCheck>
<SuppressStartupBanner>true</SuppressStartupBanner> <SuppressStartupBanner>true</SuppressStartupBanner>
<AdditionalOptions>/bigobj %(AdditionalOptions)</AdditionalOptions>
</ClCompile> </ClCompile>
<Link> <Link>
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
@@ -113,6 +114,7 @@
<FunctionLevelLinking>true</FunctionLevelLinking> <FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions> <IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck> <SDLCheck>true</SDLCheck>
<AdditionalOptions>/bigobj %(AdditionalOptions)</AdditionalOptions>
</ClCompile> </ClCompile>
<Link> <Link>
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
@@ -128,6 +130,7 @@
<FunctionLevelLinking>true</FunctionLevelLinking> <FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions> <IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck> <SDLCheck>true</SDLCheck>
<AdditionalOptions>/bigobj %(AdditionalOptions)</AdditionalOptions>
</ClCompile> </ClCompile>
<Link> <Link>
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>