From 6f6b35df505af108669bd6ff8c351c970130eb45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ingo=20Kl=C3=B6cker?= Date: Mon, 19 Jun 2023 12:11:58 +0200 Subject: [PATCH] qt: Return const pointer to JobPrivate class for const pointer to Job * lang/qt/src/job.cpp, lang/qt/src/job_p.h (getJobPrivate): Replace with two overloads for non-const pointer and const pointer to Job. * lang/qt/src/job_p.h (jobPrivate): Replace with two template functions for non-const pointer and const pointer to Job. -- This helps avoid changing values stored in the JobPrivate class in const functions (e.g. getters) of Job classes. GnuPG-bug-id: 6530 --- lang/qt/src/job.cpp | 7 ++++++- lang/qt/src/job_p.h | 12 ++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/lang/qt/src/job.cpp b/lang/qt/src/job.cpp index 85de2ce7..5e07f787 100644 --- a/lang/qt/src/job.cpp +++ b/lang/qt/src/job.cpp @@ -94,7 +94,12 @@ void QGpgME::setJobPrivate(const Job *job, std::unique_ptr d) ref = std::move(d); } -QGpgME::JobPrivate *QGpgME::getJobPrivate(const Job *job) +const QGpgME::JobPrivate *QGpgME::getJobPrivate(const Job *job) +{ + return d_func()->operator[](job).get(); +} + +QGpgME::JobPrivate *QGpgME::getJobPrivate(Job *job) { return d_func()->operator[](job).get(); } diff --git a/lang/qt/src/job_p.h b/lang/qt/src/job_p.h index 7d0f9952..43063dd1 100644 --- a/lang/qt/src/job_p.h +++ b/lang/qt/src/job_p.h @@ -56,10 +56,18 @@ public: // BCI: Add a real d-pointer to Job void setJobPrivate(const Job *job, std::unique_ptr d); -JobPrivate *getJobPrivate(const Job *job); +const JobPrivate *getJobPrivate(const Job *job); + +JobPrivate *getJobPrivate(Job *job); template -static T *jobPrivate(const Job *job) { +static const T *jobPrivate(const Job *job) { + auto d = getJobPrivate(job); + return dynamic_cast(d); +} + +template +static T *jobPrivate(Job *job) { auto d = getJobPrivate(job); return dynamic_cast(d); }