MetaMethod provides method invocation mechanism for Kanzi classes. More...
#include <kanzi/core/metadata/metamethod.hpp>
Public Member Functions | |
optional< MethodArgument > | apply (MetaObject &instance, const MethodArguments &arguments) const |
Applies the arguments on the method of an instance of the class holding the member function. More... | |
int | getArgumentCount () const |
Gets the number of method arguments. More... | |
AbstractPropertyType | getArgumentType (size_t index) const |
Gets the argument type from a given index. More... | |
const char * | getName () const |
Gets the name of the method. More... | |
AbstractPropertyType | getReturnType () const |
Gets the return-type of the method. More... | |
bool | isValid () const |
Checks whether the metamethod is valid. More... | |
MetaMethod () | |
Constructor. More... | |
template<class TClass > | |
MetaMethod (FixedString name, void(TClass::*method)()) | |
Template constructor for a void method with no argument specialization. More... | |
template<class TClass , typename TRet , typename TRetProp > | |
MetaMethod (FixedString name, const PropertyType< TRetProp > &ret, TRet(TClass::*method)()) | |
Template constructor for a method with return type and no argument specialization. More... | |
template<class TClass , typename TArg1 , typename TArg1Prop > | |
MetaMethod (FixedString name, void(TClass::*method)(TArg1), const PropertyType< TArg1Prop > &property1) | |
Template constructor for a void method with one argument specialization. More... | |
template<class TClass , typename TRet , typename TRetProp , typename TArg1 , typename TArg1Prop > | |
MetaMethod (FixedString name, const PropertyType< TRetProp > &ret, TRet(TClass::*method)(TArg1), const PropertyType< TArg1Prop > &property1) | |
Template constructor for a method with return type and one argument specialization. More... | |
template<class TClass , typename TArg1 , typename TArg1Prop , typename TArg2 , typename TArg2Prop > | |
MetaMethod (FixedString name, void(TClass::*method)(TArg1, TArg2), const PropertyType< TArg1Prop > &property1, const PropertyType< TArg2Prop > &property2) | |
Template constructor for a void method with two arguments specialization. More... | |
template<class TClass , typename TRet , typename TRetProp , typename TArg1 , typename TArg1Prop , typename TArg2 , typename TArg2Prop > | |
MetaMethod (FixedString name, const PropertyType< TRetProp > &ret, TRet(TClass::*method)(TArg1, TArg2), const PropertyType< TArg1Prop > &property1, const PropertyType< TArg2Prop > &property2) | |
Template constructor for a method with return type and two arguments specialization. More... | |
template<class TClass , typename TArg1 , typename TArg1Prop , typename TArg2 , typename TArg2Prop , typename TArg3 , typename TArg3Prop > | |
MetaMethod (FixedString name, void(TClass::*method)(TArg1, TArg2, TArg3), const PropertyType< TArg1Prop > &property1, const PropertyType< TArg2Prop > &property2, const PropertyType< TArg3Prop > &property3) | |
Template constructor for a void method with three arguments specialization. More... | |
template<class TClass , typename TRet , typename TRetProp , typename TArg1 , typename TArg1Prop , typename TArg2 , typename TArg2Prop , typename TArg3 , typename TArg3Prop > | |
MetaMethod (FixedString name, const PropertyType< TRetProp > &ret, TRet(TClass::*method)(TArg1, TArg2, TArg3), const PropertyType< TArg1Prop > &property1, const PropertyType< TArg2Prop > &property2, const PropertyType< TArg3Prop > &property3) | |
Template constructor for a method with return type and three arguments specialization. More... | |
template<class TClass , typename TArg1 , typename TArg1Prop , typename TArg2 , typename TArg2Prop , typename TArg3 , typename TArg3Prop , typename TArg4 , typename TArg4Prop > | |
MetaMethod (FixedString name, void(TClass::*method)(TArg1, TArg2, TArg3, TArg4), const PropertyType< TArg1Prop > &property1, const PropertyType< TArg2Prop > &property2, const PropertyType< TArg3Prop > &property3, const PropertyType< TArg4Prop > &property4) | |
Template constructor for a void method with four arguments specialization. More... | |
template<class TClass , typename TRet , typename TRetProp , typename TArg1 , typename TArg1Prop , typename TArg2 , typename TArg2Prop , typename TArg3 , typename TArg3Prop , typename TArg4 , typename TArg4Prop > | |
MetaMethod (FixedString name, const PropertyType< TRetProp > &ret, TRet(TClass::*method)(TArg1, TArg2, TArg3, TArg4), const PropertyType< TArg1Prop > &property1, const PropertyType< TArg2Prop > &property2, const PropertyType< TArg3Prop > &property3, const PropertyType< TArg4Prop > &property4) | |
Template constructor for a method with return type and four arguments specialization. More... | |
template<class TClass , typename TArg1 , typename TArg1Prop , typename TArg2 , typename TArg2Prop , typename TArg3 , typename TArg3Prop , typename TArg4 , typename TArg4Prop , typename TArg5 , typename TArg5Prop > | |
MetaMethod (FixedString name, void(TClass::*method)(TArg1, TArg2, TArg3, TArg4, TArg5), const PropertyType< TArg1Prop > &property1, const PropertyType< TArg2Prop > &property2, const PropertyType< TArg3Prop > &property3, const PropertyType< TArg4Prop > &property4, const PropertyType< TArg5Prop > &property5) | |
Template constructor for a void method with five arguments specialization. More... | |
template<class TClass , typename TRet , typename TRetProp , typename TArg1 , typename TArg1Prop , typename TArg2 , typename TArg2Prop , typename TArg3 , typename TArg3Prop , typename TArg4 , typename TArg4Prop , typename TArg5 , typename TArg5Prop > | |
MetaMethod (FixedString name, const PropertyType< TRetProp > &ret, TRet(TClass::*method)(TArg1, TArg2, TArg3, TArg4, TArg5), const PropertyType< TArg1Prop > &property1, const PropertyType< TArg2Prop > &property2, const PropertyType< TArg3Prop > &property3, const PropertyType< TArg4Prop > &property4, const PropertyType< TArg5Prop > &property5) | |
Template constructor for a method with return type and five arguments specialization. More... | |
template<class TClass , typename TArg1 , typename TArg1Prop , typename TArg2 , typename TArg2Prop , typename TArg3 , typename TArg3Prop , typename TArg4 , typename TArg4Prop , typename TArg5 , typename TArg5Prop , typename TArg6 , typename TArg6Prop > | |
MetaMethod (FixedString name, void(TClass::*method)(TArg1, TArg2, TArg3, TArg4, TArg5, TArg6), const PropertyType< TArg1Prop > &property1, const PropertyType< TArg2Prop > &property2, const PropertyType< TArg3Prop > &property3, const PropertyType< TArg4Prop > &property4, const PropertyType< TArg5Prop > &property5, const PropertyType< TArg6Prop > &property6) | |
Template constructor for a void method with six arguments specialization. More... | |
template<class TClass , typename TRet , typename TRetProp , typename TArg1 , typename TArg1Prop , typename TArg2 , typename TArg2Prop , typename TArg3 , typename TArg3Prop , typename TArg4 , typename TArg4Prop , typename TArg5 , typename TArg5Prop , typename TArg6 , typename TArg6Prop > | |
MetaMethod (FixedString name, const PropertyType< TRetProp > &ret, TRet(TClass::*method)(TArg1, TArg2, TArg3, TArg4, TArg5, TArg6), const PropertyType< TArg1Prop > &property1, const PropertyType< TArg2Prop > &property2, const PropertyType< TArg3Prop > &property3, const PropertyType< TArg4Prop > &property4, const PropertyType< TArg5Prop > &property5, const PropertyType< TArg6Prop > &property6) | |
Template constructor for a method with return type and six arguments specialization. More... | |
Static Public Member Functions | |
static const MetaMethod * | find (string_view metaMethod, const MetaObject &instance, const MethodArguments &arguments) |
Looks for the metaMethod in the metaclass of the instance with the given arguments. More... | |
static optional< MethodArgument > | invoke (MetaObject &object, string_view metaMethod, const MethodArguments &arguments) |
Combines the functionality of find() and apply() into a single function call. More... | |
static optional< MethodArgument > | invoke (MetaObject &object, string_view metaMethod) |
Overload of invoke() specialized to invoke parameterless methods. More... | |
MetaMethod provides method invocation mechanism for Kanzi classes.
You can expose class methods to scripting and in general to its metadata subsystem using the MetaMethod class. To do so you must register the methods to the metadata of the class using the KZ_METACLASS_METHOD macro.
You can invoke a metamethod on an object using one of the invoke() static methods. Use the string representation of the method you want to invoke.
The arguments are passed to the invocation using the MethodArguments class, where you must specify the argument types with property types which are the same as the targeted method arguments.
For an invocation to succeed, you must set all argument types in the MethodArguments which are present in the signature of the invoked method. Omitting any argument required by the signature results in failure.
When you need to make overloaded methods available to the metadata of the class, to invoke the correct overload, you must create a dedicated MetaMethod instance with a different name.
invoke() stores the return values of the invoked methods in a MethodArgument object. The function returns nullopt if the invocation cannot find the method in the metadata of the object, or in either of its ascendants metadata.
A MethodArgument instance holding the result is returned if the invocation found the method and was able to apply the specified arguments. When the method is of void type, the returned result object contains an invalid MethodArgument instance.
In cases when the argument types are unknown at build time and you need a dynamic argument invocation, use the MetaMethod name to query the MetaMethod from the metaclass of the object, set the arguments based on the method arguments and apply those on the metamethod.
|
explicit |
Constructor.
|
explicit |
Template constructor for a void method with no argument specialization.
name | The name of the metamethod. |
method | The address of the method to be handled. |
|
explicit |
Template constructor for a method with return type and no argument specialization.
name | The name of the metamethod. |
ret | The property type defining the return type of the method. |
method | The address of the method to be handled. |
|
explicit |
Template constructor for a void method with one argument specialization.
name | The name of the metamethod. |
method | The address of the method to be handled. |
property1 | The property type defining the type of the argument. |
|
explicit |
Template constructor for a method with return type and one argument specialization.
name | The name of the metamethod. |
ret | The property type defining the return type of the method. |
method | The address of the method to be handled. |
property1 | The property type defining the type of the argument. |
|
explicit |
Template constructor for a void method with two arguments specialization.
name | The name of the metamethod. |
method | The address of the method to be handled. |
property1 | The property type defining the type of the first argument. |
property2 | The property type defining the type of the second argument. |
invalid_argument | if the property types defining the arguments are identical. |
|
explicit |
Template constructor for a method with return type and two arguments specialization.
name | The name of the metamethod. |
ret | The property type defining the return type of the method. |
method | The address of the method to be handled. |
property1 | The property type defining the type of the first argument. |
property2 | The property type defining the type of the second argument. |
invalid_argument | if the property types defining the arguments are identical. |
|
explicit |
Template constructor for a void method with three arguments specialization.
name | The name of the metamethod. |
method | The address of the method to be handled. |
property1 | The property type defining the type of the first argument. |
property2 | The property type defining the type of the second argument. |
property3 | The property type defining the type of the third argument. |
invalid_argument | if at least two property types defining the arguments are identical. |
|
explicit |
Template constructor for a method with return type and three arguments specialization.
name | The name of the metamethod. |
ret | The property type defining the return type of the method. |
method | The address of the method to be handled. |
property1 | The property type defining the type of the first argument. |
property2 | The property type defining the type of the second argument. |
property3 | The property type defining the type of the third argument. |
invalid_argument | if at least two property types defining the arguments are identical. |
|
explicit |
Template constructor for a void method with four arguments specialization.
name | The name of the metamethod. |
method | The address of the method to be handled. |
property1 | The property type defining the type of the first argument. |
property2 | The property type defining the type of the second argument. |
property3 | The property type defining the type of the third argument. |
property4 | The property type defining the type of the fourth argument. |
invalid_argument | if at least two property types defining the arguments are identical. |
|
explicit |
Template constructor for a method with return type and four arguments specialization.
name | The name of the metamethod. |
ret | The property type defining the return type of the method. |
method | The address of the method to be handled. |
property1 | The property type defining the type of the first argument. |
property2 | The property type defining the type of the second argument. |
property3 | The property type defining the type of the third argument. |
property4 | The property type defining the type of the fourth argument. |
invalid_argument | if at least two property types defining the arguments are identical. |
|
explicit |
Template constructor for a void method with five arguments specialization.
name | The name of the metamethod. |
method | The address of the method to be handled. |
property1 | The property type defining the type of the first argument. |
property2 | The property type defining the type of the second argument. |
property3 | The property type defining the type of the third argument. |
property4 | The property type defining the type of the fourth argument. |
property5 | The property type defining the type of the fifth argument. |
invalid_argument | if at least two property types defining the arguments are identical. |
|
explicit |
Template constructor for a method with return type and five arguments specialization.
name | The name of the metamethod. |
ret | The property type defining the return type of the method. |
method | The address of the method to be handled. |
property1 | The property type defining the type of the first argument. |
property2 | The property type defining the type of the second argument. |
property3 | The property type defining the type of the third argument. |
property4 | The property type defining the type of the fourth argument. |
property5 | The property type defining the type of the fifth argument. |
invalid_argument | if at least two property types defining the arguments are identical. |
|
explicit |
Template constructor for a void method with six arguments specialization.
name | The name of the metamethod. |
method | The address of the method to be handled. |
property1 | The property type defining the type of the first argument. |
property2 | The property type defining the type of the second argument. |
property3 | The property type defining the type of the third argument. |
property4 | The property type defining the type of the fourth argument. |
property5 | The property type defining the type of the fifth argument. |
property6 | The property type defining the type of the sixth argument. |
invalid_argument | if at least two property types defining the arguments are identical. |
|
explicit |
Template constructor for a method with return type and six arguments specialization.
name | The name of the metamethod. |
ret | The property type defining the return type of the method. |
method | The address of the method to be handled. |
property1 | The property type defining the type of the first argument. |
property2 | The property type defining the type of the second argument. |
property3 | The property type defining the type of the third argument. |
property4 | The property type defining the type of the fourth argument. |
property5 | The property type defining the type of the fifth argument. |
property6 | The property type defining the type of the sixth argument. |
invalid_argument | if at least two property types defining the arguments are identical. |
optional<MethodArgument> kanzi::MetaMethod::apply | ( | MetaObject & | instance, |
const MethodArguments & | arguments | ||
) | const |
Applies the arguments on the method of an instance of the class holding the member function.
The return value of the method is stored in the returned MethodArgument object. You can store the arguments in arbitrary order, however you must have all the arguments set required by the signature of the method, otherwise the invocation fails.
instance | The instance of the class on which you want to invoke the method. |
arguments | The argument values with which you want to invoke the method. |
|
static |
Looks for the metaMethod in the metaclass of the instance with the given arguments.
The lookup bubbles up in the ascendants metaclass hierarchy as well as in the mixin metaclasses hierarchy.
metaMethod | The string identifier of the method as registered to the metaclass. |
instance | Instance derived from the MetaObject class. |
arguments | The set of values matching the method parameter types. |
|
static |
Combines the functionality of find() and apply() into a single function call.
object | The object from which to invoke the method. |
metaMethod | The name of the MetaMethod you want to invoke. |
arguments | The argument values with which you want to invoke the method. |
|
static |
Overload of invoke() specialized to invoke parameterless methods.
object | The object the metaMethod to be invoked from. |
metaMethod | The name of the MetaMethod to be invoked. |
const char* kanzi::MetaMethod::getName | ( | ) | const |
Gets the name of the method.
int kanzi::MetaMethod::getArgumentCount | ( | ) | const |
Gets the number of method arguments.
AbstractPropertyType kanzi::MetaMethod::getReturnType | ( | ) | const |
Gets the return-type of the method.
AbstractPropertyType kanzi::MetaMethod::getArgumentType | ( | size_t | index | ) | const |
Gets the argument type from a given index.
index | A 0-based index pointing to the argument type from the signature of the handled method. |
bool kanzi::MetaMethod::isValid | ( | ) | const |
Checks whether the metamethod is valid.
A MetaMethod is valid when it holds a valid method address with the describing argument types.