summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2020-09-14 14:20:37 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2020-10-03 10:53:26 -0700
commit2b557f567a33bb837fe32d611e7929cf2a4c92b2 (patch)
tree9a2ba331626de5af3a264c4a3317145fc7377e55
parentd183e93bad4a281830b65eb2aae87f3e125284df (diff)
downloadsubsurface-2b557f567a33bb837fe32d611e7929cf2a4c92b2.tar.gz
cleanup: hide DiveComputerList implementation details
Remove the declaration of helper functions needed only in core/device.cpp. To this goal, turn the member functions into free functions. Cosmetics: turn the DiveComputer[Node|List] "class"es into "struct"s, since all members were public anyway. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
-rw-r--r--core/device.cpp18
-rw-r--r--core/device.h10
2 files changed, 11 insertions, 17 deletions
diff --git a/core/device.cpp b/core/device.cpp
index a5fa3bc2a..adbaff644 100644
--- a/core/device.cpp
+++ b/core/device.cpp
@@ -240,13 +240,13 @@ bool DiveComputerNode::operator<(const DiveComputerNode &a) const
return std::tie(model, deviceId) < std::tie(a.model, a.deviceId);
}
-const DiveComputerNode *DiveComputerList::getExact(const QString &m, uint32_t d)
+static const DiveComputerNode *getDCExact(const QVector<DiveComputerNode> &dcs, const QString &m, uint32_t d)
{
auto it = std::lower_bound(dcs.begin(), dcs.end(), DiveComputerNode{m, d, {}, {}, {}});
return it != dcs.end() && it->model == m && it->deviceId == d ? &*it : NULL;
}
-const DiveComputerNode *DiveComputerList::get(const QString &m)
+static const DiveComputerNode *getDC(const QVector<DiveComputerNode> &dcs, const QString &m)
{
auto it = std::lower_bound(dcs.begin(), dcs.end(), DiveComputerNode{m, 0, {}, {}, {}});
return it != dcs.end() && it->model == m ? &*it : NULL;
@@ -262,7 +262,7 @@ void DiveComputerNode::showchanges(const QString &n, const QString &s, const QSt
qDebug("new firmware version %s for DC model %s deviceId 0x%x", qPrintable(f), qPrintable(model), deviceId);
}
-void DiveComputerList::addDC(QString m, uint32_t d, QString n, QString s, QString f)
+static void addDC(QVector<DiveComputerNode> &dcs, const QString &m, uint32_t d, const QString &n, const QString &s, const QString &f)
{
if (m.isEmpty() || d == 0)
return;
@@ -285,7 +285,7 @@ void DiveComputerList::addDC(QString m, uint32_t d, QString n, QString s, QStrin
extern "C" void create_device_node(const char *model, uint32_t deviceid, const char *serial, const char *firmware, const char *nickname)
{
- dcList.addDC(model, deviceid, nickname, serial, firmware);
+ addDC(dcList.dcs, model, deviceid, nickname, serial, firmware);
}
extern "C" void clear_device_nodes()
@@ -345,9 +345,9 @@ extern "C" void set_dc_nickname(struct dive *dive)
for_each_dc (dive, dc) {
if (!empty_string(dc->model) && dc->deviceid &&
- !dcList.getExact(dc->model, dc->deviceid)) {
+ !getDCExact(dcList.dcs, dc->model, dc->deviceid)) {
// we don't have this one, yet
- const DiveComputerNode *existNode = dcList.get(dc->model);
+ const DiveComputerNode *existNode = getDC(dcList.dcs, dc->model);
if (existNode) {
// we already have this model but a different deviceid
QString simpleNick(dc->model);
@@ -355,9 +355,9 @@ extern "C" void set_dc_nickname(struct dive *dive)
simpleNick.append(" (unknown deviceid)");
else
simpleNick.append(" (").append(QString::number(dc->deviceid, 16)).append(")");
- dcList.addDC(dc->model, dc->deviceid, simpleNick);
+ addDC(dcList.dcs, dc->model, dc->deviceid, simpleNick, {}, {});
} else {
- dcList.addDC(dc->model, dc->deviceid);
+ addDC(dcList.dcs, dc->model, dc->deviceid, {}, {}, {});
}
}
}
@@ -365,7 +365,7 @@ extern "C" void set_dc_nickname(struct dive *dive)
QString get_dc_nickname(const struct divecomputer *dc)
{
- const DiveComputerNode *existNode = dcList.getExact(dc->model, dc->deviceid);
+ const DiveComputerNode *existNode = getDCExact(dcList.dcs, dc->model, dc->deviceid);
if (existNode && !existNode->nickName.isEmpty())
return existNode->nickName;
diff --git a/core/device.h b/core/device.h
index 4906a2a49..ba2a882ee 100644
--- a/core/device.h
+++ b/core/device.h
@@ -26,8 +26,7 @@ extern void clear_device_nodes();
#include <QString>
#include <QVector>
-class DiveComputerNode {
-public:
+struct DiveComputerNode {
bool operator==(const DiveComputerNode &a) const;
bool operator!=(const DiveComputerNode &a) const;
bool operator<(const DiveComputerNode &a) const;
@@ -39,12 +38,7 @@ public:
QString nickName;
};
-class DiveComputerList {
-public:
- const DiveComputerNode *getExact(const QString &m, uint32_t d);
- const DiveComputerNode *get(const QString &m);
- void addDC(QString m, uint32_t d, QString n = QString(), QString s = QString(), QString f = QString());
-
+struct DiveComputerList {
// Keep the dive computers in a vector sorted by (model, deviceId)
QVector<DiveComputerNode> dcs;
};