kanzi::MetaMethod Class Reference

MetaMethod provides method invocation mechanism for Kanzi classes. More...

#include <kanzi/core/metadata/metamethod.hpp>

Public Member Functions

 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...
 
optional< MethodArgumentapply (MetaObject &instance, const MethodArguments &arguments) const
 Applies the arguments on the method of an instance of the class holding the member function. More...
 
const char * getName () const
 Gets the name of the method. More...
 
int getArgumentCount () const
 Gets the number of method arguments. More...
 
AbstractPropertyType getReturnType () const
 Gets the return-type of the method. More...
 
AbstractPropertyType getArgumentType (size_t index) const
 Gets the argument type from a given index. More...
 
bool isValid () const
 Checks whether the metamethod is valid. More...
 

Static Public Member Functions

static const MetaMethodfind (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< MethodArgumentinvoke (MetaObject &object, string_view metaMethod, const MethodArguments &arguments)
 Combines the functionality of find() and apply() into a single function call. More...
 
static optional< MethodArgumentinvoke (MetaObject &object, string_view metaMethod)
 Overload of invoke() specialized to invoke parameterless methods. More...
 

Detailed Description

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.

class ExposeMethods : public MetaObject
{
public:
KZ_METACLASS_BEGIN(ExposeMethods, MetaObject, "Test.ExposeMethods")
KZ_METACLASS_PROPERTY_TYPE(IntPropertyType)
KZ_METACLASS_PROPERTY_TYPE(StringPropertyType)
KZ_METACLASS_METHOD(VoidMethod)
KZ_METACLASS_METHOD(VirtualMethod)
KZ_METACLASS_METHOD(OneArgument)
KZ_METACLASS_METHOD(TwoArguments)
KZ_METACLASS_METHOD(VoidMethodOverload)
static PropertyType<int> IntPropertyType;
static PropertyType<kanzi::string> StringPropertyType;
static MetaMethod VoidMethod;
static MetaMethod StringRet;
static MetaMethod VirtualMethod;
static MetaMethod OneArgument;
static MetaMethod TwoArguments;
static MetaMethod VoidMethodOverload;
static shared_ptr<ExposeMethods> create(Domain*, string_view)
{
return shared_ptr<ExposeMethods>(new ExposeMethods);
}
explicit ExposeMethods();
bool m_voidMethodCalled;
bool m_virtualMethodCalled;
int m_intDataReceived;
kanzi::string m_stringDataReceived;
void voidMethod();
string stringRet();
virtual void virtualMethod();
void oneArgument(int i);
void twoArguments(int i, const kanzi::string& s);
void voidMethod(int i);
};
PropertyType<int> ExposeMethods::IntPropertyType(kzMakeFixedString("Test.ExposeMethods.IntPropertyType"), -30, 0, true);
PropertyType<kanzi::string> ExposeMethods::StringPropertyType(kzMakeFixedString("Test.ExposeMethods.StringPropertyType"), "lazy dog", 0, true);
MetaMethod ExposeMethods::VoidMethod(kzMakeFixedString("voidMethod"), &ExposeMethods::voidMethod);
MetaMethod ExposeMethods::StringRet(kzMakeFixedString("stringRet"), ExposeMethods::StringPropertyType, &ExposeMethods::stringRet);
MetaMethod ExposeMethods::VirtualMethod(kzMakeFixedString("virtualMethod"), &ExposeMethods::virtualMethod);
MetaMethod ExposeMethods::OneArgument(kzMakeFixedString("oneArgument"), &ExposeMethods::oneArgument, ExposeMethods::IntPropertyType);
MetaMethod ExposeMethods::TwoArguments(kzMakeFixedString("twoArguments"), &ExposeMethods::twoArguments, ExposeMethods::IntPropertyType, ExposeMethods::StringPropertyType);
MetaMethod ExposeMethods::VoidMethodOverload(kzMakeFixedString("voidMethod2"), &ExposeMethods::voidMethod, ExposeMethods::IntPropertyType);

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.

shared_ptr<ExposeMethods> object = ExposeMethods::create(0, "");
// Invoke ExposeMethod::voidMethod metamethod
MetaMethod::invoke(*object, "voidMethod");

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.

MethodArguments args;
// Re-use IntPropertyType to set the argument value
args.setArgument(ExposeMethods::IntPropertyType, 100);
// Invoke SingleArgument method with the arguments set
optional<MethodArgument> result = MetaMethod::invoke(*object, "oneArgument", args);

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.

optional<MethodArgument> result = MetaMethod::invoke(*object, "oneArgument");
if (result)
{
// Code execution will not reach here as the method expects an argument,
// and none were given.
}

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.

MethodArguments args;
args.setArgument(ExposeMethods::IntPropertyType, 42);
// We invoke the metamethod identified as "voidMethod2", which is an
// overload of voidMethod() with one integer argument.
optional<MethodArgument> result = MetaMethod::invoke(*object, "voidMethod2", args);

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.

optional<MethodArgument> result = MetaMethod::invoke(*object, "NullMethod");

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.

// Invoke ExposeMethod::StringRet metamethod and check if invocation succeeded
optional<MethodArgument> result = MetaMethod::invoke(*object, "stringRet");
// If the invocation succeeded, and we have a return value...
if (result != nullopt && result.value().isValid())
{
// do something with the returned value.
}

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.

typedef map<PropertyDataType, Variant> ValueMap;
shared_ptr<ExposeMethods> instance = ExposeMethods::create(0, "");
ValueMap valueMap;
valueMap.insert(make_pair(PropertyDataTypeInt, Variant(321)));
valueMap.insert(make_pair(PropertyDataTypeString, Variant(string("Archaeopteryx"))));
MethodArguments arguments;
// Look for twoArguments method, with one integer and a string parameter
const MetaMethod* method = instance->getDynamicMetaclass()->findMethod("twoArguments");
if (method)
{
// Build the arguments based on the method parameters
for (int i = 0; i < method->getArgumentCount(); i++)
{
AbstractPropertyType type = method->getArgumentType(i);
switch (type.getDataType())
{
arguments.setAbstractArgument(type, get<int>(valueMap.at(PropertyDataTypeInt)));
break;
arguments.setAbstractArgument(type, get<string>(valueMap.at(PropertyDataTypeString)));
break;
default:
// we do not handle other types
break;
}
}
// apply the arguments on the method
method->apply(*instance, arguments);
}

Constructor & Destructor Documentation

kanzi::MetaMethod::MetaMethod ( )
explicit

Constructor.

template<class TClass >
kanzi::MetaMethod::MetaMethod ( FixedString  name,
void(TClass::*)()  method 
)
explicit

Template constructor for a void method with no argument specialization.

Parameters
nameThe name of the metamethod.
methodThe address of the method to be handled.
template<class TClass , typename TRet , typename TRetProp >
kanzi::MetaMethod::MetaMethod ( FixedString  name,
const PropertyType< TRetProp > &  ret,
TRet(TClass::*)()  method 
)
explicit

Template constructor for a method with return type and no argument specialization.

Parameters
nameThe name of the metamethod.
retThe property type defining the return type of the method.
methodThe address of the method to be handled.
template<class TClass , typename TArg1 , typename TArg1Prop >
kanzi::MetaMethod::MetaMethod ( FixedString  name,
void(TClass::*)(TArg1)  method,
const PropertyType< TArg1Prop > &  property1 
)
explicit

Template constructor for a void method with one argument specialization.

Parameters
nameThe name of the metamethod.
methodThe address of the method to be handled.
property1The property type defining the type of the argument.
template<class TClass , typename TRet , typename TRetProp , typename TArg1 , typename TArg1Prop >
kanzi::MetaMethod::MetaMethod ( FixedString  name,
const PropertyType< TRetProp > &  ret,
TRet(TClass::*)(TArg1)  method,
const PropertyType< TArg1Prop > &  property1 
)
explicit

Template constructor for a method with return type and one argument specialization.

Parameters
nameThe name of the metamethod.
retThe property type defining the return type of the method.
methodThe address of the method to be handled.
property1The property type defining the type of the argument.
template<class TClass , typename TArg1 , typename TArg1Prop , typename TArg2 , typename TArg2Prop >
kanzi::MetaMethod::MetaMethod ( FixedString  name,
void(TClass::*)(TArg1, TArg2)  method,
const PropertyType< TArg1Prop > &  property1,
const PropertyType< TArg2Prop > &  property2 
)
explicit

Template constructor for a void method with two arguments specialization.

Parameters
nameThe name of the metamethod.
methodThe address of the method to be handled.
property1The property type defining the type of the first argument.
property2The property type defining the type of the second argument.
Exceptions
invalid_argumentif the property types defining the arguments are identical.
template<class TClass , typename TRet , typename TRetProp , typename TArg1 , typename TArg1Prop , typename TArg2 , typename TArg2Prop >
kanzi::MetaMethod::MetaMethod ( FixedString  name,
const PropertyType< TRetProp > &  ret,
TRet(TClass::*)(TArg1, TArg2)  method,
const PropertyType< TArg1Prop > &  property1,
const PropertyType< TArg2Prop > &  property2 
)
explicit

Template constructor for a method with return type and two arguments specialization.

Parameters
nameThe name of the metamethod.
retThe property type defining the return type of the method.
methodThe address of the method to be handled.
property1The property type defining the type of the first argument.
property2The property type defining the type of the second argument.
Exceptions
invalid_argumentif the property types defining the arguments are identical.
template<class TClass , typename TArg1 , typename TArg1Prop , typename TArg2 , typename TArg2Prop , typename TArg3 , typename TArg3Prop >
kanzi::MetaMethod::MetaMethod ( FixedString  name,
void(TClass::*)(TArg1, TArg2, TArg3)  method,
const PropertyType< TArg1Prop > &  property1,
const PropertyType< TArg2Prop > &  property2,
const PropertyType< TArg3Prop > &  property3 
)
explicit

Template constructor for a void method with three arguments specialization.

Parameters
nameThe name of the metamethod.
methodThe address of the method to be handled.
property1The property type defining the type of the first argument.
property2The property type defining the type of the second argument.
property3The property type defining the type of the third argument.
Exceptions
invalid_argumentif at least two property types defining the arguments are identical.
template<class TClass , typename TRet , typename TRetProp , typename TArg1 , typename TArg1Prop , typename TArg2 , typename TArg2Prop , typename TArg3 , typename TArg3Prop >
kanzi::MetaMethod::MetaMethod ( FixedString  name,
const PropertyType< TRetProp > &  ret,
TRet(TClass::*)(TArg1, TArg2, TArg3)  method,
const PropertyType< TArg1Prop > &  property1,
const PropertyType< TArg2Prop > &  property2,
const PropertyType< TArg3Prop > &  property3 
)
explicit

Template constructor for a method with return type and three arguments specialization.

Parameters
nameThe name of the metamethod.
retThe property type defining the return type of the method.
methodThe address of the method to be handled.
property1The property type defining the type of the first argument.
property2The property type defining the type of the second argument.
property3The property type defining the type of the third argument.
Exceptions
invalid_argumentif at least two property types defining the arguments are identical.
template<class TClass , typename TArg1 , typename TArg1Prop , typename TArg2 , typename TArg2Prop , typename TArg3 , typename TArg3Prop , typename TArg4 , typename TArg4Prop >
kanzi::MetaMethod::MetaMethod ( FixedString  name,
void(TClass::*)(TArg1, TArg2, TArg3, TArg4)  method,
const PropertyType< TArg1Prop > &  property1,
const PropertyType< TArg2Prop > &  property2,
const PropertyType< TArg3Prop > &  property3,
const PropertyType< TArg4Prop > &  property4 
)
explicit

Template constructor for a void method with four arguments specialization.

Parameters
nameThe name of the metamethod.
methodThe address of the method to be handled.
property1The property type defining the type of the first argument.
property2The property type defining the type of the second argument.
property3The property type defining the type of the third argument.
property4The property type defining the type of the fourth argument.
Exceptions
invalid_argumentif at least two property types defining the arguments are identical.
template<class TClass , typename TRet , typename TRetProp , typename TArg1 , typename TArg1Prop , typename TArg2 , typename TArg2Prop , typename TArg3 , typename TArg3Prop , typename TArg4 , typename TArg4Prop >
kanzi::MetaMethod::MetaMethod ( FixedString  name,
const PropertyType< TRetProp > &  ret,
TRet(TClass::*)(TArg1, TArg2, TArg3, TArg4)  method,
const PropertyType< TArg1Prop > &  property1,
const PropertyType< TArg2Prop > &  property2,
const PropertyType< TArg3Prop > &  property3,
const PropertyType< TArg4Prop > &  property4 
)
explicit

Template constructor for a method with return type and four arguments specialization.

Parameters
nameThe name of the metamethod.
retThe property type defining the return type of the method.
methodThe address of the method to be handled.
property1The property type defining the type of the first argument.
property2The property type defining the type of the second argument.
property3The property type defining the type of the third argument.
property4The property type defining the type of the fourth argument.
Exceptions
invalid_argumentif at least two property types defining the arguments are identical.
template<class TClass , typename TArg1 , typename TArg1Prop , typename TArg2 , typename TArg2Prop , typename TArg3 , typename TArg3Prop , typename TArg4 , typename TArg4Prop , typename TArg5 , typename TArg5Prop >
kanzi::MetaMethod::MetaMethod ( FixedString  name,
void(TClass::*)(TArg1, TArg2, TArg3, TArg4, TArg5)  method,
const PropertyType< TArg1Prop > &  property1,
const PropertyType< TArg2Prop > &  property2,
const PropertyType< TArg3Prop > &  property3,
const PropertyType< TArg4Prop > &  property4,
const PropertyType< TArg5Prop > &  property5 
)
explicit

Template constructor for a void method with five arguments specialization.

Parameters
nameThe name of the metamethod.
methodThe address of the method to be handled.
property1The property type defining the type of the first argument.
property2The property type defining the type of the second argument.
property3The property type defining the type of the third argument.
property4The property type defining the type of the fourth argument.
property5The property type defining the type of the fifth argument.
Exceptions
invalid_argumentif at least two property types defining the arguments are identical.
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 >
kanzi::MetaMethod::MetaMethod ( FixedString  name,
const PropertyType< TRetProp > &  ret,
TRet(TClass::*)(TArg1, TArg2, TArg3, TArg4, TArg5)  method,
const PropertyType< TArg1Prop > &  property1,
const PropertyType< TArg2Prop > &  property2,
const PropertyType< TArg3Prop > &  property3,
const PropertyType< TArg4Prop > &  property4,
const PropertyType< TArg5Prop > &  property5 
)
explicit

Template constructor for a method with return type and five arguments specialization.

Parameters
nameThe name of the metamethod.
retThe property type defining the return type of the method.
methodThe address of the method to be handled.
property1The property type defining the type of the first argument.
property2The property type defining the type of the second argument.
property3The property type defining the type of the third argument.
property4The property type defining the type of the fourth argument.
property5The property type defining the type of the fifth argument.
Exceptions
invalid_argumentif at least two property types defining the arguments are identical.
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 >
kanzi::MetaMethod::MetaMethod ( FixedString  name,
void(TClass::*)(TArg1, TArg2, TArg3, TArg4, TArg5, TArg6)  method,
const PropertyType< TArg1Prop > &  property1,
const PropertyType< TArg2Prop > &  property2,
const PropertyType< TArg3Prop > &  property3,
const PropertyType< TArg4Prop > &  property4,
const PropertyType< TArg5Prop > &  property5,
const PropertyType< TArg6Prop > &  property6 
)
explicit

Template constructor for a void method with six arguments specialization.

Parameters
nameThe name of the metamethod.
methodThe address of the method to be handled.
property1The property type defining the type of the first argument.
property2The property type defining the type of the second argument.
property3The property type defining the type of the third argument.
property4The property type defining the type of the fourth argument.
property5The property type defining the type of the fifth argument.
property6The property type defining the type of the sixth argument.
Exceptions
invalid_argumentif at least two property types defining the arguments are identical.
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 >
kanzi::MetaMethod::MetaMethod ( FixedString  name,
const PropertyType< TRetProp > &  ret,
TRet(TClass::*)(TArg1, TArg2, TArg3, TArg4, TArg5, TArg6)  method,
const PropertyType< TArg1Prop > &  property1,
const PropertyType< TArg2Prop > &  property2,
const PropertyType< TArg3Prop > &  property3,
const PropertyType< TArg4Prop > &  property4,
const PropertyType< TArg5Prop > &  property5,
const PropertyType< TArg6Prop > &  property6 
)
explicit

Template constructor for a method with return type and six arguments specialization.

Parameters
nameThe name of the metamethod.
retThe property type defining the return type of the method.
methodThe address of the method to be handled.
property1The property type defining the type of the first argument.
property2The property type defining the type of the second argument.
property3The property type defining the type of the third argument.
property4The property type defining the type of the fourth argument.
property5The property type defining the type of the fifth argument.
property6The property type defining the type of the sixth argument.
Exceptions
invalid_argumentif at least two property types defining the arguments are identical.

Member Function Documentation

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.

Parameters
instanceThe instance of the class on which you want to invoke the method.
argumentsThe argument values with which you want to invoke the method.
Returns
The return value of the method. If the method is void, an invalid object. If the MetaMethod is invalid or arguments do not match, nullopt.
static const MetaMethod* kanzi::MetaMethod::find ( string_view  metaMethod,
const MetaObject instance,
const MethodArguments arguments 
)
static

Looks for the metaMethod in the metaclass of the instance with the given arguments.

The lookup bubbles up in the ascendants metaclass hierarchy.

Parameters
metaMethodThe string identifier of the method as registered to the metaclass.
instanceInstance derived from the MetaObject class.
argumentsThe set of values matching the method parameter types.
Returns
The pointer to the MetaMethod registered in the metadata of the class handling the method. If no method is found, nullptr.
static optional<MethodArgument> kanzi::MetaMethod::invoke ( MetaObject object,
string_view  metaMethod,
const MethodArguments arguments 
)
static

Combines the functionality of find() and apply() into a single function call.

Parameters
objectThe object from which to invoke the method.
metaMethodThe name of the MetaMethod you want to invoke.
argumentsThe argument values with which you want to invoke the method.
Returns
A MetaArgument object containing the result values. If the invocation failed, nullopt.
static optional<MethodArgument> kanzi::MetaMethod::invoke ( MetaObject object,
string_view  metaMethod 
)
static

Overload of invoke() specialized to invoke parameterless methods.

Note
This is similar to calling {invoke(object, metaMethod, MethodArguments())} method.
Parameters
objectThe object the metaMethod to be invoked from.
metaMethodThe name of the MetaMethod to be invoked.
Returns
A MetaArgument object containing the result values. If the invocation failed, nullptr.
const char* kanzi::MetaMethod::getName ( ) const

Gets the name of the method.

Returns
The name of the MetaMethod. If the MetaMethod is invalid, nullptr.
int kanzi::MetaMethod::getArgumentCount ( ) const

Gets the number of method arguments.

Returns
The number of arguments. When called on an invalid MetaMethod, -1.
AbstractPropertyType kanzi::MetaMethod::getReturnType ( ) const

Gets the return-type of the method.

Returns
The abstract property type defining the return type. For void function members this value is invalid.
AbstractPropertyType kanzi::MetaMethod::getArgumentType ( size_t  index) const

Gets the argument type from a given index.

Parameters
indexA 0-based index pointing to the argument type from the signature of the handled method.
Returns
The abstract property type defining the argument. If the index does not point to a valid argument from the signature of the method, the function returns an invalid type.
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.

Member Data Documentation

InvokerFunction kanzi::MetaMethod::invoker
AbstractPropertyType kanzi::MetaMethod::returnType
vector<AbstractPropertyType> kanzi::MetaMethod::argumentTypes
const char* kanzi::MetaMethod::name

The documentation for this class was generated from the following file: