mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-06 01:45:38 +08:00
refs #881, utility functions for identifier list
This commit is contained in:
committed by
Mathew Sutcliffe
parent
e73c8c4f36
commit
f581a40b75
@@ -23,6 +23,29 @@ namespace BlackMisc
|
||||
|
||||
bool CIdentifierList::containsAnyNotIn(const CIdentifierList &other) const
|
||||
{
|
||||
return containsBy([&other](const CIdentifier &id) { return ! other.contains(id); });
|
||||
return containsBy([&other](const CIdentifier & id) { return ! other.contains(id); });
|
||||
}
|
||||
|
||||
QStringList CIdentifierList::getMachineNames(bool unique, bool sort) const
|
||||
{
|
||||
QStringList codes = this->transform(Predicates::MemberTransform(&CIdentifier::getMachineName));
|
||||
if (sort) { codes.sort(); }
|
||||
if (unique) { codes.removeDuplicates(); }
|
||||
return codes;
|
||||
}
|
||||
|
||||
int CIdentifierList::removeDuplicates()
|
||||
{
|
||||
if (this->size() < 2) { return 0; }
|
||||
CIdentifierList il;
|
||||
for (const CIdentifier &identifier : *this)
|
||||
{
|
||||
if (il.contains(identifier)) continue;
|
||||
il.push_back(identifier);
|
||||
}
|
||||
const int delta = this->size() - il.size();
|
||||
if (delta == 0) { return 0; }
|
||||
*this = il;
|
||||
return delta;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
@@ -42,6 +42,12 @@ namespace BlackMisc
|
||||
|
||||
//! This list contains an identifier which is not contained in other.
|
||||
bool containsAnyNotIn(const CIdentifierList &other) const;
|
||||
|
||||
//! Get machine names
|
||||
QStringList getMachineNames(bool unique = true, bool sort = true) const;
|
||||
|
||||
//! Remove duplicates
|
||||
int removeDuplicates();
|
||||
};
|
||||
} //namespace
|
||||
|
||||
|
||||
Reference in New Issue
Block a user