QtConcurrent
Trial to use Doxygen to generate UML class diagram of QtConcurrent module.
qtconcurrentmap.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_MAP_H
41 #define QTCONCURRENT_MAP_H
42 
43 #include <QtConcurrent/qtconcurrent_global.h>
44 
45 #if !defined(QT_NO_CONCURRENT) || defined(Q_CLANG_QDOC)
46 
47 #include <QtConcurrent/qtconcurrentmapkernel.h>
48 #include <QtConcurrent/qtconcurrentreducekernel.h>
49 #include <QtConcurrent/qtconcurrentfunctionwrappers.h>
50 #include <QtCore/qstringlist.h>
51 
52 QT_BEGIN_NAMESPACE
53 
54 
55 
56 namespace QtConcurrent {
57 
58 // map() on sequences
59 template <typename Sequence, typename MapFunctor>
60 QFuture<void> map(Sequence &sequence, MapFunctor map)
61 {
62  return startMap(sequence.begin(), sequence.end(), QtPrivate::createFunctionWrapper(map));
63 }
64 
65 // map() on iterators
66 template <typename Iterator, typename MapFunctor>
67 QFuture<void> map(Iterator begin, Iterator end, MapFunctor map)
68 {
69  return startMap(begin, end, QtPrivate::createFunctionWrapper(map));
70 }
71 
72 // mappedReduced() for sequences.
73 template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor>
74 QFuture<ResultType> mappedReduced(const Sequence &sequence,
75  MapFunctor map,
76  ReduceFunctor reduce,
77  ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
78 {
79  return startMappedReduced<typename QtPrivate::MapResultType<void, MapFunctor>::ResultType, ResultType>
80  (sequence,
83  options);
84 }
85 
86 template <typename Sequence, typename MapFunctor, typename ReduceFunctor>
87 QFuture<typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType> mappedReduced(const Sequence &sequence,
88  MapFunctor map,
89  ReduceFunctor reduce,
90  ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
91 {
92  return startMappedReduced<typename QtPrivate::MapResultType<void, MapFunctor>::ResultType, typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType>
93  (sequence,
96  options);
97 }
98 
99 // mappedReduced() for iterators
100 template <typename ResultType, typename Iterator, typename MapFunctor, typename ReduceFunctor>
101 QFuture<ResultType> mappedReduced(Iterator begin,
102  Iterator end,
103  MapFunctor map,
104  ReduceFunctor reduce,
105  ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
106 {
107  return startMappedReduced<typename QtPrivate::MapResultType<void, MapFunctor>::ResultType, ResultType>
108  (begin, end,
111  options);
112 }
113 
114 template <typename Iterator, typename MapFunctor, typename ReduceFunctor>
115 QFuture<typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType> mappedReduced(Iterator begin,
116  Iterator end,
117  MapFunctor map,
118  ReduceFunctor reduce,
119  ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
120 {
121  return startMappedReduced<typename QtPrivate::MapResultType<void, MapFunctor>::ResultType, typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType>
122  (begin, end,
125  options);
126 }
127 
128 // mapped() for sequences
129 template <typename Sequence, typename MapFunctor>
130 QFuture<typename QtPrivate::MapResultType<void, MapFunctor>::ResultType> mapped(const Sequence &sequence, MapFunctor map)
131 {
132  return startMapped<typename QtPrivate::MapResultType<void, MapFunctor>::ResultType>(sequence, QtPrivate::createFunctionWrapper(map));
133 }
134 
135 // mapped() for iterator ranges.
136 template <typename Iterator, typename MapFunctor>
137 QFuture<typename QtPrivate::MapResultType<void, MapFunctor>::ResultType> mapped(Iterator begin, Iterator end, MapFunctor map)
138 {
139  return startMapped<typename QtPrivate::MapResultType<void, MapFunctor>::ResultType>(begin, end, QtPrivate::createFunctionWrapper(map));
140 }
141 
142 // blockingMap() for sequences
143 template <typename Sequence, typename MapFunctor>
144 void blockingMap(Sequence &sequence, MapFunctor map)
145 {
146  startMap(sequence.begin(), sequence.end(), QtPrivate::createFunctionWrapper(map)).startBlocking();
147 }
148 
149 // blockingMap() for iterator ranges
150 template <typename Iterator, typename MapFunctor>
151 void blockingMap(Iterator begin, Iterator end, MapFunctor map)
152 {
154 }
155 
156 // blockingMappedReduced() for sequences
157 template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor>
158 ResultType blockingMappedReduced(const Sequence &sequence,
159  MapFunctor map,
160  ReduceFunctor reduce,
161  ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
162 {
163  return QtConcurrent::startMappedReduced<typename QtPrivate::MapResultType<void, MapFunctor>::ResultType, ResultType>
164  (sequence,
167  options)
168  .startBlocking();
169 }
170 
171 template <typename MapFunctor, typename ReduceFunctor, typename Sequence>
173  MapFunctor map,
174  ReduceFunctor reduce,
175  ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
176 {
177  return QtConcurrent::startMappedReduced<typename QtPrivate::MapResultType<void, MapFunctor>::ResultType, typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType>
178  (sequence,
181  options)
182  .startBlocking();
183 }
184 
185 // blockingMappedReduced() for iterator ranges
186 template <typename ResultType, typename Iterator, typename MapFunctor, typename ReduceFunctor>
187 ResultType blockingMappedReduced(Iterator begin,
188  Iterator end,
189  MapFunctor map,
190  ReduceFunctor reduce,
191  QtConcurrent::ReduceOptions options = QtConcurrent::ReduceOptions(QtConcurrent::UnorderedReduce | QtConcurrent::SequentialReduce))
192 {
193  return QtConcurrent::startMappedReduced<typename QtPrivate::MapResultType<void, MapFunctor>::ResultType, ResultType>
194  (begin, end,
197  options)
198  .startBlocking();
199 }
200 
201 template <typename Iterator, typename MapFunctor, typename ReduceFunctor>
203  Iterator end,
204  MapFunctor map,
205  ReduceFunctor reduce,
206  QtConcurrent::ReduceOptions options = QtConcurrent::ReduceOptions(QtConcurrent::UnorderedReduce | QtConcurrent::SequentialReduce))
207 {
208  return QtConcurrent::startMappedReduced<typename QtPrivate::MapResultType<void, MapFunctor>::ResultType, typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType>
209  (begin, end,
212  options)
213  .startBlocking();
214 }
215 
216 // mapped() for sequences with a different putput sequence type.
217 template <typename OutputSequence, typename InputSequence, typename MapFunctor>
218 OutputSequence blockingMapped(const InputSequence &sequence, MapFunctor map)
219 {
220  return blockingMappedReduced<OutputSequence>
221  (sequence,
225 }
226 
227 template <typename MapFunctor, typename InputSequence>
228 typename QtPrivate::MapResultType<InputSequence, MapFunctor>::ResultType blockingMapped(const InputSequence &sequence, MapFunctor map)
229 {
231  return blockingMappedReduced<OutputSequence>
232  (sequence,
236 }
237 
238 // mapped() for iterator ranges
239 template <typename Sequence, typename Iterator, typename MapFunctor>
240 Sequence blockingMapped(Iterator begin, Iterator end, MapFunctor map)
241 {
242  return blockingMappedReduced<Sequence>
243  (begin, end,
247 }
248 
249 template <typename Iterator, typename MapFunctor>
250 typename QtPrivate::MapResultType<Iterator, MapFunctor>::ResultType blockingMapped(Iterator begin, Iterator end, MapFunctor map)
251 {
252  typedef typename QtPrivate::MapResultType<Iterator, MapFunctor>::ResultType OutputSequence;
253  return blockingMappedReduced<OutputSequence>
254  (begin, end,
258 }
259 
260 } // namespace QtConcurrent
261 
262 
263 QT_END_NAMESPACE
264 
265 #endif // QT_NO_CONCURRENT
266 
267 #endif
Definition: qtconcurrentfunctionwrappers.h:243
const T & createFunctionWrapper(const T &t)
Definition: qtconcurrentfunctionwrappers.h:163
Definition: qtconcurrentreducekernel.h:93
Definition: qtconcurrentfunctionwrappers.h:218
QFuture< void > map(Sequence &sequence, MapFunctor map)
Definition: qtconcurrentmap.h:60
ResultType blockingMappedReduced(const Sequence &sequence, MapFunctor map, ReduceFunctor reduce, ReduceOptions options=ReduceOptions(UnorderedReduce|SequentialReduce))
Definition: qtconcurrentmap.h:158
void blockingMap(Sequence &sequence, MapFunctor map)
Definition: qtconcurrentmap.h:144
Definition: qtconcurrentreducekernel.h:91
OutputSequence blockingMapped(const InputSequence &sequence, MapFunctor map)
Definition: qtconcurrentmap.h:218
ThreadEngineStarter< void > startMap(Iterator begin, Iterator end, Functor functor)
[qtconcurrentmapkernel-1]
Definition: qtconcurrentmapkernel.h:195
QFuture< ResultType > mappedReduced(const Sequence &sequence, MapFunctor map, ReduceFunctor reduce, ReduceOptions options=ReduceOptions(UnorderedReduce|SequentialReduce))
Definition: qtconcurrentmap.h:74
The QtConcurrent namespace provides high-level APIs that make it possible to write multi-threaded pro...
Definition: qtconcurrentexception.h:51
Definition: qtconcurrentreducekernel.h:92
LazyResultType< MapFunctor >::Type ResultType
Definition: qtconcurrentfunctionwrappers.h:274
QFuture< typename QtPrivate::MapResultType< void, MapFunctor >::ResultType > mapped(const Sequence &sequence, MapFunctor map)
Definition: qtconcurrentmap.h:130
void startBlocking()
Definition: qtconcurrentthreadengine.h:253