QtConcurrent
Trial to use Doxygen to generate UML class diagram of QtConcurrent module.
qtconcurrentfunctionwrappers.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the QtConcurrent module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 3 requirements
23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24 **
25 ** GNU General Public License Usage
26 ** Alternatively, this file may be used under the terms of the GNU
27 ** General Public License version 2.0 or (at your option) the GNU General
28 ** Public license version 3 or any later version approved by the KDE Free
29 ** Qt Foundation. The licenses are as published by the Free Software
30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31 ** included in the packaging of this file. Please review the following
32 ** information to ensure the GNU General Public License requirements will
33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34 ** https://www.gnu.org/licenses/gpl-3.0.html.
35 **
36 ** $QT_END_LICENSE$
37 **
38 ****************************************************************************/
39 
40 #ifndef QTCONCURRENT_FUNCTIONWRAPPERS_H
41 #define QTCONCURRENT_FUNCTIONWRAPPERS_H
42 
43 #include <QtConcurrent/qtconcurrentcompilertest.h>
44 #include <QtCore/QStringList>
45 
46 #if !defined(QT_NO_CONCURRENT) || defined(Q_CLANG_QDOC)
47 
48 QT_BEGIN_NAMESPACE
49 
50 namespace QtConcurrent {
51 
52 template <typename T>
54 {
55 public:
56  typedef T (*FunctionPointerType)();
57  typedef T result_type;
58  inline FunctionWrapper0(FunctionPointerType _functionPointer)
59  :functionPointer(_functionPointer) { }
60 
61  inline T operator()()
62  {
63  return functionPointer();
64  }
65 private:
66  FunctionPointerType functionPointer;
67 };
68 
69 template <typename T, typename U>
71 {
72 public:
73  typedef T (*FunctionPointerType)(U u);
74  typedef T result_type;
75  inline FunctionWrapper1(FunctionPointerType _functionPointer)
76  :functionPointer(_functionPointer) { }
77 
78  inline T operator()(U u)
79  {
80  return functionPointer(u);
81  }
82 
83 private:
84  FunctionPointerType functionPointer;
85 };
86 
87 template <typename T, typename U, typename V>
89 {
90 public:
91  typedef T (*FunctionPointerType)(U u, V v);
92  typedef T result_type;
93  inline FunctionWrapper2(FunctionPointerType _functionPointer)
94  :functionPointer(_functionPointer) { }
95 
96  inline T operator()(U u, V v)
97  {
98  return functionPointer(u, v);
99  }
100 private:
101  FunctionPointerType functionPointer;
102 };
103 
104 template <typename T, typename C>
106 {
107 public:
108  typedef T (C::*FunctionPointerType)();
109  typedef T result_type;
111  :functionPointer(_functionPointer) { }
112 
113  inline T operator()(C &c)
114  {
115  return (c.*functionPointer)();
116  }
117 private:
118  FunctionPointerType functionPointer;
119 };
120 
121 template <typename T, typename C, typename U>
123 {
124 public:
125  typedef T (C::*FunctionPointerType)(U);
126  typedef T result_type;
127 
129  : functionPointer(_functionPointer)
130  { }
131 
132  inline T operator()(C &c, U u)
133  {
134  return (c.*functionPointer)(u);
135  }
136 
137 private:
138  FunctionPointerType functionPointer;
139 };
140 
141 template <typename T, typename C>
143 {
144 public:
145  typedef T (C::*FunctionPointerType)() const;
146  typedef T result_type;
148  :functionPointer(_functionPointer) { }
149 
150  inline T operator()(const C &c) const
151  {
152  return (c.*functionPointer)();
153  }
154 private:
155  FunctionPointerType functionPointer;
156 };
157 
158 } // namespace QtConcurrent.
159 
160 namespace QtPrivate {
161 
162 template <typename T>
163 const T& createFunctionWrapper(const T& t)
164 {
165  return t;
166 }
167 
168 template <typename T, typename U>
170 {
172 }
173 
174 template <typename T, typename C>
176 {
178 }
179 
180 template <typename T, typename C, typename U>
182 {
184 }
185 
186 template <typename T, typename C>
188 {
190 }
191 
192 #if defined(__cpp_noexcept_function_type) && __cpp_noexcept_function_type >= 201510
193 template <typename T, typename U>
195 {
197 }
198 
199 template <typename T, typename C>
201 {
203 }
204 
205 template <typename T, typename C, typename U>
207 {
209 }
210 
211 template <typename T, typename C>
213 {
215 }
216 #endif
217 
219 {
220  typedef void result_type;
221 
222  template <class C, class U>
223  inline void operator()(C &c, const U &u) const
224  {
225  return c.push_back(u);
226  }
227 
228 #ifdef Q_COMPILER_RVALUE_REFS
229  template <class C, class U>
230  inline void operator()(C &c, U &&u) const
231  {
232  return c.push_back(u);
233  }
234 #endif
235 };
236 
237 template <typename Functor, bool foo = HasResultType<Functor>::Value>
238 struct LazyResultType { typedef typename Functor::result_type Type; };
239 template <typename Functor>
240 struct LazyResultType<Functor, false> { typedef void Type; };
241 
242 template <class T>
244 
245 template <class U, class V>
246 struct ReduceResultType<void(*)(U&,V)>
247 {
248  typedef U ResultType;
249 };
250 
251 template <class T, class C, class U>
252 struct ReduceResultType<T(C::*)(U)>
253 {
254  typedef C ResultType;
255 };
256 
257 #if defined(__cpp_noexcept_function_type) && __cpp_noexcept_function_type >= 201510
258 template <class U, class V>
259 struct ReduceResultType<void(*)(U&,V) noexcept>
260 {
261  typedef U ResultType;
262 };
263 
264 template <class T, class C, class U>
265 struct ReduceResultType<T(C::*)(U) noexcept>
266 {
267  typedef C ResultType;
268 };
269 #endif
270 
271 template <class InputSequence, class MapFunctor>
273 {
275 };
276 
277 template <class U, class V>
278 struct MapResultType<void, U (*)(V)>
279 {
280  typedef U ResultType;
281 };
282 
283 template <class T, class C>
284 struct MapResultType<void, T(C::*)() const>
285 {
286  typedef T ResultType;
287 };
288 
289 #if defined(__cpp_noexcept_function_type) && __cpp_noexcept_function_type >= 201510
290 template <class U, class V>
291 struct MapResultType<void, U (*)(V) noexcept>
292 {
293  typedef U ResultType;
294 };
295 
296 template <class T, class C>
297 struct MapResultType<void, T(C::*)() const noexcept>
298 {
299  typedef T ResultType;
300 };
301 #endif
302 
303 #ifndef QT_NO_TEMPLATE_TEMPLATE_PARAMETERS
304 
305 template <template <typename> class InputSequence, typename MapFunctor, typename T>
306 struct MapResultType<InputSequence<T>, MapFunctor>
307 {
308  typedef InputSequence<typename LazyResultType<MapFunctor>::Type> ResultType;
309 };
310 
311 template <template <typename> class InputSequence, class T, class U, class V>
312 struct MapResultType<InputSequence<T>, U (*)(V)>
313 {
314  typedef InputSequence<U> ResultType;
315 };
316 
317 template <template <typename> class InputSequence, class T, class U, class C>
318 struct MapResultType<InputSequence<T>, U(C::*)() const>
319 {
320  typedef InputSequence<U> ResultType;
321 };
322 
323 #if defined(__cpp_noexcept_function_type) && __cpp_noexcept_function_type >= 201510
324 
325 template <template <typename> class InputSequence, class T, class U, class V>
326 struct MapResultType<InputSequence<T>, U (*)(V) noexcept>
327 {
328  typedef InputSequence<U> ResultType;
329 };
330 
331 template <template <typename> class InputSequence, class T, class U, class C>
332 struct MapResultType<InputSequence<T>, U(C::*)() const noexcept>
333 {
334  typedef InputSequence<U> ResultType;
335 };
336 #endif
337 
338 #endif // QT_NO_TEMPLATE_TEMPLATE_PARAMETER
339 
340 template <class MapFunctor>
341 struct MapResultType<QStringList, MapFunctor>
342 {
343  typedef QList<typename LazyResultType<MapFunctor>::Type> ResultType;
344 };
345 
346 template <class U, class V>
347 struct MapResultType<QStringList, U (*)(V)>
348 {
349  typedef QList<U> ResultType;
350 };
351 
352 template <class U, class C>
353 struct MapResultType<QStringList, U(C::*)() const>
354 {
355  typedef QList<U> ResultType;
356 };
357 
358 #if defined(__cpp_noexcept_function_type) && __cpp_noexcept_function_type >= 201510
359 
360 template <class U, class V>
361 struct MapResultType<QStringList, U (*)(V) noexcept>
362 {
363  typedef QList<U> ResultType;
364 };
365 
366 template <class U, class C>
367 struct MapResultType<QStringList, U(C::*)() const noexcept>
368 {
369  typedef QList<U> ResultType;
370 };
371 #endif
372 
373 } // namespace QtPrivate.
374 
375 
376 QT_END_NAMESPACE
377 
378 #endif // QT_NO_CONCURRENT
379 
380 #endif
T result_type
Definition: qtconcurrentfunctionwrappers.h:109
Definition: qtconcurrentfunctionwrappers.h:243
void Type
Definition: qtconcurrentfunctionwrappers.h:240
T(* FunctionPointerType)()
Definition: qtconcurrentfunctionwrappers.h:56
T result_type
Definition: qtconcurrentfunctionwrappers.h:57
T result_type
Definition: qtconcurrentfunctionwrappers.h:74
MemberFunctionWrapper(FunctionPointerType _functionPointer)
Definition: qtconcurrentfunctionwrappers.h:110
Definition: qtconcurrentfunctionwrappers.h:218
T operator()()
Definition: qtconcurrentfunctionwrappers.h:61
T operator()(U u, V v)
Definition: qtconcurrentfunctionwrappers.h:96
T operator()(U u)
Definition: qtconcurrentfunctionwrappers.h:78
T operator()(const C &c) const
Definition: qtconcurrentfunctionwrappers.h:150
T operator()(C &c, U u)
Definition: qtconcurrentfunctionwrappers.h:132
Definition: qtconcurrentcompilertest.h:49
Definition: qtconcurrentfunctionwrappers.h:272
T ResultType
Definition: qtconcurrentfunctionwrappers.h:286
InputSequence< U > ResultType
Definition: qtconcurrentfunctionwrappers.h:314
Definition: qtconcurrentfunctionwrappers.h:105
ConstMemberFunctionWrapper(FunctionPointerType _functionPointer)
Definition: qtconcurrentfunctionwrappers.h:147
Definition: qtconcurrentfunctionwrappers.h:142
Definition: qtconcurrentfunctionwrappers.h:238
T result_type
Definition: qtconcurrentfunctionwrappers.h:126
FunctionWrapper2(FunctionPointerType _functionPointer)
Definition: qtconcurrentfunctionwrappers.h:93
C ResultType
Definition: qtconcurrentfunctionwrappers.h:254
Definition: qtconcurrentfunctionwrappers.h:88
InputSequence< typename LazyResultType< MapFunctor >::Type > ResultType
Definition: qtconcurrentfunctionwrappers.h:308
QtConcurrent::ConstMemberFunctionWrapper< T, C > createFunctionWrapper(T(C::*func)() const)
Definition: qtconcurrentfunctionwrappers.h:187
QList< U > ResultType
Definition: qtconcurrentfunctionwrappers.h:355
U ResultType
Definition: qtconcurrentfunctionwrappers.h:280
QList< U > ResultType
Definition: qtconcurrentfunctionwrappers.h:349
Definition: qtconcurrentfunctionwrappers.h:70
Functor::result_type Type
Definition: qtconcurrentfunctionwrappers.h:238
U ResultType
Definition: qtconcurrentfunctionwrappers.h:248
InputSequence< U > ResultType
Definition: qtconcurrentfunctionwrappers.h:320
The QtConcurrent namespace provides high-level APIs that make it possible to write multi-threaded pro...
Definition: qtconcurrentexception.h:51
void operator()(C &c, const U &u) const
Definition: qtconcurrentfunctionwrappers.h:223
FunctionWrapper0(FunctionPointerType _functionPointer)
Definition: qtconcurrentfunctionwrappers.h:58
void result_type
Definition: qtconcurrentfunctionwrappers.h:220
T result_type
Definition: qtconcurrentfunctionwrappers.h:146
T operator()(C &c)
Definition: qtconcurrentfunctionwrappers.h:113
QList< typename LazyResultType< MapFunctor >::Type > ResultType
Definition: qtconcurrentfunctionwrappers.h:343
Definition: qtconcurrentfunctionwrappers.h:122
Definition: qtconcurrentfunctionwrappers.h:53
LazyResultType< MapFunctor >::Type ResultType
Definition: qtconcurrentfunctionwrappers.h:274
MemberFunctionWrapper1(FunctionPointerType _functionPointer)
Definition: qtconcurrentfunctionwrappers.h:128
FunctionWrapper1(FunctionPointerType _functionPointer)
Definition: qtconcurrentfunctionwrappers.h:75
T result_type
Definition: qtconcurrentfunctionwrappers.h:92