AusweisApp
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 <QList>
15
16namespace governikus
17{
18
19
20/*
21 * Usage example: map<Reader, QString>([](const Reader& r){ return r.getName(); }, readers)
22 *
23 * where readers has type QList<Reader>
24 */
25template<typename S, typename T>
26std::enable_if_t<!std::is_void_v<T>, QList<T>> map(const std::function<T(const S&)>& pFunc, const QList<S>& pItems)
27{
28 const auto sz = pItems.size();
29 QList<T> result;
30 for (int index = 0; index < sz; ++index)
31 {
32 result.append(pFunc(pItems[index]));
33 }
34
35 return result;
36}
37
38
39/*
40 * Usage example: filter<Reader>([](const Reader& r){ return r.getCard() != nullptr; }, readers)
41 *
42 * where readers has type QList<Reader>
43 */
44template<typename T>
45std::enable_if_t<!std::is_void_v<T>, QList<T>> filter(const std::function<bool(const T&)>& pFunc, const QList<T>& pItems)
46{
47 QList<T> result;
48 for (const T& item : pItems)
49 {
50 if (pFunc(item))
51 {
52 result += item;
53 }
54 }
55
56 return result;
57}
58
59
60} // namespace governikus
#define T(v)
Definition http_parser.cpp:237
Implementation of GeneralAuthenticate response APDUs.
Definition CommandApdu.h:17
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:26
QSharedPointer< T > decodeObject(const QByteArray &pData, bool pLogging=true)
Template function for decoding an OpenSSL type from DER encoded QByteArray.
Definition ASN1TemplateUtil.h:114
std::enable_if_t<!std::is_void_v< T >, QList< T > > filter(const std::function< bool(const T &)> &pFunc, const QList< T > &pItems)
Definition FuncUtils.h:45