I'm trying to reduce boilerplate class definitions, while also making it easy for me to change them in the future without having to go back and updating all of them manually
I'm wondering if I just need to make a script to generate these classes or if I can actually accomplish it all with variadic macros
I'd like to do this without Boost if possible, but if needed I can pull in and learn Boost
The goal is to be able to create an editor for all Entity Stats, which are grouped into "pods" (bunches of stats that go together, like HealthStats, AmmoStats, StorageStats, etc)
This is what I'd like to create about a dozen of:
class _EntityStorageInfo : public EntityStatPod
{
public:
_EntityStorageInfo() :EntityStatPod("_EntityStorageInfo"),
Ammo("Ammo"),
Water("Water"),
Oil("Oil"),
Nanites("Nanites")
{};
void draw()
{
drawStats(Ammo, Water, Nanites, Oil);
}
EntityStat<int> Ammo;
EntityStat<double> Water;
EntityStat<double> Nanites;
EntityStat<double> Oil;
private:
friend cereal::access;
template<class Archive>
void serialize(Archive& archive, std::uint32_t const version)
{
archive(cereal::base_class<EntityStatPod>(this), health, globalID, three, four);
}
};
This is as far as I've gotten myself, but I feel like there's one last step I'm missing that could let me skip having to supply the words "ammo,water,nanites,oil" multiple times
#define ENTITYSTATPODCLASS_BEGIN(name) \
class name : public EntityStatPod \
{ \
public: name():EntityStatPod("name"),
#define ENTITYSTATPODCLASS_MIDDLE(...) \
{}; \
void draw() { drawStats( __VA_ARGS__);}
#define ENTITYSTATPODCLASS_END(...) \
private: \
friend cereal::access; \
template<class Archive> \
void serialize(Archive& archive, std::uint32_t const version) \
{ \
archive(cereal::base_class<EntityStatPod>(this), __VA_ARGS__);\
} \
\
};
\
and this is how it looks using the macros:
ENTITYSTATPODCLASS_BEGIN(_EntityStorageInfo)
Ammo("Ammo"),
Water("Water"),
Nanites("Nanites"),
Oil("Oil")
ENTITYSTATPODCLASS_MIDDLE(Ammo,Water,Nanites,Oil)
EntityStat<int> Ammo;
EntityStat<double> Water;
EntityStat<double> Nanites;
EntityStat<double> Oil;
ENTITYSTATPODCLASS_END(Ammo, Water, Nanites, Oil)
I'd appreciate any ideas on how I could reduce the boilerplate even further, or if it's even possible without just writing a "class generation" script in another language
Thanks!