AusweisApp2
Lade ...
Suche ...
Keine Treffer
FuncUtils.h
gehe zur Dokumentation dieser Datei
1
9#pragma once
10
11#include <functional>
12#include <type_traits>
13
14#include <QVector>
15
16namespace governikus
17{
18
19#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
20
21/*
22 * Usage example: map<Reader, QString>([](const Reader& r){ return r.getName(); }, readers)
23 *
24 * where readers has type QVector<Reader>
25 */
26template<typename S, typename T>
27std::enable_if_t<!std::is_void_v<T>, QVector<T>> map(const std::function<T(const S&)>& pFunc, const QVector<S>& pItems)
28{
29 const auto sz = pItems.size();
30 QVector<T> result(sz);
31 for (int index = 0; index < sz; ++index)
32 {
33 result[index] = pFunc(pItems[index]);
34 }
35
36 return result;
37}
38
39
40#endif
41
42
43/*
44 * Usage example: map<Reader, QString>([](const Reader& r){ return r.getName(); }, readers)
45 *
46 * where readers has type QList<Reader>
47 */
48template<typename S, typename T>
49std::enable_if_t<!std::is_void_v<T>, QList<T>> map(const std::function<T(const S&)>& pFunc, const QList<S>& pItems)
50{
51 const auto sz = pItems.size();
52 QList<T> result;
53 for (int index = 0; index < sz; ++index)
54 {
55 result.append(pFunc(pItems[index]));
56 }
57
58 return result;
59}
60
61
62/*
63 * Usage example: filter<Reader>([](const Reader& r){ return r.getCard() != nullptr; }, readers)
64 *
65 * where readers has type QVector<Reader>
66 */
67template<typename T>
68std::enable_if_t<!std::is_void_v<T>, QVector<T>> filter(const std::function<bool(const T&)>& pFunc, const QVector<T>& pItems)
69{
70 QVector<T> result;
71 for (const T& item : pItems)
72 {
73 if (pFunc(item))
74 {
75 result += item;
76 }
77 }
78
79 return result;
80}
81
82
83} // namespace governikus
#define T(v)
Definition: http_parser.cpp:237
Implementation of GeneralAuthenticate response APDUs.
Definition: CommandApdu.h:16
std::enable_if_t<!std::is_void_v< T >, QList< T > > map(const std::function< T(const S &)> &pFunc, const QList< S > &pItems)
Definition: FuncUtils.h:49
std::enable_if_t<!std::is_void_v< T >, QVector< T > > filter(const std::function< bool(const T &)> &pFunc, const QVector< T > &pItems)
Definition: FuncUtils.h:68