diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2018-08-02 13:10:38 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2018-08-03 14:29:22 +0000 |
commit | 711515d089574cdc8be63c65d6b01863aadba141 (patch) | |
tree | 3e9ea0ad7ec2da8c94e6b91862d4e7b2670ce863 /sources/shiboken2/ApiExtractor/abstractmetalang.cpp | |
parent | 138815277a415595c669793383c2a4fc8c44d132 (diff) |
shiboken: Refactor code involved in inheriting template classes
- Add a helper template to conveniently search for a MetaClass by name
and convenience function to search in lists.
- Remove parameter bool *ok from
AbstractMetaBuilderPrivate::inheritTemplateType() and check on returned
pointer instead.
- In the inheritTemplate*() functions, use QScopedPointer to ensure
the result is deleted on failure.
- Search for a shadowing function first before creating the copy
in inheritTemplate().
Task-number: PYSIDE-725
Change-Id: I3183087fb42b22a2189c17b94eaafdb4c1151f0e
Reviewed-by: Christian Tismer <tismer@stackless.com>
Diffstat (limited to 'sources/shiboken2/ApiExtractor/abstractmetalang.cpp')
-rw-r--r-- | sources/shiboken2/ApiExtractor/abstractmetalang.cpp | 38 |
1 files changed, 29 insertions, 9 deletions
diff --git a/sources/shiboken2/ApiExtractor/abstractmetalang.cpp b/sources/shiboken2/ApiExtractor/abstractmetalang.cpp index 69a1390dc..e9069277a 100644 --- a/sources/shiboken2/ApiExtractor/abstractmetalang.cpp +++ b/sources/shiboken2/ApiExtractor/abstractmetalang.cpp @@ -57,6 +57,16 @@ QDebug operator<<(QDebug d, const AbstractMetaAttributes *aa) } #endif // !QT_NO_DEBUG_STREAM +template <class MetaClass> +MetaClass *findByName(QVector<MetaClass *> haystack, QStringView needle) +{ + for (MetaClass *c : haystack) { + if (c->name() == needle) + return c; + } + return nullptr; +} + /******************************************************************************* * AbstractMetaVariable */ @@ -1117,6 +1127,13 @@ bool function_sorter(AbstractMetaFunction *a, AbstractMetaFunction *b) return a->signature() < b->signature(); } +AbstractMetaFunction * +AbstractMetaFunction::find(const AbstractMetaFunctionList &haystack, + const QString &needle) +{ + return findByName(haystack, needle); +} + #ifndef QT_NO_DEBUG_STREAM static inline void formatMetaFunctionBrief(QDebug &d, const AbstractMetaFunction *af) { @@ -1513,11 +1530,7 @@ bool AbstractMetaClass::hasFunction(const QString &str) const const AbstractMetaFunction* AbstractMetaClass::findFunction(const QString& functionName) const { - for (const AbstractMetaFunction *f : m_functions) { - if (f->name() == functionName) - return f; - } - return 0; + return AbstractMetaFunction::find(m_functions, functionName); } bool AbstractMetaClass::hasProtectedFunctions() const @@ -1618,6 +1631,11 @@ AbstractMetaField *AbstractMetaField::copy() const return returned; } +AbstractMetaField *AbstractMetaField::find(const AbstractMetaFieldList &haystack, + const QString &needle) +{ + return findByName(haystack, needle); +} /******************************************************************************* * Indicates that this field has a modification that removes it */ @@ -2013,13 +2031,15 @@ void AbstractMetaClass::setInterfaces(const AbstractMetaClassList &interfaces) } } +AbstractMetaField *AbstractMetaClass::findField(const QString &name) const +{ + return AbstractMetaField::find(m_fields, name); +} AbstractMetaEnum *AbstractMetaClass::findEnum(const QString &enumName) { - for (AbstractMetaEnum *e : qAsConst(m_enums)) { - if (e->name() == enumName) - return e; - } + if (AbstractMetaEnum *e = findByName(m_enums, enumName)) + return e; if (typeEntry()->designatedInterface()) return extractInterface()->findEnum(enumName); |