samedi 8 juin 2019

Is there a way to capture the parameter names of a method's prototype inside said method or function?

I would like to create macros that define a class with methods at compile time. These methods are proxy methods to a class that is running in another process. The macros define the methods and method prototypes of the corresponding methods as they are in the remote process.

The contents of the method bodies (generated by the macros) act as wrappers for template classes and methods that call the framework level operations needed to serialize the parameters and send the resulting data to the remote process for execution.

If I can capture the parameter variables using the compiler or preprocessor and pass them along to the underlying framework methods, it will make this easier to use for those who use it.

I have done a fair amount of research into ways that parameters can be encapsulated. Tuples and parameter packs have been very useful and I use them extensively on the server side of this framework, but it seems I am now trying to use these concepts somewhat in reverse.

e.g. Instead of making existing classes and methods (and their implementations) available so I can call them from the outside of the process, I need to generate methods that become wrappers to existing methods at compile time.

For example, I would like to generate something like this (and this is an simplification).

class MyClass
{
    MyClass() { Create<MyClass>() }
    MyClass(int i) { Create<MyClass>( i ) }

    int MyMethod( int j ) { return Invoke< int (MyClass::*)( int j) >( j ); }
    int MyMethod( int j, float f ) { return Invoke <int (MyClass::*)( int j, float f)( j, f ); }
};

I have been able to take care of the method/function pointer, deduction of parameter types and the like, but the on aspect that I believe may not be possible is automatically grabbing the data from the method call (variable names) and placing them as parameters to the method/function that the method wraps.

I thought about variadic template arguments, however, then I can't be precise with overloaded methods (in terms of defining valid arguments for said method).

My first thought that this is not possible, but I am still relatively new to C++17 (jumped from C++ 2003), so perhaps there is something that would allow capturing the actual parameter variables in side a function generically?

Thank you Kevin





Aucun commentaire:

Enregistrer un commentaire