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_FILTER_H |
43 | #define QTCONCURRENT_FILTER_H |
44 | |
45 | #include <QtCore/qglobal.h> |
46 | |
47 | #ifndef QT_NO_CONCURRENT |
48 | |
49 | #include <QtCore/qtconcurrentfilterkernel.h> |
50 | #include <QtCore/qtconcurrentfunctionwrappers.h> |
51 | |
52 | QT_BEGIN_HEADER |
53 | QT_BEGIN_NAMESPACE |
54 | |
55 | QT_MODULE(Core) |
56 | |
57 | #ifdef qdoc |
58 | |
59 | namespace QtConcurrent { |
60 | |
61 | QFuture<void> filter(Sequence &sequence, FilterFunction filterFunction); |
62 | |
63 | template <typename T> |
64 | QFuture<T> filtered(const Sequence &sequence, FilterFunction filterFunction); |
65 | template <typename T> |
66 | QFuture<T> filtered(ConstIterator begin, ConstIterator end, FilterFunction filterFunction); |
67 | |
68 | template <typename T> |
69 | QFuture<T> filteredReduced(const Sequence &sequence, |
70 | FilterFunction filterFunction, |
71 | ReduceFunction reduceFunction, |
72 | QtConcurrent::ReduceOptions reduceOptions = UnorderedReduce | SequentialReduce); |
73 | template <typename T> |
74 | QFuture<T> filteredReduced(ConstIterator begin, |
75 | ConstIterator end, |
76 | FilterFunction filterFunction, |
77 | ReduceFunction reduceFunction, |
78 | QtConcurrent::ReduceOptions reduceOptions = UnorderedReduce | SequentialReduce); |
79 | |
80 | void blockingFilter(Sequence &sequence, FilterFunction filterFunction); |
81 | |
82 | template <typename Sequence> |
83 | Sequence blockingFiltered(const Sequence &sequence, FilterFunction filterFunction); |
84 | template <typename Sequence> |
85 | Sequence blockingFiltered(ConstIterator begin, ConstIterator end, FilterFunction filterFunction); |
86 | |
87 | template <typename T> |
88 | T blockingFilteredReduced(const Sequence &sequence, |
89 | FilterFunction filterFunction, |
90 | ReduceFunction reduceFunction, |
91 | QtConcurrent::ReduceOptions reduceOptions = UnorderedReduce | SequentialReduce); |
92 | template <typename T> |
93 | T blockingFilteredReduced(ConstIterator begin, |
94 | ConstIterator end, |
95 | FilterFunction filterFunction, |
96 | ReduceFunction reduceFunction, |
97 | QtConcurrent::ReduceOptions reduceOptions = UnorderedReduce | SequentialReduce); |
98 | |
99 | } // namespace QtConcurrent |
100 | |
101 | #else |
102 | |
103 | namespace QtConcurrent { |
104 | |
105 | template <typename Sequence, typename KeepFunctor, typename ReduceFunctor> |
106 | ThreadEngineStarter<void> filterInternal(Sequence &sequence, KeepFunctor keep, ReduceFunctor reduce) |
107 | { |
108 | typedef FilterKernel<Sequence, KeepFunctor, ReduceFunctor> KernelType; |
109 | return startThreadEngine(new KernelType(sequence, keep, reduce)); |
110 | } |
111 | |
112 | // filter() on sequences |
113 | template <typename Sequence, typename KeepFunctor> |
114 | QFuture<void> filter(Sequence &sequence, KeepFunctor keep) |
115 | { |
116 | return filterInternal(sequence, QtPrivate::createFunctionWrapper(keep), QtPrivate::PushBackWrapper()); |
117 | } |
118 | |
119 | // filteredReduced() on sequences |
120 | template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor> |
121 | QFuture<ResultType> filteredReduced(const Sequence &sequence, |
122 | KeepFunctor keep, |
123 | ReduceFunctor reduce, |
124 | ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) |
125 | { |
126 | return startFilteredReduced<ResultType>(sequence, QtPrivate::createFunctionWrapper(keep), QtPrivate::createFunctionWrapper(reduce), options); |
127 | } |
128 | |
129 | template <typename Sequence, typename KeepFunctor, typename ReduceFunctor> |
130 | QFuture<typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType> filteredReduced(const Sequence &sequence, |
131 | KeepFunctor keep, |
132 | ReduceFunctor reduce, |
133 | ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) |
134 | { |
135 | return startFilteredReduced<typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType> |
136 | (sequence, |
137 | QtPrivate::createFunctionWrapper(keep), |
138 | QtPrivate::createFunctionWrapper(reduce), |
139 | options); |
140 | } |
141 | |
142 | // filteredReduced() on iterators |
143 | template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor> |
144 | QFuture<ResultType> filteredReduced(Iterator begin, |
145 | Iterator end, |
146 | KeepFunctor keep, |
147 | ReduceFunctor reduce, |
148 | ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) |
149 | { |
150 | return startFilteredReduced<ResultType>(begin, end, QtPrivate::createFunctionWrapper(keep), QtPrivate::createFunctionWrapper(reduce), options); |
151 | } |
152 | |
153 | template <typename Iterator, typename KeepFunctor, typename ReduceFunctor> |
154 | QFuture<typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType> filteredReduced(Iterator begin, |
155 | Iterator end, |
156 | KeepFunctor keep, |
157 | ReduceFunctor reduce, |
158 | ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) |
159 | { |
160 | return startFilteredReduced<typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType> |
161 | (begin, end, |
162 | QtPrivate::createFunctionWrapper(keep), |
163 | QtPrivate::createFunctionWrapper(reduce), |
164 | options); |
165 | } |
166 | |
167 | // filtered() on sequences |
168 | template <typename Sequence, typename KeepFunctor> |
169 | QFuture<typename Sequence::value_type> filtered(const Sequence &sequence, KeepFunctor keep) |
170 | { |
171 | return startFiltered(sequence, QtPrivate::createFunctionWrapper(keep)); |
172 | } |
173 | |
174 | // filtered() on iterators |
175 | template <typename Iterator, typename KeepFunctor> |
176 | QFuture<typename qValueType<Iterator>::value_type> filtered(Iterator begin, Iterator end, KeepFunctor keep) |
177 | { |
178 | return startFiltered(begin, end, QtPrivate::createFunctionWrapper(keep)); |
179 | } |
180 | |
181 | // blocking filter() on sequences |
182 | template <typename Sequence, typename KeepFunctor> |
183 | void blockingFilter(Sequence &sequence, KeepFunctor keep) |
184 | { |
185 | filterInternal(sequence, QtPrivate::createFunctionWrapper(keep), QtPrivate::PushBackWrapper()).startBlocking(); |
186 | } |
187 | |
188 | // blocking filteredReduced() on sequences |
189 | template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor> |
190 | ResultType blockingFilteredReduced(const Sequence &sequence, |
191 | KeepFunctor keep, |
192 | ReduceFunctor reduce, |
193 | ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) |
194 | { |
195 | return startFilteredReduced<ResultType>(sequence, QtPrivate::createFunctionWrapper(keep), QtPrivate::createFunctionWrapper(reduce), options) |
196 | .startBlocking(); |
197 | } |
198 | |
199 | template <typename Sequence, typename KeepFunctor, typename ReduceFunctor> |
200 | typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType blockingFilteredReduced(const Sequence &sequence, |
201 | KeepFunctor keep, |
202 | ReduceFunctor reduce, |
203 | ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) |
204 | { |
205 | return blockingFilteredReduced<typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType> |
206 | (sequence, |
207 | QtPrivate::createFunctionWrapper(keep), |
208 | QtPrivate::createFunctionWrapper(reduce), |
209 | options); |
210 | } |
211 | |
212 | // blocking filteredReduced() on iterators |
213 | template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor> |
214 | ResultType blockingFilteredReduced(Iterator begin, |
215 | Iterator end, |
216 | KeepFunctor keep, |
217 | ReduceFunctor reduce, |
218 | ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) |
219 | { |
220 | return startFilteredReduced<ResultType> |
221 | (begin, end, |
222 | QtPrivate::createFunctionWrapper(keep), |
223 | QtPrivate::createFunctionWrapper(reduce), |
224 | options) |
225 | .startBlocking(); |
226 | } |
227 | |
228 | template <typename Iterator, typename KeepFunctor, typename ReduceFunctor> |
229 | typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType blockingFilteredReduced(Iterator begin, |
230 | Iterator end, |
231 | KeepFunctor keep, |
232 | ReduceFunctor reduce, |
233 | ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) |
234 | { |
235 | return startFilteredReduced<typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType> |
236 | (begin, end, |
237 | QtPrivate::createFunctionWrapper(keep), |
238 | QtPrivate::createFunctionWrapper(reduce), |
239 | options) |
240 | .startBlocking(); |
241 | } |
242 | |
243 | // blocking filtered() on sequences |
244 | template <typename Sequence, typename KeepFunctor> |
245 | Sequence blockingFiltered(const Sequence &sequence, KeepFunctor keep) |
246 | { |
247 | return startFilteredReduced<Sequence>(sequence, QtPrivate::createFunctionWrapper(keep), QtPrivate::PushBackWrapper(), OrderedReduce).startBlocking(); |
248 | } |
249 | |
250 | // blocking filtered() on iterators |
251 | template <typename OutputSequence, typename Iterator, typename KeepFunctor> |
252 | OutputSequence blockingFiltered(Iterator begin, Iterator end, KeepFunctor keep) |
253 | { |
254 | return startFilteredReduced<OutputSequence>(begin, end, |
255 | QtPrivate::createFunctionWrapper(keep), |
256 | QtPrivate::PushBackWrapper(), |
257 | OrderedReduce).startBlocking(); |
258 | } |
259 | |
260 | } // namespace QtConcurrent |
261 | |
262 | #endif // qdoc |
263 | |
264 | QT_END_NAMESPACE |
265 | QT_END_HEADER |
266 | |
267 | #endif // QT_NO_CONCURRENT |
268 | |
269 | #endif |
270 | |