访问的boost ::函数参数 [英] Access boost::function arguments
问题描述
是否有可能访问包含在一个boost ::函数类型的参数?
Is it possible to access the arguments contained in a boost::function type?
我希望能够获取函数的地址被调用,并提供该功能的参数值。
I'd like to be able to retrieve the address of the function to be called, and the values of the arguments provided for that function.
推荐答案
提振::函数擦除实现类型,但如果你知道它,你可以施放它;因为升压::功能是按值(==!=)的信息显然是可比较的。
boost::function erases the implementation type, but if you know it, you can cast to it; since boost::function are comparable by value (== !=) the information is clearly available.
它看起来像(从功能N的function_base超类),你可以得到实施的对象与
It looks like (from the function_base superclass of functionN) you can get the implementation object with:
f.target<concrete_functor_type>()
这将返回NULL,如果你提供了错误的具体类型。
Which will return NULL if you provided the wrong concrete type.
此外,在function_base(可能超出上述目标的方法没有帮助):
Also in function_base (probably not helpful beyond the target method above):
public: // should be protected, but GCC 2.95.3 will fail to allow access
detail::function::vtable_base* vtable;
mutable detail::function::function_buffer functor;
虚函数表,您可以访问:
vtable gives you access to:
struct vtable_base
{
void (*manager)(const function_buffer& in_buffer,
function_buffer& out_buffer,
functor_manager_operation_type op);
};
这可以让你的函子的typeid的:
which can get you the typeid of the functor:
case get_functor_type_tag:
out_buffer.type.type = &typeid(F);
out_buffer.type.const_qualified = in_buffer.obj_ref.is_const_qualified;
out_buffer.type.volatile_qualified = in_buffer.obj_ref.is_volatile_qualified;
return;
}
function_buffer(仿)只可用于裁判到函数对象,约束(这是固定的)成员函数的师生比,和免费的功能,在这里你还没有绑定任何参数
function_buffer (functor) is only useful for refs to function objects, bound (this is fixed) member functions ptrs, and free functions, where you haven't bound any arguments
这篇关于访问的boost ::函数参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!