1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-22 16:08:39 -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)
{
QList<DeviceUserArgs::Args>::iterator it = findDeviceArgs(id, sequence);
if (it != m_argsByDevice.end()) {
return it->m_args;
} else {
return "";
for (int i = 0; i < m_argsByDevice.size(); i++)
{
if ((m_argsByDevice.at(i).m_id == id) && (m_argsByDevice.at(i).m_sequence == sequence)) {
return m_argsByDevice.at(i).m_args;
}
}
return "";
}
void DeviceUserArgs::addDeviceArgs(const QString& id, int sequence, const QString& deviceArgs)
{
Args args;
args.m_id = id;
args.m_sequence = sequence;
args.m_args = deviceArgs;
int i = 0;
QList<DeviceUserArgs::Args>::iterator it = m_argsByDevice.begin();
for (; it != m_argsByDevice.end(); ++it)
for (; i < m_argsByDevice.size(); i++)
{
if (*it == args) {
if ((m_argsByDevice.at(i).m_id == id) && (m_argsByDevice.at(i).m_sequence == sequence)) {
break;
}
}
if (it == m_argsByDevice.end()) {
m_argsByDevice.push_back(args);
if (i == m_argsByDevice.size()) {
m_argsByDevice.push_back(Args(id, sequence, deviceArgs));
}
}
void DeviceUserArgs::addOrUpdateDeviceArgs(const QString& id, int sequence, const QString& deviceArgs)
{
Args args;
args.m_id = id;
args.m_sequence = sequence;
args.m_args = deviceArgs;
int i = 0;
QList<DeviceUserArgs::Args>::iterator it = m_argsByDevice.begin();
for (; it != m_argsByDevice.end(); ++it)
for (; i < m_argsByDevice.size(); i++)
{
if (*it == args)
{
it->m_args = deviceArgs;
return;
if ((m_argsByDevice.at(i).m_id == id) && (m_argsByDevice.at(i).m_sequence == sequence)) {
m_argsByDevice[i].m_args = deviceArgs;
}
}
if (it == m_argsByDevice.end()) {
m_argsByDevice.push_back(args);
if (i == m_argsByDevice.size()) {
m_argsByDevice.push_back(Args(id, sequence, deviceArgs));
}
}
void DeviceUserArgs::updateDeviceArgs(const QString& id, int sequence, const QString& deviceArgs)
{
Args args;
args.m_id = id;
args.m_sequence = sequence;
int i = 0;
QList<DeviceUserArgs::Args>::iterator it = m_argsByDevice.begin();
for (; it != m_argsByDevice.end(); ++it)
for (; i < m_argsByDevice.size(); i++)
{
if (*it == args)
{
it->m_args = deviceArgs;
if ((m_argsByDevice.at(i).m_id == id) && (m_argsByDevice.at(i).m_sequence == sequence)) {
m_argsByDevice[i].m_args = deviceArgs;
}
}
}
void DeviceUserArgs::deleteDeviceArgs(const QString& id, int sequence)
{
Args args;
args.m_id = id;
args.m_sequence = sequence;
int i = 0;
QList<DeviceUserArgs::Args>::iterator it = m_argsByDevice.begin();
for (; it != m_argsByDevice.end(); ++it)
for (; i < m_argsByDevice.size(); i++)
{
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;
}
}

View File

@ -32,9 +32,17 @@ public:
int m_sequence;
QString m_args;
bool operator==(const Args& rhs) { //!< reference equality
return (m_id == rhs.m_id) && (m_sequence == rhs.m_sequence);
}
Args() :
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, Args &outObj);
@ -42,7 +50,6 @@ public:
QByteArray serialize() const;
bool deserialize(const QByteArray& data);
QList<Args>::iterator findDeviceArgs(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 addOrUpdateDeviceArgs(const QString& id, int sequence, const QString& args); //!< Add or update if it exists for same reference