[gameprogrammer] Any C++ macro champions out there?

  • From: Alan Wolfe <alan.wolfe@xxxxxxxxx>
  • To: gameprogrammer@xxxxxxxxxxxxx
  • Date: Wed, 2 Jan 2013 22:29:51 -0800

Any C++ macro champions out there? I'm Trying to figure out how to do
something and hoping i don't have to fall back on code generation or manual
maintenance :P

I have a macro list defined like this:

#define TRIGGEREVENTLIST \
\
TRIGGEREVENT_BEGIN(PokeEvent, Base) \
TRIGGEREVENT_ITEM(int, PokeCount, true, 0) \
TRIGGEREVENT_ITEM(bool, PokeHard, false, false) \
TRIGGEREVENT_END() \
\
TRIGGEREVENT_BEGIN(AnotherEvent, Base) \
TRIGGEREVENT_ITEM(float, Something, true, 0.5f) \
TRIGGEREVENT_END() \
\
TRIGGEREVENT_BEGIN(UberPokeEvent, Base) \
TRIGGEREVENT_ITEM(float, UberPokeMultiplier, true, 2.0f) \
TRIGGEREVENT_END()

And I want to create a class per trigger event that contains each item as a
member and also a const & getter and setter for each item within it. I have
that part working, but I'm stuck on the next part...

What i need to do next is make a constructor or some kind of construction
mechanism which contains all the items as parameters to the function, and
then sets the members to the passed in values.

The problem I'm hitting is that to do that, I essentially need to loop
through an events item list twice (once for params, once for setting the
members to the param values) before moving onto the next event, but not
sure how to do that (or even if there is a way).

Unfortunately, a potential added nail to the coffin is that the constructor
(or construction mechanism) also needs to include as parameters all of the
inherited items.

I really want compile time assurance that when these are constructed, that
they have all the necessary data supplied to them (so when you add or
remove items, you get compile time errors about the places in the code you
need to update).

Thanks for any insight anyone can provide!

PS if anyone is interested, I can share the code i have right now to
generate classes with private members and getters and setters, as well as a
COMPILE TIME calculation of the size of the largest class (so you could use
it as a parameter to an object pool allocator or something).

Other related posts: