NuriaProject Framework  0.1
The NuriaProject Framework
Public Types | Public Member Functions | Friends | List of all members
Nuria::MetaMethod Class Reference

The MetaMethod class lets you access methods from registered types. More...

#include <metaobject.hpp>

Public Types

enum  Type { Method = 0, Static = 1, Constructor = 2 }
 

Public Member Functions

 MetaMethod ()
 
MetaAnnotation annotation (int idx) const
 
int annotationCount () const
 
int annotationLowerBound (const QByteArray &name) const
 
int annotationUpperBound (const QByteArray &name) const
 
QVector< QByteArray > argumentNames () const
 
QVector< QByteArray > argumentTypes () const
 
Callback callback (void *instance=nullptr) const
 
bool isValid () const
 
QByteArray name () const
 
QByteArray returnType () const
 
Callback testCallback (void *instance=nullptr) const
 
Type type () const
 
Callback unsafeCallback (void *instance=nullptr) const
 

Friends

class MetaObject
 

Detailed Description

The MetaMethod class lets you access methods from registered types.

By default, constructors, static and member methods are exported.

Order of methods
Methods are sorted by name first and then by argument count in ascending order. If there are more than one methods with the same name and same argument count, only differing in argument types expected, the order is undefined.
Methods with default argument values
Methods with default argument values are "expanded", meaning that for each possible function prototype a method is exposed of the same name.

Thus, the method int foo (int a = 1, int b = 2, int c = 3); would be expanded into four methods:

int foo ();
int foo (int a);
int foo (int a, int b);
int foo (int a, int b, int c);
Usage
You can use callback() and unsafeCallback() to retrieve a Callback instance which, when invoked, will call the actual method. Those methods are only different when using NURIA_REQUIRE. When a method have a NURIA_REQUIRE annotation attached, it'll be used to validate arguments on invocation. Arguments can be checked by their name.
Note
Returned Callback instances are bound to whatever instance you passed to the getter method.
Constructors
Unlike the Qt API, constructors are exposed as methods and to be used like static methods. The returned QVariant will report a type of Type*.
Note
To get the pointer to the instance easily, use Variant::stealPointer().
Behaviour of NURIA_REQUIRE
NURIA_REQUIRE gets evaluated before calling the method itself. If the call fails a invalid QVariant is returned. To check if a void method succeeded or not you'll have to use testCallback(). To avoid further checks after you did it yourself, you can use unsafeCallback().

Member Enumeration Documentation

Different types of methods.

Enumerator
Method 

Member method. Requires a valid instance.

Static 

Static method.

Constructor 

Constructor.

Constructor & Destructor Documentation

Nuria::MetaMethod::MetaMethod ( )

Creates a invalid instance.

Member Function Documentation

MetaAnnotation Nuria::MetaMethod::annotation ( int  idx) const

Returns the MetaAnnotation instance for the annotation at idx.

See also
annotationCount
int Nuria::MetaMethod::annotationCount ( ) const

Returns the number of known annotations.

See also
annotation
int Nuria::MetaMethod::annotationLowerBound ( const QByteArray &  name) const

Returns the index of the first annotation name. Returns -1 if there's no annotation called like that.

int Nuria::MetaMethod::annotationUpperBound ( const QByteArray &  name) const

Returns the index of the last annotation name. Returns -1 if there's no annotation called like that.

QVector< QByteArray > Nuria::MetaMethod::argumentNames ( ) const

Returns a list of all argument names.

QVector< QByteArray > Nuria::MetaMethod::argumentTypes ( ) const

Returns a list of all argument types.

Callback Nuria::MetaMethod::callback ( void *  instance = nullptr) const

Returns a callback of this method. Invoking it will call the method itself. If type() is Method, then instance must point to a valid instance of the type this instance is pointing to. Not doing so will lead to undefined behaviour and probably crash the application.

The returned callback will also validate arguments if the method was annotated using NURIA_REQUIRE.

See also
Callback unsafeCallback
bool Nuria::MetaMethod::isValid ( ) const

Returns true if this instance is valid.

QByteArray Nuria::MetaMethod::name ( ) const

Returns the name of the method.

QByteArray Nuria::MetaMethod::returnType ( ) const

Returns the result type name.

Callback Nuria::MetaMethod::testCallback ( void *  instance = nullptr) const

Returns a callback which returns true when calling with arguments which would pass NURIA_REQUIRE tests. If the method doesn't have a NURIA_REQUIRE annotation, the returned callback is invalid.

Type Nuria::MetaMethod::type ( ) const

Returns the type of this method.

Callback Nuria::MetaMethod::unsafeCallback ( void *  instance = nullptr) const

Returns a callback pointing to the method. The only difference to callback() is that this method will not validate any arguments.

Use with care.

See also
callback

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