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
Currently I'm using some defines that create a new class per function,
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
in advance. Take this example:
switch( property->GetParamsType() )
((CFunctionMethod_1Int*)property)->CallMethod( object, i );
((CFunctionMethod_2Int*)property)->CallMethod( object, i, j );
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
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
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
types of parameters that a function will require.
Can anyone point me in a better direction?
sweng-gamedev mailing list
sweng-gamedev <at> lists.midnightryder.com