aboutsummaryrefslogtreecommitdiffstats
path: root/core/divecomputer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/divecomputer.cpp')
-rw-r--r--core/divecomputer.cpp70
1 files changed, 31 insertions, 39 deletions
diff --git a/core/divecomputer.cpp b/core/divecomputer.cpp
index 79edfc494..e9de3f64b 100644
--- a/core/divecomputer.cpp
+++ b/core/divecomputer.cpp
@@ -19,6 +19,11 @@ bool DiveComputerNode::operator!=(const DiveComputerNode &a) const
return !(*this == a);
}
+bool DiveComputerNode::operator<(const DiveComputerNode &a) const
+{
+ return std::tie(model, deviceId) < std::tie(a.model, a.deviceId);
+}
+
bool DiveComputerNode::changesValues(const DiveComputerNode &b) const
{
if (model != b.model || deviceId != b.deviceId) {
@@ -32,27 +37,23 @@ bool DiveComputerNode::changesValues(const DiveComputerNode &b) const
const DiveComputerNode *DiveComputerList::getExact(const QString &m, uint32_t d)
{
- for (QMap<QString, DiveComputerNode>::iterator it = dcMap.find(m); it != dcMap.end() && it.key() == m; ++it)
- if (it->deviceId == d)
- return &*it;
- return NULL;
+ 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)
{
- QMap<QString, DiveComputerNode>::iterator it = dcMap.find(m);
- if (it != dcMap.end())
- return &*it;
- return NULL;
+ auto it = std::lower_bound(dcs.begin(), dcs.end(), DiveComputerNode { m, 0 , {}, {}, {} } );
+ return it != dcs.end() && it->model == m ? &*it : NULL;
}
void DiveComputerNode::showchanges(const QString &n, const QString &s, const QString &f) const
{
- if (nickName != n)
+ if (nickName != n && !n.isEmpty())
qDebug("new nickname %s for DC model %s deviceId 0x%x", qPrintable(n), qPrintable(model), deviceId);
- if (serialNumber != s)
+ if (serialNumber != s && !s.isEmpty())
qDebug("new serial number %s for DC model %s deviceId 0x%x", qPrintable(s), qPrintable(model), deviceId);
- if (firmware != f)
+ if (firmware != f && !f.isEmpty())
qDebug("new firmware version %s for DC model %s deviceId 0x%x", qPrintable(f), qPrintable(model), deviceId);
}
@@ -60,28 +61,21 @@ void DiveComputerList::addDC(QString m, uint32_t d, QString n, QString s, QStrin
{
if (m.isEmpty() || d == 0)
return;
- const DiveComputerNode *existNode = this->getExact(m, d);
-
- if (existNode) {
- // Update any non-existent fields from the old entry
- if (n.isEmpty())
- n = existNode->nickName;
- if (s.isEmpty())
- s = existNode->serialNumber;
- if (f.isEmpty())
- f = existNode->firmware;
-
- // Do all the old values match?
- if (n == existNode->nickName && s == existNode->serialNumber && f == existNode->firmware)
- return;
-
+ auto it = std::lower_bound(dcs.begin(), dcs.end(), DiveComputerNode { m, d , {}, {}, {} } );
+ if (it != dcs.end() && it->model == m && it->deviceId == d) {
// debugging: show changes
if (verbose)
- existNode->showchanges(n, s, f);
- dcMap.remove(m, *existNode);
+ it->showchanges(n, s, f);
+ // Update any non-existent fields from the old entry
+ if (!n.isEmpty())
+ it->nickName = n;
+ if (!s.isEmpty())
+ it->serialNumber = s;
+ if (!f.isEmpty())
+ it->firmware = f;
+ } else {
+ dcs.insert(it, DiveComputerNode { m, d, s, f, n });
}
-
- dcMap.insert(m, { m, d, s, f, n });
}
extern "C" void create_device_node(const char *model, uint32_t deviceid, const char *serial, const char *firmware, const char *nickname)
@@ -89,7 +83,7 @@ extern "C" void create_device_node(const char *model, uint32_t deviceid, const c
dcList.addDC(model, deviceid, nickname, serial, firmware);
}
-extern "C" bool compareDC(const DiveComputerNode &a, const DiveComputerNode &b)
+static bool compareDCById(const DiveComputerNode &a, const DiveComputerNode &b)
{
return a.deviceId < b.deviceId;
}
@@ -98,10 +92,9 @@ extern "C" void call_for_each_dc (void *f, void (*callback)(void *, const char *
const char *, const char *, const char *),
bool select_only)
{
- QList<DiveComputerNode> values = dcList.dcMap.values();
- qSort(values.begin(), values.end(), compareDC);
- for (int i = 0; i < values.size(); i++) {
- const DiveComputerNode *node = &values.at(i);
+ QVector<DiveComputerNode> values = dcList.dcs;
+ std::sort(values.begin(), values.end(), compareDCById);
+ for (const DiveComputerNode &node: values) {
bool found = false;
if (select_only) {
int j;
@@ -111,7 +104,7 @@ extern "C" void call_for_each_dc (void *f, void (*callback)(void *, const char *
if (!d->selected)
continue;
for_each_dc(d, dc) {
- if (dc->deviceid == node->deviceId) {
+ if (dc->deviceid == node.deviceId) {
found = true;
break;
}
@@ -123,12 +116,11 @@ extern "C" void call_for_each_dc (void *f, void (*callback)(void *, const char *
found = true;
}
if (found)
- callback(f, qPrintable(node->model), node->deviceId, qPrintable(node->nickName),
- qPrintable(node->serialNumber), qPrintable(node->firmware));
+ callback(f, qPrintable(node.model), node.deviceId, qPrintable(node.nickName),
+ qPrintable(node.serialNumber), qPrintable(node.firmware));
}
}
-
extern "C" int is_default_dive_computer(const char *vendor, const char *product)
{
auto dc = SettingsObjectWrapper::instance()->dive_computer_settings;