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 
19  {
20  return containsBy([&other](const CIdentifier &id) { return !other.contains(id); });
21  }
22 
24  {
25  CIdentifierList il;
26  for (const CIdentifier &identifier : *this)
27  {
28  bool contained =
29  il.containsBy([=](const CIdentifier &ident) { return identifier.hasSameMachineName(ident); });
30  if (!contained) { il.push_back(identifier); }
31  }
32  return il;
33  }
34 
35  QStringList CIdentifierList::getMachineNames(bool unique, bool sort) const
36  {
38  if (sort) { codes.sort(); }
39  if (unique) { codes.removeDuplicates(); }
40  return codes;
41  }
42 
44  {
45  if (this->size() < 2) { return 0; }
46  CIdentifierList il;
47  for (const CIdentifier &identifier : *this)
48  {
49  if (il.contains(identifier)) continue;
50  il.push_back(identifier);
51  }
52  const int delta = this->size() - il.size();
53  if (delta == 0) { return 0; }
54  *this = il;
55  return delta;
56  }
57 } // 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 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.
#define SWIFT_DEFINE_SEQUENCE_MIXINS(Namespace, T, List)
Explicit template definition of mixins for a CSequence subclass.
Definition: sequence.h:63