mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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>
This commit is contained in:
parent
d183e93bad
commit
2b557f567a
2 changed files with 11 additions and 17 deletions
|
@ -240,13 +240,13 @@ bool DiveComputerNode::operator<(const DiveComputerNode &a) const
|
||||||
return std::tie(model, deviceId) < std::tie(a.model, a.deviceId);
|
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, {}, {}, {}});
|
auto it = std::lower_bound(dcs.begin(), dcs.end(), DiveComputerNode{m, d, {}, {}, {}});
|
||||||
return it != dcs.end() && it->model == m && it->deviceId == d ? &*it : NULL;
|
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, {}, {}, {}});
|
auto it = std::lower_bound(dcs.begin(), dcs.end(), DiveComputerNode{m, 0, {}, {}, {}});
|
||||||
return it != dcs.end() && it->model == m ? &*it : NULL;
|
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);
|
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)
|
if (m.isEmpty() || d == 0)
|
||||||
return;
|
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)
|
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()
|
extern "C" void clear_device_nodes()
|
||||||
|
@ -345,9 +345,9 @@ extern "C" void set_dc_nickname(struct dive *dive)
|
||||||
|
|
||||||
for_each_dc (dive, dc) {
|
for_each_dc (dive, dc) {
|
||||||
if (!empty_string(dc->model) && dc->deviceid &&
|
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
|
// we don't have this one, yet
|
||||||
const DiveComputerNode *existNode = dcList.get(dc->model);
|
const DiveComputerNode *existNode = getDC(dcList.dcs, dc->model);
|
||||||
if (existNode) {
|
if (existNode) {
|
||||||
// we already have this model but a different deviceid
|
// we already have this model but a different deviceid
|
||||||
QString simpleNick(dc->model);
|
QString simpleNick(dc->model);
|
||||||
|
@ -355,9 +355,9 @@ extern "C" void set_dc_nickname(struct dive *dive)
|
||||||
simpleNick.append(" (unknown deviceid)");
|
simpleNick.append(" (unknown deviceid)");
|
||||||
else
|
else
|
||||||
simpleNick.append(" (").append(QString::number(dc->deviceid, 16)).append(")");
|
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 {
|
} 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)
|
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())
|
if (existNode && !existNode->nickName.isEmpty())
|
||||||
return existNode->nickName;
|
return existNode->nickName;
|
||||||
|
|
|
@ -26,8 +26,7 @@ extern void clear_device_nodes();
|
||||||
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
class DiveComputerNode {
|
struct DiveComputerNode {
|
||||||
public:
|
|
||||||
bool operator==(const DiveComputerNode &a) const;
|
bool operator==(const DiveComputerNode &a) const;
|
||||||
bool operator!=(const DiveComputerNode &a) const;
|
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;
|
QString nickName;
|
||||||
};
|
};
|
||||||
|
|
||||||
class DiveComputerList {
|
struct 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());
|
|
||||||
|
|
||||||
// Keep the dive computers in a vector sorted by (model, deviceId)
|
// Keep the dive computers in a vector sorted by (model, deviceId)
|
||||||
QVector<DiveComputerNode> dcs;
|
QVector<DiveComputerNode> dcs;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue