File indexing completed on 2025-02-09 04:28:37
0001 /* 0002 This file is part of the KTextTemplate library 0003 0004 SPDX-FileCopyrightText: 2010 Michael Jansen <kde@michael-jansen.biz> 0005 SPDX-FileCopyrightText: 2010 Stephen Kelly <steveire@gmail.com> 0006 0007 SPDX-License-Identifier: LGPL-2.1-or-later 0008 0009 */ 0010 0011 #ifndef CUSTOMTYPESREGISTRY_P_H 0012 #define CUSTOMTYPESREGISTRY_P_H 0013 0014 #include "metatype.h" 0015 0016 #include <QMutex> 0017 0018 namespace KTextTemplate 0019 { 0020 0021 struct CustomTypeInfo { 0022 public: 0023 CustomTypeInfo() 0024 : lookupFunction(nullptr) 0025 { 0026 } 0027 0028 KTextTemplate::MetaType::LookupFunction lookupFunction; 0029 }; 0030 0031 struct CustomTypeRegistry { 0032 CustomTypeRegistry(); 0033 0034 void registerLookupOperator(int id, MetaType::LookupFunction f); 0035 0036 template<typename RealType, typename HandleAs> 0037 int registerBuiltInMetatype() 0038 { 0039 QVariant (*lf)(const QVariant &, const QString &) = LookupTrait<RealType &, HandleAs &>::doLookUp; 0040 0041 const int id = qMetaTypeId<RealType>(); 0042 0043 registerLookupOperator(id, reinterpret_cast<MetaType::LookupFunction>(lf)); 0044 0045 return id; 0046 } 0047 0048 template<typename Type> 0049 int registerBuiltInMetatype() 0050 { 0051 return registerBuiltInMetatype<Type, Type>(); 0052 } 0053 0054 QVariant lookup(const QVariant &object, const QString &property) const; 0055 bool lookupAlreadyRegistered(int id) const; 0056 0057 QHash<int, CustomTypeInfo> types; 0058 QMutex mutex; 0059 }; 0060 } 0061 0062 #endif