QtCore/qtconcurrentmap.h Source File

qtconcurrentmap.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtCore 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 Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #ifndef QTCONCURRENT_MAP_H
43 #define QTCONCURRENT_MAP_H
44 
45 #include <QtCore/qglobal.h>
46 
47 #ifndef QT_NO_CONCURRENT
48 
52 #include <QtCore/qstringlist.h>
53 
56 
57 QT_MODULE(Core)
58 
59 #ifdef qdoc
60 
61 namespace QtConcurrent {
62 
63  QFuture<void> map(Sequence &sequence, MapFunction function);
64  QFuture<void> map(Iterator begin, Iterator end, MapFunction function);
65 
66  template <typename T>
67  QFuture<T> mapped(const Sequence &sequence, MapFunction function);
68  template <typename T>
69  QFuture<T> mapped(ConstIterator begin, ConstIterator end, MapFunction function);
70 
71  template <typename T>
72  QFuture<T> mappedReduced(const Sequence &sequence,
73  MapFunction function,
74  ReduceFunction function,
75  QtConcurrent::ReduceOptions options = UnorderedReduce | SequentialReduce);
76  template <typename T>
77  QFuture<T> mappedReduced(ConstIterator begin,
78  ConstIterator end,
79  MapFunction function,
80  ReduceFunction function,
81  QtConcurrent::ReduceOptions options = UnorderedReduce | SequentialReduce);
82 
83  void blockingMap(Sequence &sequence, MapFunction function);
84  void blockingMap(Iterator begin, Iterator end, MapFunction function);
85 
86  template <typename T>
87  T blockingMapped(const Sequence &sequence, MapFunction function);
88  template <typename T>
89  T blockingMapped(ConstIterator begin, ConstIterator end, MapFunction function);
90 
91  template <typename T>
92  T blockingMappedReduced(const Sequence &sequence,
93  MapFunction function,
94  ReduceFunction function,
95  QtConcurrent::ReduceOptions options = UnorderedReduce | SequentialReduce);
96  template <typename T>
97  T blockingMappedReduced(ConstIterator begin,
98  ConstIterator end,
99  MapFunction function,
100  ReduceFunction function,
101  QtConcurrent::ReduceOptions options = UnorderedReduce | SequentialReduce);
102 
103 } // namespace QtConcurrent
104 
105 #else
106 
107 namespace QtConcurrent {
108 
109 // map() on sequences
110 template <typename Sequence, typename MapFunctor>
111 QFuture<void> map(Sequence &sequence, MapFunctor map)
112 {
113  return startMap(sequence.begin(), sequence.end(), QtPrivate::createFunctionWrapper(map));
114 }
115 
116 // map() on iterators
117 template <typename Iterator, typename MapFunctor>
118 QFuture<void> map(Iterator begin, Iterator end, MapFunctor map)
119 {
120  return startMap(begin, end, QtPrivate::createFunctionWrapper(map));
121 }
122 
123 // mappedReduced() for sequences.
124 template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor>
125 QFuture<ResultType> mappedReduced(const Sequence &sequence,
126  MapFunctor map,
127  ReduceFunctor reduce,
128  ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
129 {
130  return startMappedReduced<typename QtPrivate::MapResultType<void, MapFunctor>::ResultType, ResultType>
131  (sequence,
134  options);
135 }
136 
137 template <typename Sequence, typename MapFunctor, typename ReduceFunctor>
139  MapFunctor map,
140  ReduceFunctor reduce,
141  ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
142 {
143  return startMappedReduced<typename QtPrivate::MapResultType<void, MapFunctor>::ResultType, typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType>
144  (sequence,
147  options);
148 }
149 
150 // mappedReduced() for iterators
151 template <typename ResultType, typename Iterator, typename MapFunctor, typename ReduceFunctor>
153  Iterator end,
154  MapFunctor map,
155  ReduceFunctor reduce,
156  ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
157 {
158  return startMappedReduced<typename QtPrivate::MapResultType<void, MapFunctor>::ResultType, ResultType>
159  (begin, end,
162  options);
163 }
164 
165 template <typename Iterator, typename MapFunctor, typename ReduceFunctor>
167  Iterator end,
168  MapFunctor map,
169  ReduceFunctor reduce,
170  ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
171 {
172  return startMappedReduced<typename QtPrivate::MapResultType<void, MapFunctor>::ResultType, typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType>
173  (begin, end,
176  options);
177 }
178 
179 // mapped() for sequences
180 template <typename Sequence, typename MapFunctor>
182 {
183  return startMapped<typename QtPrivate::MapResultType<void, MapFunctor>::ResultType>(sequence, QtPrivate::createFunctionWrapper(map));
184 }
185 
186 // mapped() for iterator ranges.
187 template <typename Iterator, typename MapFunctor>
189 {
190  return startMapped<typename QtPrivate::MapResultType<void, MapFunctor>::ResultType>(begin, end, QtPrivate::createFunctionWrapper(map));
191 }
192 
193 // blockingMap() for sequences
194 template <typename Sequence, typename MapFunctor>
195 void blockingMap(Sequence &sequence, MapFunctor map)
196 {
197  startMap(sequence.begin(), sequence.end(), QtPrivate::createFunctionWrapper(map)).startBlocking();
198 }
199 
200 // blockingMap() for iterator ranges
201 template <typename Iterator, typename MapFunctor>
202 void blockingMap(Iterator begin, Iterator end, MapFunctor map)
203 {
205 }
206 
207 // blockingMappedReduced() for sequences
208 template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor>
209 ResultType blockingMappedReduced(const Sequence &sequence,
210  MapFunctor map,
211  ReduceFunctor reduce,
212  ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
213 {
214  return QtConcurrent::startMappedReduced<typename QtPrivate::MapResultType<void, MapFunctor>::ResultType, ResultType>
215  (sequence,
218  options)
219  .startBlocking();
220 }
221 
222 template <typename MapFunctor, typename ReduceFunctor, typename Sequence>
224  MapFunctor map,
225  ReduceFunctor reduce,
226  ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
227 {
228  return QtConcurrent::startMappedReduced<typename QtPrivate::MapResultType<void, MapFunctor>::ResultType, typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType>
229  (sequence,
232  options)
233  .startBlocking();
234 }
235 
236 // blockingMappedReduced() for iterator ranges
237 template <typename ResultType, typename Iterator, typename MapFunctor, typename ReduceFunctor>
238 ResultType blockingMappedReduced(Iterator begin,
239  Iterator end,
240  MapFunctor map,
241  ReduceFunctor reduce,
242  QtConcurrent::ReduceOptions options = QtConcurrent::ReduceOptions(QtConcurrent::UnorderedReduce | QtConcurrent::SequentialReduce))
243 {
244  return QtConcurrent::startMappedReduced<typename QtPrivate::MapResultType<void, MapFunctor>::ResultType, ResultType>
245  (begin, end,
248  options)
249  .startBlocking();
250 }
251 
252 template <typename Iterator, typename MapFunctor, typename ReduceFunctor>
254  Iterator end,
255  MapFunctor map,
256  ReduceFunctor reduce,
257  QtConcurrent::ReduceOptions options = QtConcurrent::ReduceOptions(QtConcurrent::UnorderedReduce | QtConcurrent::SequentialReduce))
258 {
259  return QtConcurrent::startMappedReduced<typename QtPrivate::MapResultType<void, MapFunctor>::ResultType, typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType>
260  (begin, end,
263  options)
264  .startBlocking();
265 }
266 
267 // mapped() for sequences with a different putput sequence type.
268 template <typename OutputSequence, typename InputSequence, typename MapFunctor>
269 OutputSequence blockingMapped(const InputSequence &sequence, MapFunctor map)
270 {
271  return blockingMappedReduced<OutputSequence>
272  (sequence,
276 }
277 
278 template <typename MapFunctor, typename InputSequence>
279 typename QtPrivate::MapResultType<InputSequence, MapFunctor>::ResultType blockingMapped(const InputSequence &sequence, MapFunctor map)
280 {
282  return blockingMappedReduced<OutputSequence>
283  (sequence,
287 }
288 
289 // mapped() for iterator ranges
290 template <typename Sequence, typename Iterator, typename MapFunctor>
291 Sequence blockingMapped(Iterator begin, Iterator end, MapFunctor map)
292 {
293  return blockingMappedReduced<Sequence>
294  (begin, end,
298 }
299 
300 template <typename Iterator, typename MapFunctor>
301 typename QtPrivate::MapResultType<Iterator, MapFunctor>::ResultType blockingMapped(Iterator begin, Iterator end, MapFunctor map)
302 {
303  typedef typename QtPrivate::MapResultType<Iterator, MapFunctor>::ResultType OutputSequence;
304  return blockingMappedReduced<OutputSequence>
305  (begin, end,
309 }
310 
311 } // namespace QtConcurrent
312 
313 #endif // qdoc
314 
317 
318 #endif // QT_NO_CONCURRENT
319 
320 #endif
#define QT_END_NAMESPACE
Definition: qglobal.h:128
QFuture< typename QtPrivate::MapResultType< void, MapFunctor >::ResultType > mapped(const Sequence &sequence, MapFunctor map)
#define QT_BEGIN_HEADER
Definition: qglobal.h:141
QFuture< void > map(Sequence &sequence, MapFunctor map)
OutputSequence blockingMapped(const InputSequence &sequence, MapFunctor map)
QFuture< ResultType > mappedReduced(const Sequence &sequence, MapFunctor map, ReduceFunctor reduce, ReduceOptions options=ReduceOptions(UnorderedReduce|SequentialReduce))
void blockingMap(Sequence &sequence, MapFunctor map)
#define QT_BEGIN_NAMESPACE
Definition: qglobal.h:127
GLuint GLuint end
Definition: GLee.h:872
const T & createFunctionWrapper(const T &t)
ResultType blockingMappedReduced(const Sequence &sequence, MapFunctor map, ReduceFunctor reduce, ReduceOptions options=ReduceOptions(UnorderedReduce|SequentialReduce))
LazyResultType< MapFunctor >::Type ResultType
#define QT_END_HEADER
Definition: qglobal.h:142
ThreadEngineStarter< void > startMap(Iterator begin, Iterator end, Functor functor)