AusweisApp2
 Alle Klassen Namensbereiche Dateien Funktionen Variablen Typdefinitionen Aufzählungen Aufzählungswerte Propertys Freundbeziehungen Makrodefinitionen
FuncUtils.h
gehe zur Dokumentation dieser Datei
1 
7 #pragma once
8 
9 #include <functional>
10 #include <type_traits>
11 
12 #include <QVector>
13 
14 namespace governikus
15 {
16 
17 /*
18  * Usage example: map<Reader, QString>([](const Reader& r){ return r.getName(); }, readers)
19  *
20  * where readers has type QVector<Reader>
21  */
22 template<typename S, typename T>
23 typename std::enable_if<!std::is_void<T>::value, QVector<T> >::type map(const std::function<T(const S&)>& pFunc, const QVector<S>& pItems)
24 {
25  const int sz = pItems.size();
26  QVector<T> result(sz);
27  for (int index = 0; index < sz; ++index)
28  {
29  result[index] = pFunc(pItems[index]);
30  }
31 
32  return result;
33 }
34 
35 
36 /*
37  * Usage example: map<Reader, QString>([](const Reader& r){ return r.getName(); }, readers)
38  *
39  * where readers has type QList<Reader>
40  */
41 template<typename S, typename T>
42 typename std::enable_if<!std::is_void<T>::value, QList<T> >::type map(const std::function<T(const S&)>& pFunc, const QList<S>& pItems)
43 {
44  const int sz = pItems.size();
45  QList<T> result;
46  for (int index = 0; index < sz; ++index)
47  {
48  result.append(pFunc(pItems[index]));
49  }
50 
51  return result;
52 }
53 
54 
55 /*
56  * Usage example: filter<Reader>([](const Reader& r){ return r.getCard() != nullptr; }, readers)
57  *
58  * where readers has type QVector<Reader>
59  */
60 template<typename T>
61 typename std::enable_if<!std::is_void<T>::value, QVector<T> >::type filter(const std::function<bool(const T&)>& pFunc, const QVector<T>& pItems)
62 {
63  QVector<T> result;
64  for (const T& item : pItems)
65  {
66  if (pFunc(item))
67  {
68  result += item;
69  }
70  }
71 
72  return result;
73 }
74 
75 
76 }
std::enable_if<!std::is_void< T >::value, QVector< T > >::type filter(const std::function< bool(const T &)> &pFunc, const QVector< T > &pItems)
Definition: FuncUtils.h:61
std::enable_if<!std::is_void< T >::value, QVector< T > >::type map(const std::function< T(const S &)> &pFunc, const QVector< S > &pItems)
Definition: FuncUtils.h:23
#define T(v)
Definition: http_parser.cpp:234