[gameprogrammer] Fun with the preprocessor

I'm doing something with synchronized memory in classes.  Here is the gist
of what I would like to do.

In the header file, inside the class:

class MyClass
{
vector position;
int orientation;

START_SYNCHRONIZATION(BaseClass)
SYNCHRONIZE(vector, position);
SYNCHRONIZE(int, orientation);
...
END_SYNCHRONIZATION
}

I want the defines (all in caps) to expand to two functions and a copy of
each variable with a different name.

SerializeClass(BitStream *bitStream)
{
BaseClass::SerializeClass(bitStream)
Serialize(position, bitStream);
Serialize(orientation, bitStream);
}

DeserializeClass(BitStream *bitStream)
{
BaseClass::DeserializeClass(bitStream)
Deserialize(position,bitStream);
Deserialize(orientation,bitStream);
}

vector variableCopy_position;
int variableCopy_orientation;


Any way to do this with what I have here?  There is one way, which is to
pass all paramters to the #define to begin with.  I.E.

SUPER_SYNCHRONIZE(base_class, type1, variablename1, type2, variablename2)

Problem with that is I want to support an unlimited number of paramters.  I
guess I can write this define out until type99, variablename99, and hope
nobody does more than 99 parameters.  But that is sort of ugly and stupid.
Any better way?



---------------------
To unsubscribe go to http://gameprogrammer.com/mailinglist.html


Other related posts: