Fix QNetworkReply ioGetFromHttpWithCache test case
[profile/ivi/qtbase.git] / src / concurrent / qtconcurrentmap.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the QtCore module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
16 **
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
20 **
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
28 **
29 ** Other Usage
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef QTCONCURRENT_MAP_H
43 #define QTCONCURRENT_MAP_H
44
45 #include <QtConcurrent/qtconcurrent_global.h>
46
47 #ifndef QT_NO_CONCURRENT
48
49 #include <QtConcurrent/qtconcurrentmapkernel.h>
50 #include <QtConcurrent/qtconcurrentreducekernel.h>
51 #include <QtConcurrent/qtconcurrentfunctionwrappers.h>
52 #include <QtCore/qstringlist.h>
53
54 QT_BEGIN_HEADER
55 QT_BEGIN_NAMESPACE
56
57
58 #ifdef qdoc
59
60 namespace QtConcurrent {
61
62     QFuture<void> map(Sequence &sequence, MapFunction function);
63     QFuture<void> map(Iterator begin, Iterator end, MapFunction function);
64
65     template <typename T>
66     QFuture<T> mapped(const Sequence &sequence, MapFunction function);
67     template <typename T>
68     QFuture<T> mapped(ConstIterator begin, ConstIterator end, MapFunction function);
69
70     template <typename T>
71     QFuture<T> mappedReduced(const Sequence &sequence,
72                              MapFunction function,
73                              ReduceFunction function,
74                              QtConcurrent::ReduceOptions options = UnorderedReduce | SequentialReduce);
75     template <typename T>
76     QFuture<T> mappedReduced(ConstIterator begin,
77                              ConstIterator end,
78                              MapFunction function,
79                              ReduceFunction function,
80                              QtConcurrent::ReduceOptions options = UnorderedReduce | SequentialReduce);
81
82     void blockingMap(Sequence &sequence, MapFunction function);
83     void blockingMap(Iterator begin, Iterator end, MapFunction function);
84
85     template <typename T>
86     T blockingMapped(const Sequence &sequence, MapFunction function);
87     template <typename T>
88     T blockingMapped(ConstIterator begin, ConstIterator end, MapFunction function);
89
90     template <typename T>
91     T blockingMappedReduced(const Sequence &sequence,
92                             MapFunction function,
93                             ReduceFunction function,
94                             QtConcurrent::ReduceOptions options = UnorderedReduce | SequentialReduce);
95     template <typename T>
96     T blockingMappedReduced(ConstIterator begin,
97                             ConstIterator end,
98                             MapFunction function,
99                             ReduceFunction function,
100                             QtConcurrent::ReduceOptions options = UnorderedReduce | SequentialReduce);
101
102 } // namespace QtConcurrent
103
104 #else
105
106 namespace QtConcurrent {
107
108 // map() on sequences
109 template <typename Sequence, typename MapFunctor>
110 QFuture<void> map(Sequence &sequence, MapFunctor map)
111 {
112     return startMap(sequence.begin(), sequence.end(), QtPrivate::createFunctionWrapper(map));
113 }
114
115 // map() on iterators
116 template <typename Iterator, typename MapFunctor>
117 QFuture<void> map(Iterator begin, Iterator end, MapFunctor map)
118 {
119     return startMap(begin, end, QtPrivate::createFunctionWrapper(map));
120 }
121
122 // mappedReduced() for sequences.
123 template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor>
124 QFuture<ResultType> mappedReduced(const Sequence &sequence,
125                                   MapFunctor map,
126                                   ReduceFunctor reduce,
127                                   ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
128 {
129     return startMappedReduced<typename QtPrivate::MapResultType<void, MapFunctor>::ResultType, ResultType>
130         (sequence,
131          QtPrivate::createFunctionWrapper(map),
132          QtPrivate::createFunctionWrapper(reduce),
133          options);
134 }
135
136 template <typename Sequence, typename MapFunctor, typename ReduceFunctor>
137 QFuture<typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType> mappedReduced(const Sequence &sequence,
138                                   MapFunctor map,
139                                   ReduceFunctor reduce,
140                                   ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
141 {
142     return startMappedReduced<typename QtPrivate::MapResultType<void, MapFunctor>::ResultType, typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType>
143         (sequence,
144          QtPrivate::createFunctionWrapper(map),
145          QtPrivate::createFunctionWrapper(reduce),
146          options);
147 }
148
149 // mappedReduced() for iterators
150 template <typename ResultType, typename Iterator, typename MapFunctor, typename ReduceFunctor>
151 QFuture<ResultType> mappedReduced(Iterator begin,
152                                   Iterator end,
153                                   MapFunctor map,
154                                   ReduceFunctor reduce,
155                                   ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
156 {
157     return startMappedReduced<typename QtPrivate::MapResultType<void, MapFunctor>::ResultType, ResultType>
158         (begin, end,
159          QtPrivate::createFunctionWrapper(map),
160          QtPrivate::createFunctionWrapper(reduce),
161          options);
162 }
163
164 template <typename Iterator, typename MapFunctor, typename ReduceFunctor>
165 QFuture<typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType> mappedReduced(Iterator begin,
166                                   Iterator end,
167                                   MapFunctor map,
168                                   ReduceFunctor reduce,
169                                   ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
170 {
171     return startMappedReduced<typename QtPrivate::MapResultType<void, MapFunctor>::ResultType, typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType>
172         (begin, end,
173          QtPrivate::createFunctionWrapper(map),
174          QtPrivate::createFunctionWrapper(reduce),
175          options);
176 }
177
178 // mapped() for sequences
179 template <typename Sequence, typename MapFunctor>
180 QFuture<typename QtPrivate::MapResultType<void, MapFunctor>::ResultType> mapped(const Sequence &sequence, MapFunctor map)
181 {
182     return startMapped<typename QtPrivate::MapResultType<void, MapFunctor>::ResultType>(sequence, QtPrivate::createFunctionWrapper(map));
183 }
184
185 // mapped() for iterator ranges.
186 template <typename Iterator, typename MapFunctor>
187 QFuture<typename QtPrivate::MapResultType<void, MapFunctor>::ResultType> mapped(Iterator begin, Iterator end, MapFunctor map)
188 {
189     return startMapped<typename QtPrivate::MapResultType<void, MapFunctor>::ResultType>(begin, end, QtPrivate::createFunctionWrapper(map));
190 }
191
192 // blockingMap() for sequences
193 template <typename Sequence, typename MapFunctor>
194 void blockingMap(Sequence &sequence, MapFunctor map)
195 {
196     startMap(sequence.begin(), sequence.end(), QtPrivate::createFunctionWrapper(map)).startBlocking();
197 }
198
199 // blockingMap() for iterator ranges
200 template <typename Iterator, typename MapFunctor>
201 void blockingMap(Iterator begin, Iterator end, MapFunctor map)
202 {
203     startMap(begin, end, QtPrivate::createFunctionWrapper(map)).startBlocking();
204 }
205
206 // blockingMappedReduced() for sequences
207 template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor>
208 ResultType blockingMappedReduced(const Sequence &sequence,
209                                  MapFunctor map,
210                                  ReduceFunctor reduce,
211                                  ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
212 {
213     return QtConcurrent::startMappedReduced<typename QtPrivate::MapResultType<void, MapFunctor>::ResultType, ResultType>
214         (sequence,
215          QtPrivate::createFunctionWrapper(map),
216          QtPrivate::createFunctionWrapper(reduce),
217          options)
218         .startBlocking();
219 }
220
221 template <typename MapFunctor, typename ReduceFunctor, typename Sequence>
222 typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType blockingMappedReduced(const Sequence &sequence,
223                                  MapFunctor map,
224                                  ReduceFunctor reduce,
225                                  ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
226 {
227     return QtConcurrent::startMappedReduced<typename QtPrivate::MapResultType<void, MapFunctor>::ResultType, typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType>
228         (sequence,
229          QtPrivate::createFunctionWrapper(map),
230          QtPrivate::createFunctionWrapper(reduce),
231          options)
232         .startBlocking();
233 }
234
235 // blockingMappedReduced() for iterator ranges
236 template <typename ResultType, typename Iterator, typename MapFunctor, typename ReduceFunctor>
237 ResultType blockingMappedReduced(Iterator begin,
238                                  Iterator end,
239                                  MapFunctor map,
240                                  ReduceFunctor reduce,
241                                  QtConcurrent::ReduceOptions options = QtConcurrent::ReduceOptions(QtConcurrent::UnorderedReduce | QtConcurrent::SequentialReduce))
242 {
243     return QtConcurrent::startMappedReduced<typename QtPrivate::MapResultType<void, MapFunctor>::ResultType, ResultType>
244         (begin, end,
245          QtPrivate::createFunctionWrapper(map),
246          QtPrivate::createFunctionWrapper(reduce),
247          options)
248         .startBlocking();
249 }
250
251 template <typename Iterator, typename MapFunctor, typename ReduceFunctor>
252 typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType blockingMappedReduced(Iterator begin,
253                                  Iterator end,
254                                  MapFunctor map,
255                                  ReduceFunctor reduce,
256                                  QtConcurrent::ReduceOptions options = QtConcurrent::ReduceOptions(QtConcurrent::UnorderedReduce | QtConcurrent::SequentialReduce))
257 {
258     return QtConcurrent::startMappedReduced<typename QtPrivate::MapResultType<void, MapFunctor>::ResultType, typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType>
259         (begin, end,
260          QtPrivate::createFunctionWrapper(map),
261          QtPrivate::createFunctionWrapper(reduce),
262          options)
263         .startBlocking();
264 }
265
266 // mapped() for sequences with a different putput sequence type.
267 template <typename OutputSequence, typename InputSequence, typename MapFunctor>
268 OutputSequence blockingMapped(const InputSequence &sequence, MapFunctor map)
269 {
270     return blockingMappedReduced<OutputSequence>
271         (sequence,
272          QtPrivate::createFunctionWrapper(map),
273          QtPrivate::PushBackWrapper(),
274          QtConcurrent::OrderedReduce);
275 }
276
277 template <typename MapFunctor, typename InputSequence>
278 typename QtPrivate::MapResultType<InputSequence, MapFunctor>::ResultType blockingMapped(const InputSequence &sequence, MapFunctor map)
279 {
280     typedef typename QtPrivate::MapResultType<InputSequence, MapFunctor>::ResultType OutputSequence;
281     return blockingMappedReduced<OutputSequence>
282         (sequence,
283          QtPrivate::createFunctionWrapper(map),
284          QtPrivate::PushBackWrapper(),
285          QtConcurrent::OrderedReduce);
286 }
287
288 // mapped()  for iterator ranges
289 template <typename Sequence, typename Iterator, typename MapFunctor>
290 Sequence blockingMapped(Iterator begin, Iterator end, MapFunctor map)
291 {
292     return blockingMappedReduced<Sequence>
293         (begin, end,
294          QtPrivate::createFunctionWrapper(map),
295          QtPrivate::PushBackWrapper(),
296          QtConcurrent::OrderedReduce);
297 }
298
299 template <typename Iterator, typename MapFunctor>
300 typename QtPrivate::MapResultType<Iterator, MapFunctor>::ResultType blockingMapped(Iterator begin, Iterator end, MapFunctor map)
301 {
302     typedef typename QtPrivate::MapResultType<Iterator, MapFunctor>::ResultType OutputSequence;
303     return blockingMappedReduced<OutputSequence>
304         (begin, end,
305          QtPrivate::createFunctionWrapper(map),
306          QtPrivate::PushBackWrapper(),
307          QtConcurrent::OrderedReduce);
308 }
309
310 } // namespace QtConcurrent
311
312 #endif // qdoc
313
314 QT_END_NAMESPACE
315 QT_END_HEADER
316
317 #endif // QT_NO_CONCURRENT
318
319 #endif