J
Joel
Hi all,
Forgive me if I've expressed the subject line ill.
What I'm trying to do is to call a c++ function given the following:
a. A function name. This would be used to fetch a list of function
descriptors for the overloaded functions of that name. A function
descriptor would contain the address of the function to be called, and
a description of the parameters that it must take.
b. A list of parameters. This would be compared to the parameters in
each of the function descriptors to check which function must be
called, and then the desciptor would be given the parameters, and
requested to invoke that function
To illustrate:
...............................................
void SomeFunction (int a, int b)
{
// This is the function that must be invoked.
}
void GenericFunction (string FunctionName, ParameterCollection
Paremeters)
{
FunctionDescriptorList Descriptors;
Descriptors.LoadFunctionDescriptors (FunctionName);
// The Parameters object contains a list of parameters to be
passed.
// I would validate the parameters in the collection against the
// parameters required as specified by the DescriptorObject, and
use the
// DescriptorObject (which describes overloaded functions named
// SomeFunction) to call the matching SomeFunction, passing to it
// the two required integer parameters (as above).
}
...............................................
I am not sure how to achieve any of the invoking functionality I have
descibed in the comments above.
One approach I have tried is:
typedef void (* EllipsisFunction) (...);
void SomeFunction (int a, int b)
{
}
int main (void)
{
EllipsisFunction fn = (EllipsisFunction) SomeFunction;
fn (1, 2);
.....etc.
}
I could use code of this nature to effect something of what I am
trying to achieve (minus the validation), except for the fact that
again I must know the number of parameters that I call when I actually
type the code.
Another approach that I can use is that instead of SomeFunction taking
two integers, it could simply take a parameter collection object as
it's sole parameter. The second GenericFunction that I described above
would then have no problems in validating a ParameterCollection object
against the required parameters as described in a MethodDescriptor
object, and then in passing the ParameterCollection itself to
SomeFunction. This implies, however, that the signature of
SomeFunction would now have to take a ParameterCollection. Ideally, I
would prefer that if it means to take two integers, then the signature
should reflect that. I am aware tho that it isn't always an ideal
world
But what I want to do is somehow to push the required parameters
(specified in a ParametersCollection object) onto the stack, before I
actually make the function call. Again, forgive me for using
non-technical words like "somehow". I have reached the extent of my
C++ knowledge in this particular area.
And that's where I am at present. It's a bit of a lengthy post but I
wanted to let you know how I've been thinking about this.
The problem is that I do not see right now a way to completely fulfill
the ideal that I have specified at the beginning of this post. Is
there a way that it could be accomplished?
With best regards,
cirquitz
Forgive me if I've expressed the subject line ill.
What I'm trying to do is to call a c++ function given the following:
a. A function name. This would be used to fetch a list of function
descriptors for the overloaded functions of that name. A function
descriptor would contain the address of the function to be called, and
a description of the parameters that it must take.
b. A list of parameters. This would be compared to the parameters in
each of the function descriptors to check which function must be
called, and then the desciptor would be given the parameters, and
requested to invoke that function
To illustrate:
...............................................
void SomeFunction (int a, int b)
{
// This is the function that must be invoked.
}
void GenericFunction (string FunctionName, ParameterCollection
Paremeters)
{
FunctionDescriptorList Descriptors;
Descriptors.LoadFunctionDescriptors (FunctionName);
// The Parameters object contains a list of parameters to be
passed.
// I would validate the parameters in the collection against the
// parameters required as specified by the DescriptorObject, and
use the
// DescriptorObject (which describes overloaded functions named
// SomeFunction) to call the matching SomeFunction, passing to it
// the two required integer parameters (as above).
}
...............................................
I am not sure how to achieve any of the invoking functionality I have
descibed in the comments above.
One approach I have tried is:
typedef void (* EllipsisFunction) (...);
void SomeFunction (int a, int b)
{
}
int main (void)
{
EllipsisFunction fn = (EllipsisFunction) SomeFunction;
fn (1, 2);
.....etc.
}
I could use code of this nature to effect something of what I am
trying to achieve (minus the validation), except for the fact that
again I must know the number of parameters that I call when I actually
type the code.
Another approach that I can use is that instead of SomeFunction taking
two integers, it could simply take a parameter collection object as
it's sole parameter. The second GenericFunction that I described above
would then have no problems in validating a ParameterCollection object
against the required parameters as described in a MethodDescriptor
object, and then in passing the ParameterCollection itself to
SomeFunction. This implies, however, that the signature of
SomeFunction would now have to take a ParameterCollection. Ideally, I
would prefer that if it means to take two integers, then the signature
should reflect that. I am aware tho that it isn't always an ideal
world
But what I want to do is somehow to push the required parameters
(specified in a ParametersCollection object) onto the stack, before I
actually make the function call. Again, forgive me for using
non-technical words like "somehow". I have reached the extent of my
C++ knowledge in this particular area.
And that's where I am at present. It's a bit of a lengthy post but I
wanted to let you know how I've been thinking about this.
The problem is that I do not see right now a way to completely fulfill
the ideal that I have specified at the beginning of this post. Is
there a way that it could be accomplished?
With best regards,
cirquitz