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

RuntimeMetaObject lets you easily define types at run-time. More...

#include <runtimemetaobject.hpp>

Inheritance diagram for Nuria::RuntimeMetaObject:
Nuria::MetaObject Nuria::QtMetaObjectWrapper

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
 
- Public Types inherited from Nuria::MetaObject
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)
 
- Public Member Functions inherited from Nuria::MetaObject
 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 Public Member Functions inherited from Nuria::MetaObject
static MetaObjectMap allTypes ()
 
static MetaObjectbyName (const QByteArray &type)
 
static MetaObjectbyTypeId (int typeId)
 
template<typename T >
static MetaObjectof ()
 
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)
 

Detailed Description

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.

Usage
  1. Intantiate RuntimeMetaObject
  2. Use the add*() methods to set-up your virtual type
  3. Use finalize() to make the meta-object usable.

You may want to use MetaObject::registerMetaObject() if you want to make your type known application-wide.

Behaviour on uniqueness
The add*() methods will always ensure uniqueness. If two elements are added deemed equal by C++ rules, then the latter one replaces the one already stored. This means when e.g. adding two enums sequentially with the same name, only the latter will be used.

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:

int foo (QString a, int b);
static QByteArray foo (QString house, int mouse);

Member Typedef Documentation

typedef QMultiMap< QByteArray, QVariant > Nuria::RuntimeMetaObject::AnnotationMap

Map for annotations.

typedef std::function< QVariant(void *) > Nuria::RuntimeMetaObject::FieldGetter
See also
addField
typedef std::function< bool(void *, const QVariant &) > Nuria::RuntimeMetaObject::FieldSetter
See also
addField
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.

See also
setDeleter

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.

See also
addMethod

Member Enumeration Documentation

Possible invocation types for InvokeCreator.

Enumerator
Invoke 

Invoke the method with argument validation.

UnsafeInvoke 

Invoke the method without argument validation.

ArgumentTest 

Only do argument validation.

Constructor & Destructor Documentation

Nuria::RuntimeMetaObject::RuntimeMetaObject ( const QByteArray &  name)

Constructor.

Nuria::RuntimeMetaObject::~RuntimeMetaObject ( )

Destructor.

Member Function Documentation

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.

See also
InvokeCreator
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.

void Nuria::RuntimeMetaObject::gateCall ( GateMethod  method,
int  category,
int  index,
int  nth,
void *  result,
void *  additional 
)
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.

See also
InstanceDeleter
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:

myRuntimeMetaObject->setQtMetaTypeId (qMetaTypeId< MyType > ());
void Nuria::RuntimeMetaObject::setQtMetaTypePointerId ( int  pointerTypeId)

Sets the Qt meta-type id of the pointer type. Usage is something like:

myRuntimeMetaObject->setQtMetaTypeId (qMetaTypeId< MyType * > ());

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