swift
platformset.cpp
1 // SPDX-FileCopyrightText: Copyright (C) 2017 swift Project Community / Contributors
2 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3 
5 
6 #include "misc/platformset.h"
7 
8 #include <QDBusMetaType>
9 #include <QString>
10 
11 #include "misc/containerbase.h"
12 
13 SWIFT_DEFINE_COLLECTION_MIXINS(swift::misc, CPlatform, CPlatformSet)
14 
15 namespace swift::misc
16 {
17  CPlatformSet::CPlatformSet(const CCollection<CPlatform> &other) : CCollection<CPlatform>(other) {}
18 
19  QStringList CPlatformSet::getPlatformNames() const
20  {
21  QStringList names;
22  for (const CPlatform &p : *this) { names.append(p.getPlatformName()); }
23  return names;
24  }
25 
26  CPlatformSet CPlatformSet::matchesAny(CPlatform::Platform platform) const
27  {
28  CPlatformSet set;
29  for (const CPlatform &p : *this)
30  {
31  if (!p.matchesAny(platform)) continue;
32  set.insert(p);
33  }
34  return set;
35  }
36 
37  CPlatformSet CPlatformSet::exactMatch(CPlatform::Platform platform) const
38  {
39  CPlatformSet set;
40  for (const CPlatform &p : *this)
41  {
42  if (p.getPlatform() != platform) continue;
43  set.insert(p);
44  }
45  return set;
46  }
47 
48  bool CPlatformSet::containsName(const QString &platformName) const
49  {
50  return this->contains(&CPlatform::getPlatformName, platformName);
51  }
52 
53  const CPlatformSet &CPlatformSet::allPlatforms()
54  {
55  static const CPlatformSet platforms({ CPlatform::win32Platform(), CPlatform::win64Platform(),
56  CPlatform::linuxPlatform(), CPlatform::macOSPlatform() });
57  return platforms;
58  }
59 
60  void CPlatformSet::registerMetadata()
61  {
62  qRegisterMetaType<swift::misc::CSequence<CPlatform>>();
63  qDBusRegisterMetaType<swift::misc::CSequence<CPlatform>>();
64  qRegisterMetaType<swift::misc::CCollection<CPlatform>>();
65  qDBusRegisterMetaType<swift::misc::CCollection<CPlatform>>();
66  qRegisterMetaType<CPlatformSet>();
67  qDBusRegisterMetaType<CPlatformSet>();
68  registerMetaValueType<CPlatformSet>();
69  }
70 } // namespace swift::misc
71 
CPlatformSet()=default
Default constructor.
#define SWIFT_DEFINE_COLLECTION_MIXINS(Namespace, T, Set)
Explicit template definition of mixins for a CCollection subclass.
Definition: collection.h:63
Free functions in swift::misc.
void append(QList< T > &&value)
QList< T >::iterator insert(QList< T >::const_iterator before, QList< T >::parameter_type value)