1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-26 09:48:45 -05:00

DeviceUserArgs: do not use iterator with QList and removed operator == on DeviceArgs struct

This commit is contained in:
f4exb 2019-06-30 04:20:18 +02:00
parent ae787a2768
commit 19305eeff0
2 changed files with 37 additions and 65 deletions

View File

@ -66,106 +66,71 @@ bool DeviceUserArgs::deserialize(const QByteArray& data)
} }
} }
QList<DeviceUserArgs::Args>::iterator DeviceUserArgs::findDeviceArgs(const QString& id, int sequence)
{
DeviceUserArgs::Args args;
args.m_id = id;
args.m_sequence = sequence;
QList<DeviceUserArgs::Args>::iterator it = m_argsByDevice.begin();
for (; it != m_argsByDevice.end(); ++it)
{
if (*it == args) {
return it;
}
}
}
QString DeviceUserArgs::findUserArgs(const QString& id, int sequence) QString DeviceUserArgs::findUserArgs(const QString& id, int sequence)
{ {
QList<DeviceUserArgs::Args>::iterator it = findDeviceArgs(id, sequence); for (int i = 0; i < m_argsByDevice.size(); i++)
{
if (it != m_argsByDevice.end()) { if ((m_argsByDevice.at(i).m_id == id) && (m_argsByDevice.at(i).m_sequence == sequence)) {
return it->m_args; return m_argsByDevice.at(i).m_args;
} else { }
return "";
} }
return "";
} }
void DeviceUserArgs::addDeviceArgs(const QString& id, int sequence, const QString& deviceArgs) void DeviceUserArgs::addDeviceArgs(const QString& id, int sequence, const QString& deviceArgs)
{ {
Args args; int i = 0;
args.m_id = id;
args.m_sequence = sequence;
args.m_args = deviceArgs;
QList<DeviceUserArgs::Args>::iterator it = m_argsByDevice.begin(); for (; i < m_argsByDevice.size(); i++)
for (; it != m_argsByDevice.end(); ++it)
{ {
if (*it == args) { if ((m_argsByDevice.at(i).m_id == id) && (m_argsByDevice.at(i).m_sequence == sequence)) {
break; break;
} }
} }
if (it == m_argsByDevice.end()) { if (i == m_argsByDevice.size()) {
m_argsByDevice.push_back(args); m_argsByDevice.push_back(Args(id, sequence, deviceArgs));
} }
} }
void DeviceUserArgs::addOrUpdateDeviceArgs(const QString& id, int sequence, const QString& deviceArgs) void DeviceUserArgs::addOrUpdateDeviceArgs(const QString& id, int sequence, const QString& deviceArgs)
{ {
Args args; int i = 0;
args.m_id = id;
args.m_sequence = sequence;
args.m_args = deviceArgs;
QList<DeviceUserArgs::Args>::iterator it = m_argsByDevice.begin(); for (; i < m_argsByDevice.size(); i++)
for (; it != m_argsByDevice.end(); ++it)
{ {
if (*it == args) if ((m_argsByDevice.at(i).m_id == id) && (m_argsByDevice.at(i).m_sequence == sequence)) {
{ m_argsByDevice[i].m_args = deviceArgs;
it->m_args = deviceArgs;
return;
} }
} }
if (it == m_argsByDevice.end()) { if (i == m_argsByDevice.size()) {
m_argsByDevice.push_back(args); m_argsByDevice.push_back(Args(id, sequence, deviceArgs));
} }
} }
void DeviceUserArgs::updateDeviceArgs(const QString& id, int sequence, const QString& deviceArgs) void DeviceUserArgs::updateDeviceArgs(const QString& id, int sequence, const QString& deviceArgs)
{ {
Args args; int i = 0;
args.m_id = id;
args.m_sequence = sequence;
QList<DeviceUserArgs::Args>::iterator it = m_argsByDevice.begin(); for (; i < m_argsByDevice.size(); i++)
for (; it != m_argsByDevice.end(); ++it)
{ {
if (*it == args) if ((m_argsByDevice.at(i).m_id == id) && (m_argsByDevice.at(i).m_sequence == sequence)) {
{ m_argsByDevice[i].m_args = deviceArgs;
it->m_args = deviceArgs;
} }
} }
} }
void DeviceUserArgs::deleteDeviceArgs(const QString& id, int sequence) void DeviceUserArgs::deleteDeviceArgs(const QString& id, int sequence)
{ {
Args args; int i = 0;
args.m_id = id;
args.m_sequence = sequence;
QList<DeviceUserArgs::Args>::iterator it = m_argsByDevice.begin(); for (; i < m_argsByDevice.size(); i++)
for (; it != m_argsByDevice.end(); ++it)
{ {
if (*it == args) if ((m_argsByDevice.at(i).m_id == id) && (m_argsByDevice.at(i).m_sequence == sequence))
{ {
m_argsByDevice.erase(it); m_argsByDevice.takeAt(i);
return; return;
} }
} }

View File

@ -32,9 +32,17 @@ public:
int m_sequence; int m_sequence;
QString m_args; QString m_args;
bool operator==(const Args& rhs) { //!< reference equality Args() :
return (m_id == rhs.m_id) && (m_sequence == rhs.m_sequence); m_id(""),
} m_sequence(0),
m_args("")
{}
Args(const QString id, int sequence, const QString& args) :
m_id(id),
m_sequence(sequence),
m_args(args)
{}
friend QDataStream &operator << (QDataStream &ds, const Args &inObj); friend QDataStream &operator << (QDataStream &ds, const Args &inObj);
friend QDataStream &operator >> (QDataStream &ds, Args &outObj); friend QDataStream &operator >> (QDataStream &ds, Args &outObj);
@ -42,7 +50,6 @@ public:
QByteArray serialize() const; QByteArray serialize() const;
bool deserialize(const QByteArray& data); bool deserialize(const QByteArray& data);
QList<Args>::iterator findDeviceArgs(const QString& id, int sequence);
QString findUserArgs(const QString& id, int sequence); QString findUserArgs(const QString& id, int sequence);
void addDeviceArgs(const QString& id, int sequence, const QString& args); //!< Will not add if it exists for same reference void addDeviceArgs(const QString& id, int sequence, const QString& args); //!< Will not add if it exists for same reference
void addOrUpdateDeviceArgs(const QString& id, int sequence, const QString& args); //!< Add or update if it exists for same reference void addOrUpdateDeviceArgs(const QString& id, int sequence, const QString& args); //!< Add or update if it exists for same reference