diff options
Diffstat (limited to 'sources/shiboken6/ApiExtractor/abstractmetalang_helpers.h')
-rw-r--r-- | sources/shiboken6/ApiExtractor/abstractmetalang_helpers.h | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/sources/shiboken6/ApiExtractor/abstractmetalang_helpers.h b/sources/shiboken6/ApiExtractor/abstractmetalang_helpers.h new file mode 100644 index 000000000..2a053ceaf --- /dev/null +++ b/sources/shiboken6/ApiExtractor/abstractmetalang_helpers.h @@ -0,0 +1,35 @@ +// Copyright (C) 2020 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 + +#ifndef ABSTRACTMETALANG_HELPERS_H +#define ABSTRACTMETALANG_HELPERS_H + +#include "abstractmetalang_typedefs.h" + +template <class MetaClass> +std::shared_ptr<MetaClass> findByName(const QList<std::shared_ptr<MetaClass> > &haystack, + QStringView needle) +{ + for (const auto &c : haystack) { + if (c->name() == needle) + return c; + } + return {}; +} + +// Helper for recursing the base classes of an AbstractMetaClass. +// Returns the class for which the predicate is true. +template <class Predicate> +AbstractMetaClassCPtr recurseClassHierarchy(const AbstractMetaClassCPtr &klass, + Predicate pred) +{ + if (pred(klass)) + return klass; + for (auto base : klass->baseClasses()) { + if (auto r = recurseClassHierarchy(base, pred)) + return r; + } + return {}; +} + +#endif // ABSTRACTMETALANG_HELPERS_H |