The method class provides several meta information about a method and can be invoked. More...
#include <method.h>
Public Member Functions | |
type | get_declaring_type () const |
Returns the class that declares this method. More... | |
variant | get_metadata (int key) const |
Returns the metadata for the given key key . More... | |
variant | get_metadata (const std::string &key) const |
Returns the metadata for the given key key . More... | |
std::string | get_name () const |
Returns the name of this method. More... | |
std::vector< type > | get_parameter_types () const |
Returns an ordered list of type objects which represents the parameters of this method. More... | |
type | get_return_type () const |
Returns the type object of the return type. More... | |
std::string | get_signature () const |
Returns the signature of this method as readable string. More... | |
variant | invoke (detail::instance object) const |
Invokes the method represented by the current instance object . More... | |
variant | invoke (detail::instance object, detail::argument arg1) const |
Invokes the method represented by the current instance object , using the specified parameters. More... | |
variant | invoke (detail::instance object, detail::argument arg1, detail::argument arg2) const |
Invokes the method represented by the current instance object , using the specified parameters. More... | |
variant | invoke (detail::instance object, detail::argument arg1, detail::argument arg2, detail::argument arg3) const |
Invokes the method represented by the current instance object , using the specified parameters. More... | |
variant | invoke (detail::instance object, detail::argument arg1, detail::argument arg2, detail::argument arg3, detail::argument arg4) const |
Invokes the method represented by the current instance object , using the specified parameters. More... | |
variant | invoke (detail::instance object, detail::argument arg1, detail::argument arg2, detail::argument arg3, detail::argument arg4, detail::argument arg5) const |
Invokes the method represented by the current instance object , using the specified parameters. More... | |
variant | invoke (detail::instance object, detail::argument arg1, detail::argument arg2, detail::argument arg3, detail::argument arg4, detail::argument arg5, detail::argument arg6) const |
Invokes the method represented by the current instance object , using the specified parameters. More... | |
variant | invoke_variadic (detail::instance object, std::vector< detail::argument > args) const |
Invokes the method represented by the current instance object , using the specified parameters. More... | |
bool | is_static () const |
Returns true if this method is static method, otherwise false. More... | |
bool | is_valid () const |
Returns true if this method is valid, otherwise false. More... | |
operator bool () const | |
Convenience function to check if this method is valid or not. More... | |
bool | operator!= (const method &other) const |
Returns true if this method is the not the same like the other . More... | |
bool | operator== (const method &other) const |
Returns true if this method is the same like the other . More... | |
The method class provides several meta information about a method and can be invoked.
A instance of a method class can only be obtained from the type class. See type::get_method() and type::get_methods().
For registration a method, nested inside a class, see class_::method() and for global methods see register_global::method.
A method has a name, a signature, a return type, a list of parameter types as well as attributes that specify its behavior: is_static(). When the method was declared inside a class, then get_declaring_type() can be used to obtain the type of this class.
The method can be invoked with invoke(); When its not a static method you have to provide a valid class instance to invoke the method. This instance can be the raw type on the stack; the current class hierarchy level doesn't matter. It can be also a raw pointer to the object or a variant which contains the instance, again as pointer or stack object. When the method is declared as static you you still have to provide a dummy instance object, therefore the function rttr::empty_instance()
should be used.
A method will be successfully invoked when the provided instance can be converted to the declared class type. When the method has parameters defined, then the same number of arguments must be provided and the type itself must 100% match the type of the registered function. An automatically type conversion is not performed.
The return type of invoke() is variant object. This object contains not only the possible return value of a function, it also indicates whether the method was invoked or not. A valid variant object means, that then the method was successfully invoked, otherwise not. When the invoked method has no return type, i.e. is a void
method, then a valid variant of type void
is returned.
While the invoke() function can directly forward up to six arguments, it is sometime necessary to forward even more arguments. Therefore the function invoke_variadic() should be used; it allows to pack an unlimited amount of arguments into a std::vector and forward them to the function.
Another way to invoke a method is to use the type class through invoke_method().
A method object is lightweight and can be copied by value. However, each copy will refer to the same underlying method.
type rttr::method::get_declaring_type | ( | ) | const |
Returns the class that declares this method.
variant rttr::method::get_metadata | ( | int | key | ) | const |
Returns the metadata for the given key key
.
key
, an invalid variant object is returned (see variant::is_valid).variant rttr::method::get_metadata | ( | const std::string & | key | ) | const |
Returns the metadata for the given key key
.
key
, an invalid variant object is returned (see variant::is_valid).std::string rttr::method::get_name | ( | ) | const |
Returns the name of this method.
std::vector<type> rttr::method::get_parameter_types | ( | ) | const |
Returns an ordered list of type objects which represents the parameters of this method.
type rttr::method::get_return_type | ( | ) | const |
Returns the type object of the return type.
std::string rttr::method::get_signature | ( | ) | const |
Returns the signature of this method as readable string.
variant rttr::method::invoke | ( | detail::instance | object | ) | const |
Invokes the method represented by the current instance object
.
empty_instance()
.variant rttr::method::invoke | ( | detail::instance | object, |
detail::argument | arg1 | ||
) | const |
Invokes the method represented by the current instance object
, using the specified parameters.
empty_instance()
.variant rttr::method::invoke | ( | detail::instance | object, |
detail::argument | arg1, | ||
detail::argument | arg2 | ||
) | const |
Invokes the method represented by the current instance object
, using the specified parameters.
empty_instance()
.variant rttr::method::invoke | ( | detail::instance | object, |
detail::argument | arg1, | ||
detail::argument | arg2, | ||
detail::argument | arg3 | ||
) | const |
Invokes the method represented by the current instance object
, using the specified parameters.
empty_instance()
.variant rttr::method::invoke | ( | detail::instance | object, |
detail::argument | arg1, | ||
detail::argument | arg2, | ||
detail::argument | arg3, | ||
detail::argument | arg4 | ||
) | const |
Invokes the method represented by the current instance object
, using the specified parameters.
empty_instance()
.variant rttr::method::invoke | ( | detail::instance | object, |
detail::argument | arg1, | ||
detail::argument | arg2, | ||
detail::argument | arg3, | ||
detail::argument | arg4, | ||
detail::argument | arg5 | ||
) | const |
Invokes the method represented by the current instance object
, using the specified parameters.
empty_instance()
.variant rttr::method::invoke | ( | detail::instance | object, |
detail::argument | arg1, | ||
detail::argument | arg2, | ||
detail::argument | arg3, | ||
detail::argument | arg4, | ||
detail::argument | arg5, | ||
detail::argument | arg6 | ||
) | const |
Invokes the method represented by the current instance object
, using the specified parameters.
empty_instance()
.variant rttr::method::invoke_variadic | ( | detail::instance | object, |
std::vector< detail::argument > | args | ||
) | const |
Invokes the method represented by the current instance object
, using the specified parameters.
Use this method when the argument count is higher then six.
empty_instance()
.bool rttr::method::is_static | ( | ) | const |
Returns true if this method is static method, otherwise false.
A static method does not need an instance for performing an invoke.
bool rttr::method::is_valid | ( | ) | const |
Returns true if this method is valid, otherwise false.
rttr::method::operator bool | ( | ) | const |
Convenience function to check if this method is valid or not.
bool rttr::method::operator!= | ( | const method & | other | ) | const |
Returns true if this method is the not the same like the other
.
bool rttr::method::operator== | ( | const method & | other | ) | const |
Returns true if this method is the same like the other
.