Boost comes with an example file in
boost_1_41_0\libs\function_types\example
called interpreter.hpp and interpreter_example.hpp
I am trying to create a situation where I have a bunch of functions of different arguments, return types, etc all register and be recorded to a single location. Then have the ability to pull out a function and execute it with some params.
After reading a few questions here, and from a few other sources I think the design implemented in this example file is as good as I will be able to get. It takes a function of any type and allows you to call it using a string argument list, which is parsed into the right data types.
Basically its a console command interpreter, and thats probably what its meant to illustrate.
I have been studying the code and poking around trying to get the same implementation to accept class member functions, but have been unsuccessful so far.
I was wondering if someone could suggest the modifications needed, or maybe worked on something similar and have some same code.
In the example you’ll see
interpreter.register_function("echo", & echo);
interpreter.register_function("add", & add);
interpreter.register_function("repeat", & repeat);
I want to do something like
test x;
interpreter.register_function("classFunc", boost::bind( &test::classFunc, &x ) );
But this breaks the any number of arguments feature.
So I am thinking some kind of auto generating boost::bind( &test::classFunc, &x, _1, _2, _3 … ) would be the ticket, I just am unsure of the best way to implement it.
Thanks
I’ve been working on this issue and i’ve somewhat succeeded to make the boost interpreter accept the member function such as:
The enable_if statement is used to prevent the use of the wrong method at the compile time. Now, what you need to understand :
So, what needs to be done is simply add one step to the “parsing” apply, which would be to add the concerned object to the apply loop! Here it goes:
in interpreter::invoker
This way, it will simply skip the first argument type and parse everything correctly.
The method can be called this way:
invoker.register_function("SomeMethod",&TheClass::TheMethod,&my_object);