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
This commit is contained in:
Ingo Klöcker 2023-06-19 12:11:58 +02:00
parent 5811d069d3
commit 6f6b35df50
No known key found for this signature in database
GPG Key ID: F5A5D1692277A1E9
2 changed files with 16 additions and 3 deletions

View File

@ -94,7 +94,12 @@ void QGpgME::setJobPrivate(const Job *job, std::unique_ptr<JobPrivate> d)
ref = std::move(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(); return d_func()->operator[](job).get();
} }

View File

@ -56,10 +56,18 @@ public:
// BCI: Add a real d-pointer to Job // BCI: Add a real d-pointer to Job
void setJobPrivate(const Job *job, std::unique_ptr<JobPrivate> d); void setJobPrivate(const Job *job, std::unique_ptr<JobPrivate> d);
JobPrivate *getJobPrivate(const Job *job); const JobPrivate *getJobPrivate(const Job *job);
JobPrivate *getJobPrivate(Job *job);
template <typename T> template <typename T>
static T *jobPrivate(const Job *job) { static const T *jobPrivate(const Job *job) {
auto d = getJobPrivate(job);
return dynamic_cast<const T *>(d);
}
template <typename T>
static T *jobPrivate(Job *job) {
auto d = getJobPrivate(job); auto d = getJobPrivate(job);
return dynamic_cast<T *>(d); return dynamic_cast<T *>(d);
} }