QtConcurrent
Trial to use Doxygen to generate UML class diagram of QtConcurrent module.
qtconcurrentfilter.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_FILTER_H
41 #define QTCONCURRENT_FILTER_H
42 
43 #include <QtConcurrent/qtconcurrent_global.h>
44 
45 #if !defined(QT_NO_CONCURRENT) || defined(Q_CLANG_QDOC)
46 
47 #include <QtConcurrent/qtconcurrentfilterkernel.h>
48 #include <QtConcurrent/qtconcurrentfunctionwrappers.h>
49 
50 QT_BEGIN_NAMESPACE
51 
52 namespace QtConcurrent {
53 
55 template <typename Sequence, typename KeepFunctor, typename ReduceFunctor>
56 ThreadEngineStarter<void> filterInternal(Sequence &sequence, KeepFunctor keep, ReduceFunctor reduce)
57 {
59  return startThreadEngine(new KernelType(sequence, keep, reduce));
60 }
61 
62 // filter() on sequences
63 template <typename Sequence, typename KeepFunctor>
64 QFuture<void> filter(Sequence &sequence, KeepFunctor keep)
65 {
67 }
68 
69 // filteredReduced() on sequences
70 template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor>
71 QFuture<ResultType> filteredReduced(const Sequence &sequence,
72  KeepFunctor keep,
73  ReduceFunctor reduce,
74  ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
75 {
76  return startFilteredReduced<ResultType>(sequence, QtPrivate::createFunctionWrapper(keep), QtPrivate::createFunctionWrapper(reduce), options);
77 }
78 
79 #ifndef Q_CLANG_QDOC
80 template <typename Sequence, typename KeepFunctor, typename ReduceFunctor>
81 QFuture<typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType> filteredReduced(const Sequence &sequence,
82  KeepFunctor keep,
83  ReduceFunctor reduce,
84  ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
85 {
86  return startFilteredReduced<typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType>
87  (sequence,
90  options);
91 }
92 #endif
93 
94 // filteredReduced() on iterators
95 template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor>
96 QFuture<ResultType> filteredReduced(Iterator begin,
97  Iterator end,
98  KeepFunctor keep,
99  ReduceFunctor reduce,
100  ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
101 {
102  return startFilteredReduced<ResultType>(begin, end, QtPrivate::createFunctionWrapper(keep), QtPrivate::createFunctionWrapper(reduce), options);
103 }
104 
105 #ifndef Q_CLANG_QDOC
106 template <typename Iterator, typename KeepFunctor, typename ReduceFunctor>
107 QFuture<typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType> filteredReduced(Iterator begin,
108  Iterator end,
109  KeepFunctor keep,
110  ReduceFunctor reduce,
111  ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
112 {
113  return startFilteredReduced<typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType>
114  (begin, end,
117  options);
118 }
119 #endif
120 
121 // filtered() on sequences
122 template <typename Sequence, typename KeepFunctor>
123 QFuture<typename Sequence::value_type> filtered(const Sequence &sequence, KeepFunctor keep)
124 {
125  return startFiltered(sequence, QtPrivate::createFunctionWrapper(keep));
126 }
127 
128 // filtered() on iterators
129 template <typename Iterator, typename KeepFunctor>
130 QFuture<typename qValueType<Iterator>::value_type> filtered(Iterator begin, Iterator end, KeepFunctor keep)
131 {
132  return startFiltered(begin, end, QtPrivate::createFunctionWrapper(keep));
133 }
134 
135 // blocking filter() on sequences
136 template <typename Sequence, typename KeepFunctor>
137 void blockingFilter(Sequence &sequence, KeepFunctor keep)
138 {
140 }
141 
142 // blocking filteredReduced() on sequences
143 template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor>
144 ResultType blockingFilteredReduced(const Sequence &sequence,
145  KeepFunctor keep,
146  ReduceFunctor reduce,
147  ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
148 {
149  return startFilteredReduced<ResultType>(sequence, QtPrivate::createFunctionWrapper(keep), QtPrivate::createFunctionWrapper(reduce), options)
150  .startBlocking();
151 }
152 
153 #ifndef Q_CLANG_QDOC
154 template <typename Sequence, typename KeepFunctor, typename ReduceFunctor>
156  KeepFunctor keep,
157  ReduceFunctor reduce,
158  ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
159 {
160  return blockingFilteredReduced<typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType>
161  (sequence,
164  options);
165 }
166 #endif
167 
168 // blocking filteredReduced() on iterators
169 template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor>
170 ResultType blockingFilteredReduced(Iterator begin,
171  Iterator end,
172  KeepFunctor keep,
173  ReduceFunctor reduce,
174  ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
175 {
176  return startFilteredReduced<ResultType>
177  (begin, end,
180  options)
181  .startBlocking();
182 }
183 
184 #ifndef Q_CLANG_QDOC
185 template <typename Iterator, typename KeepFunctor, typename ReduceFunctor>
187  Iterator end,
188  KeepFunctor keep,
189  ReduceFunctor reduce,
190  ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
191 {
192  return startFilteredReduced<typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType>
193  (begin, end,
196  options)
197  .startBlocking();
198 }
199 #endif
200 
201 // blocking filtered() on sequences
202 template <typename Sequence, typename KeepFunctor>
203 Sequence blockingFiltered(const Sequence &sequence, KeepFunctor keep)
204 {
205  return startFilteredReduced<Sequence>(sequence, QtPrivate::createFunctionWrapper(keep), QtPrivate::PushBackWrapper(), OrderedReduce).startBlocking();
206 }
207 
208 // blocking filtered() on iterators
209 template <typename OutputSequence, typename Iterator, typename KeepFunctor>
210 OutputSequence blockingFiltered(Iterator begin, Iterator end, KeepFunctor keep)
211 {
212  return startFilteredReduced<OutputSequence>(begin, end,
215  OrderedReduce).startBlocking();
216 }
217 
218 } // namespace QtConcurrent
219 
220 QT_END_NAMESPACE
221 
222 #endif // QT_NO_CONCURRENT
223 
224 #endif
Definition: qtconcurrentfilterkernel.h:77
QFuture< typename Sequence::value_type > filtered(const Sequence &sequence, KeepFunctor keep)
Definition: qtconcurrentfilter.h:123
Definition: qtconcurrentfunctionwrappers.h:243
const T & createFunctionWrapper(const T &t)
Definition: qtconcurrentfunctionwrappers.h:163
Definition: qtconcurrentreducekernel.h:93
Definition: qtconcurrentfunctionwrappers.h:218
ThreadEngineStarter< typename ThreadEngine::ResultType > startThreadEngine(ThreadEngine *threadEngine)
[qtconcurrentthreadengine-1]
Definition: qtconcurrentthreadengine.h:262
Sequence blockingFiltered(const Sequence &sequence, KeepFunctor keep)
Definition: qtconcurrentfilter.h:203
Definition: qtconcurrentthreadengine.h:247
ThreadEngineStarter< typename qValueType< Iterator >::value_type > startFiltered(Iterator begin, Iterator end, KeepFunctor functor)
[QtConcurrent-2]
Definition: qtconcurrentfilterkernel.h:298
QFuture< void > filter(Sequence &sequence, KeepFunctor keep)
Definition: qtconcurrentfilter.h:64
ThreadEngineStarter< void > filterInternal(Sequence &sequence, KeepFunctor keep, ReduceFunctor reduce)
[QtConcurrent-1]
Definition: qtconcurrentfilter.h:56
Definition: qtconcurrentreducekernel.h:91
QFuture< ResultType > filteredReduced(const Sequence &sequence, KeepFunctor keep, ReduceFunctor reduce, ReduceOptions options=ReduceOptions(UnorderedReduce|SequentialReduce))
Definition: qtconcurrentfilter.h:71
The QtConcurrent namespace provides high-level APIs that make it possible to write multi-threaded pro...
Definition: qtconcurrentexception.h:51
Definition: qtconcurrentreducekernel.h:92
ResultType blockingFilteredReduced(const Sequence &sequence, KeepFunctor keep, ReduceFunctor reduce, ReduceOptions options=ReduceOptions(UnorderedReduce|SequentialReduce))
Definition: qtconcurrentfilter.h:144
void blockingFilter(Sequence &sequence, KeepFunctor keep)
Definition: qtconcurrentfilter.h:137
void startBlocking()
Definition: qtconcurrentthreadengine.h:253