qi::AnyFunction¶
This class is a type-erased pointer to a function. It has value semantics.
Summary¶
class qi::AnyFunction
Functions (class qi::AnyFunction)
Global Classes
Detailed Description¶
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);
Reference¶
- typedef boost::function< AnyReference(const AnyReferenceVector &)> DynamicFunction¶
qi::AnyFunction Class Reference¶
Public Functions¶
-
()AnyFunction
-
()~AnyFunction
-
(const AnyFunction& b)AnyFunction
-
(FunctionTypeInterface* type, void* value)AnyFunction
-
AnyFunction&
(const AnyFunction& b)operator=
-
AnyReference
(const AnyReferenceVector& args)call
-
AnyReference
(AnyReference arg1, const AnyReferenceVector& args)call
-
AnyReference
(const AnyReferenceVector& args)operator()
- template<typename R>
-
R
(qi::AutoAnyReference p1)call
- template<typename R>
-
AnyReference
(qi::AutoAnyReference p1)operator()
-
const AnyFunction&
() constdropFirstArgument
-
const AnyFunction&
(void* value) constreplaceFirstArgument
-
const AnyFunction&
(void* value) constprependArgument
-
std::vector<TypeInterface*>
() constargumentsType
-
TypeInterface*
() constresultType
-
Signature
(bool dropFirst) constparametersSignature
-
Signature
() constreturnSignature
-
void
(AnyFunction& b)swap
-
() constoperator bool
-
FunctionTypeInterface*
() constfunctionType
- template<typename T>
-
AnyFunction
(T&& f)from
Public Static Functions¶
- template<typename F>
-
AnyFunction
(F&& func)from
- template<typename F, typename C>
-
AnyFunction
(F func, C instance)from
-
AnyFunction
(DynamicFunction f)fromDynamicFunction
Detailed Description¶
Represents a generic callable function. This class has value semantic.
Function Documentation¶
- template<typename F>
-
static AnyFunction
qi::AnyFunction::
from
(F&& func)¶
- template<typename F, typename C>
-
Brief:
Returns: a AnyFunction binding instance to member function func qi::AnyFunction::
from
(F func, C instance)¶
-
static AnyFunction
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)¶
-
AnyFunction&
qi::AnyFunction::
operator=
(const AnyFunction& b)¶
-
AnyReference
qi::AnyFunction::
call
(const AnyReferenceVector& args)¶ Brief:
Parameters: - args – A list of unnamed arguments, each wrapped in an AnyReference for allowing introspection.
Calls the function.
-
AnyReference
qi::AnyFunction::
call
(AnyReference arg1, const AnyReferenceVector& args)¶ Call the function, reference must be destroy()ed.
-
AnyReference
qi::AnyFunction::
operator
(const AnyReferenceVector& args)¶ Call the function, reference must be destroy()ed.
- template<typename R>
-
R
qi::AnyFunction::
call
(qi::AutoAnyReference p1 = qi::AutoAnyReference()¶ Call the function.
- template<typename R>
-
AnyReference
qi::AnyFunction::
operator
(qi::AutoAnyReference p1 = qi::AutoAnyReference()¶ Call the function, reference must be destroy()ed.
-
const AnyFunction&
qi::AnyFunction::
dropFirstArgument
()const
¶ Change signature, drop the first argument passed to call.
-
const AnyFunction&
qi::AnyFunction::
replaceFirstArgument
(void* value)const
¶ Replace first argument by value which must be storage for correct type.
-
const AnyFunction&
qi::AnyFunction::
prependArgument
(void* value)const
¶ Prepend extra argument value to argument list.
-
std::vector<TypeInterface*>
qi::AnyFunction::
argumentsType
()const
¶ Return expected argument types, taking transform into account.
-
TypeInterface*
qi::AnyFunction::
resultType
()const
¶
-
Signature
qi::AnyFunction::
returnSignature
()const
¶
-
FunctionTypeInterface*
qi::AnyFunction::
functionType
()const
¶
- template<typename T>
-
AnyFunction
qi::AnyFunction::
from
(T&& f)¶