From f4103e4998d0a2512b6b8db931a81911b3e908a0 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Tue, 29 Dec 2020 22:39:12 +0100 Subject: cleanup: const-ify DivePlotDataModel::*max() functions These functions return the maximum partial pressures in the given dive. Obviously, being pure accessors, they should be const. This commit also replaces the macro generating these functions by a call to a function taking a pointer-to-member. Arguably, C++'s pointer-to-member syntax is just as horrible as macros, but at least it doesn't mess with syntax highlighting of my editor and should be better to debug. Signed-off-by: Berthold Stoeger --- qt-models/diveplotdatamodel.cpp | 34 ++++++++++++++++++++++------------ qt-models/diveplotdatamodel.h | 6 +++--- 2 files changed, 25 insertions(+), 15 deletions(-) (limited to 'qt-models') diff --git a/qt-models/diveplotdatamodel.cpp b/qt-models/diveplotdatamodel.cpp index 538771331..6c008139e 100644 --- a/qt-models/diveplotdatamodel.cpp +++ b/qt-models/diveplotdatamodel.cpp @@ -199,20 +199,30 @@ unsigned int DivePlotDataModel::dcShown() const return dcNr; } -#define MAX_PPGAS_FUNC(GAS, GASFUNC) \ - double DivePlotDataModel::GASFUNC() \ - { \ - double ret = -1; \ - for (int i = 0, count = rowCount(); i < count; i++) { \ - if (pInfo.entry[i].pressures.GAS > ret) \ - ret = pInfo.entry[i].pressures.GAS; \ - } \ - return ret; \ +static double max_gas(const plot_info &pi, double gas_pressures::*gas) +{ + double ret = -1; + for (int i = 0; i < pi.nr; ++i) { + if (pi.entry[i].pressures.*gas > ret) + ret = pi.entry[i].pressures.*gas; } + return ret; +} + +double DivePlotDataModel::pheMax() const +{ + return max_gas(pInfo, &gas_pressures::he); +} -MAX_PPGAS_FUNC(he, pheMax); -MAX_PPGAS_FUNC(n2, pn2Max); -MAX_PPGAS_FUNC(o2, po2Max); +double DivePlotDataModel::pn2Max() const +{ + return max_gas(pInfo, &gas_pressures::n2); +} + +double DivePlotDataModel::po2Max() const +{ + return max_gas(pInfo, &gas_pressures::o2); +} void DivePlotDataModel::emitDataChanged() { diff --git a/qt-models/diveplotdatamodel.h b/qt-models/diveplotdatamodel.h index d034a62b3..36b41ac56 100644 --- a/qt-models/diveplotdatamodel.h +++ b/qt-models/diveplotdatamodel.h @@ -82,9 +82,9 @@ public: void setDive(struct dive *d, const plot_info &pInfo); const plot_info &data() const; unsigned int dcShown() const; - double pheMax(); - double pn2Max(); - double po2Max(); + double pheMax() const; + double pn2Max() const; + double po2Max() const; void emitDataChanged(); private: -- cgit v1.2.3-70-g09d2