I am trying to create a game save system using boost serialization, and want to create an easy way for clients to select member variables for serialization.
Basically I want the user to input something like this:
class apple : public Actor
{
public:
int a;
bool isTasty;
float unimportantData;
SET_SAVED_MEMBERS(a, isTasty);
};
And I would like this to be expanded into something like
class apple : public Actor
{
public:
// ...
template<typename Archive>
void serialize(Archive& arch, const unsigned int version)
{
arch & BOOST_SERIALIZATION_NVP(a);
arch & BOOST_SERIALIZATION_NVP(isTasty);
}
Of course, it is fine if it requires a few more macros than this.
I'm fine with template meta programming (preferably) or preprocessor meta programming.
C++11 is fine, too.
Thanks for the help!
Previously I had a boost-focused answer that I wasn't able to test. Here's something more comprehensible using a combination of template meta-programming and macros:
Currently I have it just printing so I could test it (but indicate above the line you would need to change). Here is a test using your apple example:
Note that I'm sending in a string instead of an archive object -- that works fine with the fact that it's currently using print.