22 #ifndef GRANTLEE_METATYPE_H 23 #define GRANTLEE_METATYPE_H 25 #include "grantlee_templates_export.h" 29 #include <QtCore/QVariant> 50 class GRANTLEE_TEMPLATES_EXPORT MetaType
56 typedef QVariant (*LookupFunction)(
const QVariant &,
const QString &);
61 static void registerLookUpOperator(
int id, LookupFunction f);
66 static void internalLock();
71 static void internalUnlock();
76 static QVariant lookup(
const QVariant &
object,
const QString &property);
81 static bool lookupAlreadyRegistered(
int id);
94 template <
typename RealType,
typename HandleAs>
struct LookupTrait {
95 static QVariant doLookUp(
const QVariant &
object,
const QString &property)
97 typedef typename Grantlee::TypeAccessor<RealType> Accessor;
98 return Accessor::lookUp(
object.value<RealType>(), property);
102 template <
typename RealType,
typename HandleAs>
103 struct LookupTrait<RealType &, HandleAs &> {
104 static QVariant doLookUp(
const QVariant &
object,
const QString &property)
106 typedef typename Grantlee::TypeAccessor<HandleAs &> Accessor;
107 return Accessor::lookUp(
object.value<HandleAs>(), property);
111 template <
typename RealType,
typename HandleAs>
static int doRegister(
int id)
113 if (MetaType::lookupAlreadyRegistered(
id))
116 QVariant (*lf)(
const QVariant &,
const QString &)
117 = LookupTrait<RealType, HandleAs>::doLookUp;
119 MetaType::registerLookUpOperator(
120 id, reinterpret_cast<MetaType::LookupFunction>(lf));
128 template <
typename RealType,
typename HandleAs>
struct InternalRegisterType {
131 const int id = qMetaTypeId<RealType>();
132 return doRegister<RealType &, HandleAs &>(id);
136 template <
typename RealType,
typename HandleAs>
137 struct 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 GRANTLEE_BEGIN_LOOKUP(Type) \ 217 inline QVariant TypeAccessor<Type &>::lookUp(const Type &object, \ 218 const QString &property) \ 226 #define GRANTLEE_BEGIN_LOOKUP_PTR(Type) \ 230 inline QVariant TypeAccessor<Type *>::lookUp(const Type *const object, \ 231 const QString &property) \ 239 #define GRANTLEE_END_LOOKUP \ 244 #endif // #define GRANTLEE_METATYPE_H int registerMetaType()
Registers the type RealType with the metatype system.
The Grantlee namespace holds all public Grantlee API.