refs #881, utility functions for identifier list

This commit is contained in:
Klaus Basan
2017-02-13 17:06:53 +01:00
committed by Mathew Sutcliffe
parent e73c8c4f36
commit f581a40b75
2 changed files with 30 additions and 1 deletions

View File

@@ -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

View File

@@ -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