NuriaProject Framework
0.1
The NuriaProject Framework
|
RuntimeMetaObject lets you easily define types at run-time. More...
#include <runtimemetaobject.hpp>
Public Types | |
typedef QMultiMap< QByteArray, QVariant > | AnnotationMap |
typedef std::function< QVariant(void *) > | FieldGetter |
typedef std::function< bool(void *, const QVariant &) > | FieldSetter |
typedef std::function< void(void *) > | InstanceDeleter |
enum | InvokeAction { InvokeAction::Invoke, InvokeAction::UnsafeInvoke, InvokeAction::ArgumentTest } |
typedef std::function< Callback(void *, InvokeAction) > | InvokeCreator |
![]() | |
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 | |
RuntimeMetaObject (const QByteArray &name) | |
~RuntimeMetaObject () | |
void | addEnum (const QByteArray &name, const AnnotationMap &annotations, const QMap< QByteArray, int > &keyValueMap) |
void | addField (const QByteArray &name, const QByteArray &valueType, const AnnotationMap &annotations, FieldGetter getter, FieldSetter setter) |
void | addField (const QByteArray &name, const QByteArray &valueType, const AnnotationMap &annotations, FieldGetter getter) |
void | addMethod (MetaMethod::Type type, const QByteArray &name, const QByteArray &returnType, const QVector< QByteArray > &argumentNames, const QVector< QByteArray > &argumentTypes, const AnnotationMap &annotations, InvokeCreator invokeCreator) |
void | finalize () |
void | setAnnotations (const AnnotationMap &annotations) |
void | setBaseClasses (const QVector< QByteArray > &bases) |
void | setInstanceDeleter (InstanceDeleter deleter) |
void | setQtMetaTypeId (int valueTypeId) |
void | setQtMetaTypePointerId (int pointerTypeId) |
![]() | |
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 () |
Protected Member Functions | |
void | gateCall (GateMethod method, int category, int index, int nth, void *result, void *additional) override |
Additional Inherited Members | |
![]() | |
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) |
RuntimeMetaObject lets you easily define types at run-time.
This class can be used when you want to quickly construct a type at run-time without needing to implement the gateCall method yourself.
You may want to use MetaObject::registerMetaObject() if you want to make your type known application-wide.
Methods are deemed equal if both have the same name and take the same amount of arguments, all of which are the same type. This means that the following two prototypes are equal to RuntimeMetaObject:
typedef QMultiMap< QByteArray, QVariant > Nuria::RuntimeMetaObject::AnnotationMap |
Map for annotations.
typedef std::function< QVariant(void *) > Nuria::RuntimeMetaObject::FieldGetter |
typedef std::function< bool(void *, const QVariant &) > Nuria::RuntimeMetaObject::FieldSetter |
typedef std::function< void(void *) > Nuria::RuntimeMetaObject::InstanceDeleter |
Deleter function which is supposed to destroy the instance passed as first argument and free all memory associated with it.
typedef std::function< Callback(void *, InvokeAction) > Nuria::RuntimeMetaObject::InvokeCreator |
Lambda which when called returns a Nuria::Callback which when invoked does the real call. The first argument passed to this is the instance the returned Callback should act on. It may be nullptr
for constructors or static methods. The second argument is of type InvokeAction which defines the expected behaviouf of the returned callback.
|
strong |
Nuria::RuntimeMetaObject::RuntimeMetaObject | ( | const QByteArray & | name | ) |
Constructor.
Nuria::RuntimeMetaObject::~RuntimeMetaObject | ( | ) |
Destructor.
void Nuria::RuntimeMetaObject::addEnum | ( | const QByteArray & | name, |
const AnnotationMap & | annotations, | ||
const QMap< QByteArray, int > & | keyValueMap | ||
) |
Adds enum name with elements keyValueMap to the type.
void Nuria::RuntimeMetaObject::addField | ( | const QByteArray & | name, |
const QByteArray & | valueType, | ||
const AnnotationMap & | annotations, | ||
FieldGetter | getter, | ||
FieldSetter | setter | ||
) |
Adds a writable field name to this object of valueType. getter is called when the field is read and setter when it should be changed.
void Nuria::RuntimeMetaObject::addField | ( | const QByteArray & | name, |
const QByteArray & | valueType, | ||
const AnnotationMap & | annotations, | ||
FieldGetter | getter | ||
) |
Adds a read-only field name to this object of valueType. getter is called when the field is read.
void Nuria::RuntimeMetaObject::addMethod | ( | MetaMethod::Type | type, |
const QByteArray & | name, | ||
const QByteArray & | returnType, | ||
const QVector< QByteArray > & | argumentNames, | ||
const QVector< QByteArray > & | argumentTypes, | ||
const AnnotationMap & | annotations, | ||
InvokeCreator | invokeCreator | ||
) |
Adds method name as type method with signature returnType, argumentNames, argumentTypes to the meta object. argumentNames and argumentTypes must have the same amount of elements, not doing so will lead to undefined behaviour. invokeCreator is a method which when called returns a Nuria::Callback which when called does the real invocation of the method. Please refer to InvokeCreator for more details on this.
void Nuria::RuntimeMetaObject::finalize | ( | ) |
Calling this method will ensure that all assumptions MetaObject has are met - That is, everything that is sorted is sorted. You have to call this method before using this instance as meta-object.
|
overrideprotectedvirtual |
Calls the back-end. method will be called, passing category, target and index, the result will be written to result.
Implements Nuria::MetaObject.
void Nuria::RuntimeMetaObject::setAnnotations | ( | const AnnotationMap & | annotations | ) |
Sets the annotation of this type.
void Nuria::RuntimeMetaObject::setBaseClasses | ( | const QVector< QByteArray > & | bases | ) |
Sets the base classes.
void Nuria::RuntimeMetaObject::setInstanceDeleter | ( | InstanceDeleter | deleter | ) |
Uses deleter as method which is called when a instance of the type this meta object represents should be destroyed.
The default deleter does nothing.
void Nuria::RuntimeMetaObject::setQtMetaTypeId | ( | int | valueTypeId | ) |
Sets the Qt meta-type id. The default is 0
which is correct if this type doesn't have value-semantics. Usage is something like:
void Nuria::RuntimeMetaObject::setQtMetaTypePointerId | ( | int | pointerTypeId | ) |
Sets the Qt meta-type id of the pointer type. Usage is something like: