NuriaProject Framework
0.1
The NuriaProject Framework
|
The MetaObject class provides access to meta-data of types at run-time. More...
#include <metaobject.hpp>
Public Types | |
enum | GateMethod { ClassName = 0, MetaTypeId = 1, PointerMetaTypeId = 2, BaseClasses = 3, AnnotationCount = 4, MethodCount = 5, FieldCount = 6, EnumCount = 7, AnnotationName = 10, AnnotationValue = 11, MethodName = 20, MethodType = 21, MethodReturnType = 22, MethodArgumentNames = 23, MethodArgumentTypes = 24, MethodCallback = 25, MethodUnsafeCallback = 26, MethodArgumentTest = 27, FieldName = 30, FieldType = 31, FieldRead = 32, FieldWrite = 33, FieldAccess = 34, EnumName = 40, EnumElementCount = 41, EnumElementKey = 42, EnumElementValue = 43, DestroyInstance = 50 } |
Public Member Functions | |
MetaObject () | |
virtual | ~MetaObject () |
MetaAnnotation | annotation (int idx) const |
int | annotationCount () |
int | annotationLowerBound (const QByteArray &name) const |
int | annotationUpperBound (const QByteArray &name) const |
QByteArray | className () |
void | destroyInstance (void *instance) |
MetaEnum | enumAt (int idx) |
MetaEnum | enumByName (const QByteArray &name) |
int | enumCount () |
MetaField | field (int idx) |
MetaField | fieldByName (const QByteArray &name) |
int | fieldCount () |
int | metaTypeId () |
MetaMethod | method (int idx) |
MetaMethod | method (const QVector< QByteArray > &prototype) |
int | methodCount () |
int | methodLowerBound (const QByteArray &name) |
int | methodUpperBound (const QByteArray &name) |
QVector< QByteArray > | parents () |
int | pointerMetaTypeId () |
Static Public Member Functions | |
static MetaObjectMap | allTypes () |
static MetaObject * | byName (const QByteArray &type) |
static MetaObject * | byTypeId (int typeId) |
template<typename T > | |
static MetaObject * | of () |
static void | registerMetaObject (MetaObject *object) |
Registers object to the global meta system. More... | |
static MetaObjectMap | typesInheriting (const QByteArray &typeName) |
static MetaObjectMap | typesWithAnnotation (const QByteArray &name) |
Protected Member Functions | |
virtual void | gateCall (GateMethod method, int category, int index, int nth, void *result, void *additional=0)=0 |
Friends | |
class | MetaAnnotation |
class | MetaEnum |
class | MetaField |
class | MetaMethod |
The MetaObject class provides access to meta-data of types at run-time.
Instances of this class are usually generated by Tria, the code-generator of the Nuria Framework. While this is the primary use-case, you're free to sub-class this class yourself to create types at run-time.
Using Tria you're able to "expose" arbitary structures to be used dynamically at run-time.
If you want to use tria without qmake, please see the nuria.prf file and tria itself for information (Calling it with "-h" as argument).
That already covers the basics. You should probably Q_DECLARE_METATYPE your types. Tria will automatically do this in the generated code for all needed types though.
NURIA_INTROSPECT
will mark a struct or a class to be exported. It's ignored on anything else.
NURIA_SKIP
can be used to explicitly mark elements (methods, enums, fields) to be ignored by Tria.
NURIA_READ
and NURIA_WRITE
mark a method to be used as getter or setter method for the field whose name is passed as only argument. Methods with this annotation will not be exposed as methods themselves. Please refer to MetaField for further information.
NURIA_REQUIRE
is a powerful mechanism which lets you write a requirement which needs to be fulfilled for the operation to succeed. Can be applied to fields and methods (Of all kind). The macro itself takes a C++ condition as check. The condition can call methods as well as use fields directly, as long the method/field the macro is applied to requires a instance of the object itself (E.g., it's a member method). These conditions are embedded into the generated source by Tria, thus there's no notable overhead introduced here.
Except for the conversion operators, all methods are still exposed as normal methods. Methods may take additional optional arguments.
This means that all elements are sorted in ascending order, which allows you to use binary search algorithms.
Please refer to the GateMethod enum class. You can also read the source code of MetaObject or open a file generated by Tria.
|
strong |
Methods for gateCall. You only need to know about this if you intend to sub-class MetaObject yourself.
|
inline |
Constructor, does nothing.
|
inlinevirtual |
Destructor, does nothing.
|
static |
Returns a map of all known types.
MetaAnnotation Nuria::MetaObject::annotation | ( | int | idx | ) | const |
Returns the MetaAnnotation instance for the annotation at idx.
int Nuria::MetaObject::annotationCount | ( | ) |
Returns the number of known annotations.
int Nuria::MetaObject::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::MetaObject::annotationUpperBound | ( | const QByteArray & | name | ) | const |
Returns the index of the last annotation name. Returns -1
if there's no annotation called like that.
|
static |
Returns the corresponding MetaObject instance for type. If type is not known, nullptr
is returned.
|
static |
Returns the MetaObject for the type typeId. If typeId may be the Qt type id for T*
or T
. If no matching meta object is found nullptr
is returned.
QByteArray Nuria::MetaObject::className | ( | ) |
Returns the class name of the represented type.
void Nuria::MetaObject::destroyInstance | ( | void * | instance | ) |
Destroys instance.
MetaEnum Nuria::MetaObject::enumAt | ( | int | idx | ) |
MetaEnum Nuria::MetaObject::enumByName | ( | const QByteArray & | name | ) |
Tries to find the enum name. Returns a valid MetaEnum instance on success, else the instance is invalid.
int Nuria::MetaObject::enumCount | ( | ) |
Returns the number of known enums.
MetaField Nuria::MetaObject::field | ( | int | idx | ) |
Returns the MetaField instance for the field at idx.
MetaField Nuria::MetaObject::fieldByName | ( | const QByteArray & | name | ) |
Tries to find the field name. Returns a valid MetaField instance on success, else the instance is invalid.
int Nuria::MetaObject::fieldCount | ( | ) |
Returns the number of known fields.
|
protectedpure virtual |
Calls the back-end. method will be called, passing category, target and index, the result will be written to result.
Implemented in Nuria::RuntimeMetaObject.
int Nuria::MetaObject::metaTypeId | ( | ) |
Returns the Qt meta-type id of this type. Returns 0
if this type doesn't have value-semantics.
MetaMethod Nuria::MetaObject::method | ( | int | idx | ) |
Returns the MetaMethod instance for the method at idx.
MetaMethod Nuria::MetaObject::method | ( | const QVector< QByteArray > & | prototype | ) |
Tries to find the method prototype. The first item in prototype is the method name, all latter items are typenames of the arguments in the correct order.
The method name of a constructor is "" (Empty). If the method can't be found, the returned method is invalid.
int Nuria::MetaObject::methodCount | ( | ) |
Returns the number of known methods.
int Nuria::MetaObject::methodLowerBound | ( | const QByteArray & | name | ) |
Returns the index of the first overload of method name. Returns -1
if there's no method called like that.
int Nuria::MetaObject::methodUpperBound | ( | const QByteArray & | name | ) |
Returns the index of the last overload of method name. Returns -1
if there's no method called like that.
|
inlinestatic |
Returns the MetaObject of T
. For this to work, T*
has to be registered to the Qt meta system using Q_DECLARE_METATYPE(T*)
QVector< QByteArray > Nuria::MetaObject::parents | ( | ) |
Returns a list of types this type inherits.
int Nuria::MetaObject::pointerMetaTypeId | ( | ) |
Returns the Qt meta-type id of this type as pointer.
|
static |
Registers object to the global meta system.
This method will not take ownership of object, you'll need to make sure that it'll survive until the application quits. Please note that you rarely need to do this by hand.
|
static |
Returns all types which inherit typeName.
|
static |
Returns all types which have a annotation called name stored in the type. This method does not search through methods, etc.