This class is a type-erased pointer to a function. It has value semantics.
Global Classes
class qi::AnyFunction
Functions (class qi::AnyFunction)
It is possible to create a qi::AnyFunction
from any functor (including
boost::function
). By using fromDynamicFunction, you can provide a
“variadic” function that will receive a vector of references to its arguments.
qi::AnyFunction freeFunc = qi::AnyFunction::from(someFunc);
qi::AnyFunction memberFunc = qi::AnyFunction::from(Class::func, myObj);
// if you use boost::bind or qi::bind, you must explicitly cast to the right
// signature
qi::AnyFunction memberFunc = qi::AnyFunction::from(
boost::function<int(int value1, const std::string& value2)>(
boost::bind(someFunc, _1, "argument")));
You can then call the function with a vector of arguments or by giving the arguments as in a normal function call.
Warning
The caller is responsible for destroying its qi::AnyReference
to the
returned value when using type-erased calls. You can store the returned
reference in a qi::AnyValue
to benefit from RAII destruction.
// typed call
int value = func.call<int>(42);
// using operator()
qi::AnyValue ret(func(42), false, true);
std::cout << ret.toInt() << std::endl;
// type-erased call
qi::AnyReferenceVector args;
args.push_back(qi::AnyReference::from(42));
ret.reset(func.call(args), false, true);
AnyFunction
()~AnyFunction
()AnyFunction
(const AnyFunction& b)AnyFunction
(FunctionTypeInterface* type, void* value)operator=
(const AnyFunction& b)call
(const AnyReferenceVector& args)call
(AnyReference arg1, const AnyReferenceVector& args)operator()
(const AnyReferenceVector& args)call
(qi::AutoAnyReference p1)operator()
(qi::AutoAnyReference p1)dropFirstArgument
() constreplaceFirstArgument
(void* value) constprependArgument
(void* value) constargumentsType
() constresultType
() constparametersSignature
(bool dropFirst) constreturnSignature
() constswap
(AnyFunction& b)operator bool
() constfunctionType
() constfrom
(T&& f)from
(F&& func)from
(F func, C instance)fromDynamicFunction
(DynamicFunction f)Represents a generic callable function. This class has value semantic.
qi::AnyFunction::
from
(F&& func)¶Brief:
Returns: | a AnyFunction binding instance to member function func |
---|
qi::AnyFunction::
from
(F func, C instance)¶qi::AnyFunction::
fromDynamicFunction
(DynamicFunction f)¶Brief:
Returns: | a AnyFunction that takes arguments as a list of unconverted AnyReference. |
---|
qi::AnyFunction::
AnyFunction
()¶qi::AnyFunction::
~AnyFunction
()¶qi::AnyFunction::
AnyFunction
(const AnyFunction& b)¶qi::AnyFunction::
AnyFunction
(FunctionTypeInterface* type, void* value)¶qi::AnyFunction::
operator=
(const AnyFunction& b)¶qi::AnyFunction::
call
(const AnyReferenceVector& args)¶Call the function, reference must be destroy()ed.
qi::AnyFunction::
call
(AnyReference arg1, const AnyReferenceVector& args)¶Call the function, reference must be destroy()ed.
qi::AnyFunction::
operator
(const AnyReferenceVector& args)¶Call the function, reference must be destroy()ed.
qi::AnyFunction::
call
(qi::AutoAnyReference p1 = qi::AutoAnyReference()¶Call the function.
qi::AnyFunction::
operator
(qi::AutoAnyReference p1 = qi::AutoAnyReference()¶Call the function, reference must be destroy()ed.
qi::AnyFunction::
dropFirstArgument
() const
¶Change signature, drop the first argument passed to call.
qi::AnyFunction::
replaceFirstArgument
(void* value) const
¶Replace first argument by value which must be storage for correct type.
qi::AnyFunction::
prependArgument
(void* value) const
¶Prepend extra argument value to argument list.
qi::AnyFunction::
argumentsType
() const
¶Return expected argument types, taking transform into account.
qi::AnyFunction::
resultType
() const
¶qi::AnyFunction::
parametersSignature
(bool dropFirst = false) const
¶qi::AnyFunction::
returnSignature
() const
¶qi::AnyFunction::
swap
(AnyFunction& b)¶qi::AnyFunction::
operator
bool() const
¶qi::AnyFunction::
functionType
() const
¶qi::AnyFunction::
from
(T&& f)¶