swift
Loading...
Searching...
No Matches
mixinmetatype.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (C) 2013 swift Project Community / Contributors
2// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3
5
6#ifndef SWIFT_MISC_MIXIN_MIXINMETATYPE_H
7#define SWIFT_MISC_MIXIN_MIXINMETATYPE_H
8
9#include <QMetaType>
10#include <QString>
11#include <QtGlobal>
12
15#include "misc/variant.h"
16
17namespace swift::misc::mixin
18{
25 template <class Derived>
27 {
28 public:
30 static void registerMetadata();
31
35 int getMetaTypeId() const;
36
39
42 bool isA(int metaTypeId) const;
43
44 private:
45 const Derived *derived() const;
46 Derived *derived();
47
48 template <typename Base2>
49 static bool baseIsA(const Base2 *base, int metaTypeId);
50 static bool baseIsA(const void *, int);
51 };
52
53 template <class Derived>
55 {
56 private_ns::MetaTypeHelper<Derived>::maybeRegisterMetaType();
57 }
58
59 template <class Derived>
61 {
62 return private_ns::MetaTypeHelper<Derived>::maybeGetMetaTypeId();
63 }
64
65 template <class Derived>
70
71 template <class Derived>
72 bool MetaType<Derived>::isA(int metaTypeId) const
73 {
74 if (metaTypeId == QMetaType::UnknownType)
75 {
76 return false;
77 }
78 if (metaTypeId == getMetaTypeId())
79 {
80 return true;
81 }
82 return baseIsA(static_cast<const TMetaBaseOfT<Derived> *>(derived()), metaTypeId);
83 }
84
85 template <class Derived>
86 const Derived *MetaType<Derived>::derived() const
87 {
88 return static_cast<const Derived *>(this);
89 }
90
91 template <class Derived>
92 Derived *MetaType<Derived>::derived()
93 {
94 return static_cast<Derived *>(this);
95 }
96
97 template <class Derived>
98 template <typename Base2>
99 bool MetaType<Derived>::baseIsA(const Base2 *base, int metaTypeId)
100 {
101 return base->isA(metaTypeId);
102 }
103
104 template <class Derived>
105 bool MetaType<Derived>::baseIsA(const void *, int)
106 {
107 return false;
108 }
109
114#define SWIFT_MISC_DECLARE_USING_MIXIN_METATYPE(DERIVED) \
115 using ::swift::misc::mixin::MetaType<DERIVED>::registerMetadata; \
116 using ::swift::misc::mixin::MetaType<DERIVED>::getMetaTypeId; \
117 using ::swift::misc::mixin::MetaType<DERIVED>::getClassName; \
118 using ::swift::misc::mixin::MetaType<DERIVED>::isA;
119
120} // namespace swift::misc::mixin
121
122#endif // SWIFT_MISC_MIXIN_MIXINMETATYPE_H
CRTP class template from which a derived class can inherit common methods dealing with the metatype o...
int getMetaTypeId() const
Returns the Qt meta type ID of this object.
QString getClassName() const
Class name.
bool isA(int metaTypeId) const
Returns true if this object is an instance of the class with the given meta type ID,...
static void registerMetadata()
Register metadata.
Mixin classes which implement common operations for value classes.
typename TMetaBaseOf< T >::type TMetaBaseOfT
Alias for typename TMetaBaseOf<T>::type.
const char * name() const const