22 #ifndef GRANTLEE_METATYPE_H 23 #define GRANTLEE_METATYPE_H 25 #include "grantlee_templates_export.h" 29 #include <QtCore/QVariant> 52 class GRANTLEE_TEMPLATES_EXPORT MetaType
58 typedef QVariant (*LookupFunction)(
const QVariant &,
const QString &);
63 static void registerLookUpOperator(
int id, LookupFunction f);
68 static void internalLock();
73 static void internalUnlock();
78 static QVariant lookup(
const QVariant &
object,
const QString &property);
83 static bool lookupAlreadyRegistered(
int id);
96 template <
typename RealType,
typename HandleAs>
struct LookupTrait {
97 static QVariant doLookUp(
const QVariant &
object,
const QString &property)
99 typedef typename Grantlee::TypeAccessor<RealType> Accessor;
100 return Accessor::lookUp(
object.value<RealType>(), property);
104 template <
typename RealType,
typename HandleAs>
105 struct LookupTrait<RealType &, HandleAs &> {
106 static QVariant doLookUp(
const QVariant &
object,
const QString &property)
108 typedef typename Grantlee::TypeAccessor<HandleAs &> Accessor;
109 return Accessor::lookUp(
object.value<HandleAs>(), property);
113 template <
typename RealType,
typename HandleAs>
static int doRegister(
int id)
115 if (MetaType::lookupAlreadyRegistered(
id))
118 QVariant (*lf)(
const QVariant &,
const QString &)
119 = LookupTrait<RealType, HandleAs>::doLookUp;
121 MetaType::registerLookUpOperator(
122 id, reinterpret_cast<MetaType::LookupFunction>(lf));
130 template <
typename RealType,
typename HandleAs>
struct InternalRegisterType {
133 const int id = qMetaTypeId<RealType>();
134 return doRegister<RealType &, HandleAs &>(id);
138 template <
typename RealType,
typename HandleAs>
139 struct InternalRegisterType<RealType *, HandleAs *> {
142 const int id = qMetaTypeId<RealType *>();
143 return doRegister<RealType *, HandleAs *>(id);
186 MetaType::internalLock();
188 const int id = InternalRegisterType<RealType, HandleAs>::doReg();
190 MetaType::internalUnlock();
204 return registerMetaType<Type, Type>();
215 #define GRANTLEE_BEGIN_LOOKUP(Type) \ 219 inline QVariant TypeAccessor<Type &>::lookUp(const Type &object, \ 220 const QString &property) \ 228 #define GRANTLEE_BEGIN_LOOKUP_PTR(Type) \ 232 inline QVariant TypeAccessor<Type *>::lookUp(const Type *const object, \ 233 const QString &property) \ 241 #define GRANTLEE_END_LOOKUP \ 246 #endif // #define GRANTLEE_METATYPE_H int registerMetaType()
Registers the type RealType with the metatype system.
The Grantlee namespace holds all public Grantlee API.