Ref T218, sequence replaceOrAdd overloads

This commit is contained in:
Klaus Basan
2018-01-04 21:16:20 +01:00
parent 2c5a6c0a3a
commit fa6f83d87b
3 changed files with 17 additions and 4 deletions

View File

@@ -798,7 +798,7 @@ namespace BlackMisc
CProcessInfo currentProcess = CProcessInfo::currentProcess();
Q_ASSERT(currentProcess.exists());
apps.replaceOrAdd(currentProcess, currentProcess);
apps.replaceOrAdd(currentProcess);
json.insert("apps", apps.toJson());
json.insert("uuid", uuid.toString());
if (!(file.seek(0) && file.resize(0) && file.write(QJsonDocument(json).toJson()) && file.checkedClose()))

View File

@@ -106,7 +106,7 @@ namespace BlackMisc
CUrlList withoutDuplicates;
for (const CUrl &url : (*this))
{
withoutDuplicates.replaceOrAdd(url, url);
withoutDuplicates.replaceOrAdd(url);
}
return withoutDuplicates;
}

View File

@@ -24,7 +24,6 @@
namespace BlackMisc
{
/*!
* Generic sequential container with value semantics.
* \tparam T the type of elements contained.
@@ -351,6 +350,21 @@ namespace BlackMisc
else { push_back(replacement); }
}
//! Replace elements matching the given element. If there is no match, push the new element on the end.
void replaceOrAdd(const T &replacement)
{
this->replaceOrAdd(replacement, replacement);
}
//! Replace or add given elements
void replaceOrAdd(const CSequence<T> &replacements)
{
for (const T &replacement : replacements)
{
this->replaceOrAdd(replacement, replacement);
}
}
//! Replace elements matching a particular key/value pair. If there is no match, push the new element on the end.
//! \param key1 A pointer to a member function of T.
//! \param value1 Will be compared to the return value of key1.
@@ -505,7 +519,6 @@ namespace BlackMisc
private:
QVector<T> m_impl;
};
} //namespace BlackMisc
Q_DECLARE_METATYPE(BlackMisc::CSequence<int>)