diff options
Diffstat (limited to 'src/gui/kernel/qplatformintegration.h')
-rw-r--r-- | src/gui/kernel/qplatformintegration.h | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/gui/kernel/qplatformintegration.h b/src/gui/kernel/qplatformintegration.h index 01406958e2..23e868180f 100644 --- a/src/gui/kernel/qplatformintegration.h +++ b/src/gui/kernel/qplatformintegration.h @@ -81,6 +81,30 @@ class QOffscreenSurface; class QPlatformVulkanInstance; class QVulkanInstance; +namespace QPlatformInterface::Private { + +template <typename R, typename I, auto func, typename... Args> +struct QInterfaceProxyImp +{ + template <typename T> + static R apply(T *obj, Args... args) + { + if (auto *iface = dynamic_cast<I*>(obj)) + return (iface->*func)(args...); + else + return R(); + } +}; + +template <auto func> +struct QInterfaceProxy; +template <typename R, typename I, typename... Args, R(I::*func)(Args...)> +struct QInterfaceProxy<func> : public QInterfaceProxyImp<R, I, func, Args...> {}; +template <typename R, typename I, typename... Args, R(I::*func)(Args...) const> +struct QInterfaceProxy<func> : public QInterfaceProxyImp<R, I, func, Args...> {}; + +} // QPlatformInterface::Private + class Q_GUI_EXPORT QPlatformIntegration { public: @@ -200,6 +224,13 @@ public: virtual QPlatformVulkanInstance *createPlatformVulkanInstance(QVulkanInstance *instance) const; #endif + template <auto func, typename... Args> + auto call(Args... args) + { + using namespace QPlatformInterface::Private; + return QInterfaceProxy<func>::apply(this, args...); + } + protected: QPlatformIntegration() = default; }; |