mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-30 20:15:35 +08:00
Ref T218, sequence replaceOrAdd overloads
This commit is contained in:
@@ -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()))
|
||||
|
||||
@@ -106,7 +106,7 @@ namespace BlackMisc
|
||||
CUrlList withoutDuplicates;
|
||||
for (const CUrl &url : (*this))
|
||||
{
|
||||
withoutDuplicates.replaceOrAdd(url, url);
|
||||
withoutDuplicates.replaceOrAdd(url);
|
||||
}
|
||||
return withoutDuplicates;
|
||||
}
|
||||
|
||||
@@ -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>)
|
||||
|
||||
Reference in New Issue
Block a user