Class versioning working

This commit is contained in:
Randolph Voorhies
2013-06-12 11:18:35 -07:00
parent c8c6846905
commit be5d1581d4
3 changed files with 34 additions and 18 deletions

View File

@@ -22,7 +22,8 @@ namespace cereal
BinaryOutputArchive &>::type
operator & (T const & t)
{
std::cout << "Member serialize" << std::endl;
std::cout << "Member serialize. Version " << cereal_class_version(t) << std::endl;
//t.serialize(*this, traits::version<T>::value)
return *this;
}
@@ -32,7 +33,8 @@ namespace cereal
BinaryOutputArchive &>::type
operator & (T const & t)
{
std::cout << "Non member serialize" << std::endl;
std::cout << "Non member serialize. Version " << cereal_class_version(t) << std::endl;
//serialize(*this, t, traits::version<T>::value)
return *this;
}
@@ -42,7 +44,8 @@ namespace cereal
BinaryOutputArchive &>::type
operator & (T const & t)
{
std::cout << "Member split" << std::endl;
std::cout << "Member split. Version " << cereal_class_version(t) << std::endl;
//t.save(*this, traits::version<T>::value);
return *this;
}
@@ -52,7 +55,7 @@ namespace cereal
BinaryOutputArchive &>::type
operator & (T const & t)
{
std::cout << "Non member split" << std::endl;
std::cout << "Non member split. Version " << cereal_class_version(t) << std::endl;
//save(*this, t, traits::version<T>::value);
return *this;
}
@@ -73,4 +76,7 @@ namespace cereal
}
};
#define CEREAL_CLASS_VERSION(classname, version) \
unsigned int constexpr cereal_class_version(classname const &) { return version; };
}

View File

@@ -13,6 +13,7 @@ struct Test1
ar & a & b;
}
};
CEREAL_CLASS_VERSION(Test1, 1);
// ###################################
struct Test2
@@ -32,6 +33,7 @@ struct Test2
ar & a & b;
}
};
CEREAL_CLASS_VERSION(Test2, 2);
// ###################################
struct Test3
@@ -46,25 +48,29 @@ void serialize(Archive & ar, Test3 & t, unsigned int version)
//ar & t.a;
//ar & t.b;
}
CEREAL_CLASS_VERSION(Test3, 3);
// ###################################
struct Test4
namespace test4
{
int a;
std::string b;
};
// ###################################
struct Test4
{
int a;
std::string b;
};
template<class Archive>
void save(Archive & ar, Test4 & t, unsigned int version)
{
ar & t.a & t.b;
}
void save(Archive & ar, Test4 & t, unsigned int version)
{
ar & t.a & t.b;
}
template<class Archive>
void load(Archive & ar, Test4 & t, unsigned int version)
{
ar & t.a & t.b;
void load(Archive & ar, Test4 & t, unsigned int version)
{
ar & t.a & t.b;
}
CEREAL_CLASS_VERSION(Test4, 4);
}
// ######################################################################
@@ -75,7 +81,7 @@ int main()
Test1 t1;
Test2 t2;
Test3 t3;
Test4 t4;
test4::Test4 t4;
archive & t1;
archive & t2;

View File

@@ -1,9 +1,13 @@
namespace cereal
{
template<typename T> unsigned int constexpr cereal_class_version(T const &) { return 0; };
namespace traits
{
template<typename> struct Void { typedef void type; };
// ######################################################################
// Member Serialize
template<typename T, class A, typename Sfinae = void>