Normally that would work great Stephane, but if you look at my macro list, it's a list of lists. I agree, if it was a single list i could do multiple passes and do: // 1 - define class header and member vars and getters / setters // 2 - define constructor parameters // 3 - define constructor body and then end class declaration But the problem is that i have multiple classes represented in my list, which means i can only do a single pass since i can't do the header for each class, then the constructor header for each class, and then end each class. In the below, 3 classes need to be generated from the single macro list: #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, PokeEvent) \ TRIGGEREVENT_ITEM(float, UberPokeMultiplier, true, 2.0f) \ TRIGGEREVENT_END() On Thu, Jan 3, 2013 at 5:26 PM, Stéphane Marchesin < stephane.marchesin@xxxxxxxxx> wrote: > On Wed, Jan 2, 2013 at 10:29 PM, Alan Wolfe <alan.wolfe@xxxxxxxxx> wrote: > > 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). > > You put all your things in one header, let's call that header > listofthings.h: > > DO_SOMETHING(0, "A") > DO_SOMETHING(2, "B") > ... > > then you can include that header multiple times, redefining > DO_SOMETHING differently every time: > > #define DO_SOMETHING(A,B) printf("%d %s\n", A, B); > #include "listofthings.h" > #undef DO_SOMETHING > > #define DO_SOMETHING(A,B) table[A] = B; > #include "listofthings.h" > #undef DO_SOMETHING > > Stéphane > > > > > 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). > > --------------------- > To unsubscribe go to http://gameprogrammer.com/mailinglist.html > > >