22#ifndef CUTELEE_METATYPE_H
23#define CUTELEE_METATYPE_H
25#include "cutelee_templates_export.h"
29#include <QtCore/QVariant>
50class CUTELEE_TEMPLATES_EXPORT MetaType
61 static void registerLookUpOperator(
int id, LookupFunction f);
66 static void internalLock();
71 static void internalUnlock();
81 static bool lookupAlreadyRegistered(
int id);
94template <
typename RealType,
typename HandleAs>
struct LookupTrait {
97 typedef typename Cutelee::TypeAccessor<RealType> Accessor;
98 return Accessor::lookUp(
object.value<RealType>(), property);
102template <
typename RealType,
typename HandleAs>
103struct LookupTrait<RealType &, HandleAs &> {
106 typedef typename Cutelee::TypeAccessor<HandleAs &> Accessor;
107 return Accessor::lookUp(
object.value<HandleAs>(), property);
111template <
typename RealType,
typename HandleAs>
static int doRegister(
int id)
113 if (MetaType::lookupAlreadyRegistered(
id))
117 = LookupTrait<RealType, HandleAs>::doLookUp;
119 MetaType::registerLookUpOperator(
120 id,
reinterpret_cast<MetaType::LookupFunction
>(lf));
128template <
typename RealType,
typename HandleAs>
struct InternalRegisterType {
131 const int id = qMetaTypeId<RealType>();
132 return doRegister<RealType &, HandleAs &>(
id);
136template <
typename RealType,
typename HandleAs>
137struct InternalRegisterType<RealType *, HandleAs *> {
140 const int id = qMetaTypeId<RealType *>();
141 return doRegister<RealType *, HandleAs *>(
id);
184 MetaType::internalLock();
186 const int id = InternalRegisterType<RealType, HandleAs>::doReg();
188 MetaType::internalUnlock();
202 return registerMetaType<Type, Type>();
213#define CUTELEE_BEGIN_LOOKUP(Type) \
217 inline QVariant TypeAccessor<Type &>::lookUp(const Type &object, \
218 const QString &property) \
226#define CUTELEE_BEGIN_LOOKUP_PTR(Type) \
230 inline QVariant TypeAccessor<Type *>::lookUp(const Type *const object, \
231 const QString &property) \
239#define CUTELEE_END_LOOKUP \
The Cutelee namespace holds all public Cutelee API.
int registerMetaType()
Registers the type RealType with the metatype system.