swift
identifierlist.cpp
1 // SPDX-FileCopyrightText: Copyright (C) 2015 swift Project Community / Contributors
2 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3 
4 #include "misc/identifierlist.h"
5 
6 #include <QStringList>
7 
9 
10 SWIFT_DEFINE_SEQUENCE_MIXINS(swift::misc, CIdentifier, CIdentifierList)
11 
12 namespace swift::misc
13 {
15 
17  {
18  return containsBy([&other](const CIdentifier &id) { return !other.contains(id); });
19  }
20 
22  {
23  CIdentifierList il;
24  for (const CIdentifier &identifier : *this)
25  {
26  bool contained =
27  il.containsBy([=](const CIdentifier &ident) { return identifier.hasSameMachineName(ident); });
28  if (!contained) { il.push_back(identifier); }
29  }
30  return il;
31  }
32 
33  QStringList CIdentifierList::getMachineNames(bool unique, bool sort) const
34  {
36  if (sort) { codes.sort(); }
37  if (unique) { codes.removeDuplicates(); }
38  return codes;
39  }
40 
42  {
43  if (this->size() < 2) { return 0; }
44  CIdentifierList il;
45  for (const CIdentifier &identifier : *this)
46  {
47  if (il.contains(identifier)) continue;
48  il.push_back(identifier);
49  }
50  const int delta = this->size() - il.size();
51  if (delta == 0) { return 0; }
52  *this = il;
53  return delta;
54  }
55 } // namespace swift::misc
Value object encapsulating information identifying a component of a modular distributed swift process...
Definition: identifier.h:29
const QString & getMachineName() const
Machine name.
Definition: identifier.h:103
bool hasSameMachineName(const CIdentifier &other) const
Check if the other identifier has the same machine name.
Definition: identifier.cpp:158
Value object encapsulating a list of object identifiers.
CIdentifierList()=default
Default constructor.
QStringList getMachineNames(bool unique=true, bool sort=true) const
Get machine names.
int removeDuplicates()
Remove duplicates.
CIdentifierList getMachinesUnique() const
Get a list of identifiers reduced to maximum one per machine. If there is more than one per machine,...
bool containsAnyNotIn(const CIdentifierList &other) const
This list contains an identifier which is not contained in other.
bool containsBy(Predicate p) const
Return true if there is an element for which a given predicate returns true.
Definition: range.h:101
bool contains(const T &object) const
Return true if there is an element equal to given object. Uses the most efficient implementation avai...
Definition: range.h:109
auto transform(F function) const
Return a new container generated by applying some transformation function to all elements of this one...
Definition: range.h:403
size_type size() const
Returns number of elements in the sequence.
Definition: sequence.h:273
void push_back(const T &value)
Appends an element at the end of the sequence.
Definition: sequence.h:305
auto MemberTransform(T memberFunc)
Returns a function object that returns the value returned by one of it's argument member functions.
Definition: predicates.h:54
Free functions in swift::misc.
qsizetype removeDuplicates()
void sort(Qt::CaseSensitivity cs)
#define SWIFT_DEFINE_SEQUENCE_MIXINS(Namespace, T, List)
Explicit template definition of mixins for a CSequence subclass.
Definition: sequence.h:63