-
Notifications
You must be signed in to change notification settings - Fork 89
Improve manual implementations of up- and downcasting #1204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1204 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 73 73
Lines 12681 12681
=========================================
Hits 12681 12681 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
d144680
to
6d63031
Compare
eeab59b
to
dee86e9
Compare
dee86e9
to
00886c0
Compare
00886c0
to
311ddd9
Compare
@jnbooth Thank you for the contribution, this is looking good. Regarding the downcasting, I think we can get all those concerns implemented in a sane way with a bit of meta-programming that automatically selects between qobject_cast and dynamic_cast. And keeping static_cast for the special cases is okay, though I think we should add another assertion just out of caution. |
@LeonMatthesKDAB I don't know how to do that kind of metaprogramming. Are there examples of it in the codebase that I could learn from? Alternatively, should I strip down part of this PR so it can be merged without that? |
Add detection whether to use qobject_cast or dynamic_cast via template specialization. Also add additional checks that a static_cast downcast is sane to do (i.e. at least the size of the types must be the same).
@jnbooth This should do it: I pushed this to a branch on my fork (non-qobject-casting) and rebased, feel free to cherry-pick or just use that branch for your PR. My template meta-programming is a bit rusty nowadays, so @ahayzen-kdab please review carefully to check this is sane. |
Any updates on this? I think at minimum it would be good to remove the null pointer returns. |
I don't have approve permissions btw, so it is up to someone else to do that. |
Ah sorry @jnbooth this PR probably lost the race with another approval which outdated the auto-merge, this is an annoying issue with our workflow at the moment 🙄 |
This PR provides some minor improvements to #1159 for the implementations of
Upcast
.downcastPtr
's use ofdynamic_cast
withqobject_cast
, which is much faster and does not require RTTI.Upcast<QVector<QPoint>>
forQPolygon
, replacing the standalone functions previously used forDeref
andDerefMut
.Upcast<QVector<QPointF>>
forQPolygonF
, replacing the standalone functions previously used forDeref
andDerefMut
.Implements¹Upcast<QCoreApplication>
forQGuiApplication
and addsDeref
.Implements¹Upcast<QGuiApplication>
forQApplication
and addsDeref
.Implements¹Deref
forQQmlApplicationEngine
toQQmlEngine
using the existing upcasting implementation.QStringList
's implementation ofUpcast<QList<QString>>
due to a misuse ofdynamic_cast
.¹ Removed in favor of #1202.