reflection and functions
igrok <igrok <at> orangutan.eclipse.co.uk>
2006-01-05 01:48:02 GMT
I've been experimenting with setting up a system of reflection in C++,
but have found that doing reflection on class functions is messy to
implement.
Currently I'm using some defines that create a new class per function,
and
after grabbing the relevant property class, you call:
CFunctionMethod* property = object->FindFunction( "DoSomething" );
property->CallMethod( object, params );
One thing that is very messy about this is that the params need to be
known
in advance. Take this example:
switch( property->GetParamsType() )
{
case PARAMS_1Int:
((CFunctionMethod_1Int*)property)->CallMethod( object, i );
break;
case PARAMS_2Int:
((CFunctionMethod_2Int*)property)->CallMethod( object, i, j );
break;
}
Obviously this will get difficult to maintain as the permutations of
ParamsType grows, and I feel sure there must be a better way.
I've been reading the article in Games Programming Gems 5, called 'Using
Templates for Reflection in C++' which implements a nice neat way of
doing
reflectance of data members.
This is relatively simple as there is a limited number of data types
(int,float,pointer,etc) and the Get() and Set() functions need none or
one
parameter only.
Templates are used in this system, but not defines.
The article claims that it is easy to expand their system to support
exposure of class functions as well, but obviously I'm a bit stupid and
can't see how this can be done. The main obsticle is the varying number
and
types of parameters that a function will require.
Can anyone point me in a better direction?
Thanks
_______________________________________________
sweng-gamedev mailing list
sweng-gamedev <at> lists.midnightryder.com
http://lists.midnightryder.com/listinfo.cgi/sweng-gamedev-midnightryder.com