qtconcurrentfilter.h
上传用户:detong
上传日期:2022-06-22
资源大小:20675k
文件大小:29k
源码类别:

系统编程

开发平台:

Unix_Linux

  1. /****************************************************************************
  2. **
  3. ** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
  4. ** Contact: Qt Software Information (qt-info@nokia.com)
  5. **
  6. ** This file is part of the QtCore module of the Qt Toolkit.
  7. **
  8. ** Commercial Usage
  9. ** Licensees holding valid Qt Commercial licenses may use this file in
  10. ** accordance with the Qt Commercial License Agreement provided with the
  11. ** Software or, alternatively, in accordance with the terms contained in
  12. ** a written agreement between you and Nokia.
  13. **
  14. **
  15. ** GNU General Public License Usage
  16. ** Alternatively, this file may be used under the terms of the GNU
  17. ** General Public License versions 2.0 or 3.0 as published by the Free
  18. ** Software Foundation and appearing in the file LICENSE.GPL included in
  19. ** the packaging of this file.  Please review the following information
  20. ** to ensure GNU General Public Licensing requirements will be met:
  21. ** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
  22. ** http://www.gnu.org/copyleft/gpl.html.  In addition, as a special
  23. ** exception, Nokia gives you certain additional rights. These rights
  24. ** are described in the Nokia Qt GPL Exception version 1.3, included in
  25. ** the file GPL_EXCEPTION.txt in this package.
  26. **
  27. ** Qt for Windows(R) Licensees
  28. ** As a special exception, Nokia, as the sole copyright holder for Qt
  29. ** Designer, grants users of the Qt/Eclipse Integration plug-in the
  30. ** right for the Qt/Eclipse Integration to link to functionality
  31. ** provided by Qt Designer and its related libraries.
  32. **
  33. ** If you are unsure which license is appropriate for your use, please
  34. ** contact the sales department at qt-sales@nokia.com.
  35. **
  36. ****************************************************************************/
  37. #ifndef QTCONCURRENT_FILTER_H
  38. #define QTCONCURRENT_FILTER_H
  39. #include <QtCore/qglobal.h>
  40. #ifndef QT_NO_CONCURRENT
  41. #include <QtCore/qtconcurrentfilterkernel.h>
  42. #include <QtCore/qtconcurrentfunctionwrappers.h>
  43. QT_BEGIN_HEADER
  44. QT_BEGIN_NAMESPACE
  45. QT_MODULE(Core)
  46. #ifdef qdoc
  47. namespace QtConcurrent {
  48.     QFuture<void> filter(Sequence &sequence, FilterFunction filterFunction);
  49.     template <typename T>
  50.     QFuture<T> filtered(const Sequence &sequence, FilterFunction filterFunction);
  51.     template <typename T>
  52.     QFuture<T> filtered(ConstIterator begin, ConstIterator end, FilterFunction filterFunction);
  53.     template <typename T>
  54.     QFuture<T> filteredReduced(const Sequence &sequence,
  55.                                FilterFunction filterFunction,
  56.                                ReduceFunction reduceFunction,
  57.                                QtConcurrent::ReduceOptions reduceOptions = UnorderedReduce | SequentialReduce);
  58.     template <typename T>
  59.     QFuture<T> filteredReduced(ConstIterator begin,
  60.                                ConstIterator end,
  61.                                FilterFunction filterFunction,
  62.                                ReduceFunction reduceFunction,
  63.                                QtConcurrent::ReduceOptions reduceOptions = UnorderedReduce | SequentialReduce);
  64.     void blockingFilter(Sequence &sequence, FilterFunction filterFunction);
  65.     template <typename Sequence>
  66.     Sequence blockingFiltered(const Sequence &sequence, FilterFunction filterFunction);
  67.     template <typename Sequence>
  68.     Sequence blockingFiltered(ConstIterator begin, ConstIterator end, FilterFunction filterFunction);
  69.     template <typename T>
  70.     T blockingFilteredReduced(const Sequence &sequence,
  71.                               FilterFunction filterFunction,
  72.                               ReduceFunction reduceFunction,
  73.                               QtConcurrent::ReduceOptions reduceOptions = UnorderedReduce | SequentialReduce);
  74.     template <typename T>
  75.     T blockingFilteredReduced(ConstIterator begin,
  76.                               ConstIterator end,
  77.                               FilterFunction filterFunction,
  78.                               ReduceFunction reduceFunction,
  79.                               QtConcurrent::ReduceOptions reduceOptions = UnorderedReduce | SequentialReduce);
  80. } // namespace QtConcurrent
  81. #else
  82. namespace QtConcurrent {
  83. template <typename Sequence, typename KeepFunctor, typename T, typename C, typename U>
  84. ThreadEngineStarter<void> filterInternal(Sequence &sequence, KeepFunctor keep, T (C::*reduce)(U))
  85. {
  86.     typedef MemberFunctionWrapper1<T, C, U> ReduceFunctor;
  87.     typedef typename Sequence::const_iterator Iterator;
  88.     typedef FilterKernel<Sequence, KeepFunctor, ReduceFunctor> KernelType;
  89.     return startThreadEngine(new KernelType(sequence, keep, reduce));
  90. }
  91. // filter() on sequences
  92. template <typename Sequence, typename KeepFunctor>
  93. QFuture<void> filter(Sequence &sequence, KeepFunctor keep)
  94. {
  95.     return filterInternal(sequence, keep, &Sequence::push_back);
  96. }
  97. template <typename Sequence, typename T>
  98. QFuture<void> filter(Sequence &sequence, bool (keep)(T))
  99. {
  100.     return filterInternal(sequence, FunctionWrapper1<bool, T>(keep), &Sequence::push_back);
  101. }
  102. template <typename Sequence, typename C>
  103. QFuture<void> filter(Sequence &sequence, bool (C::*keep)() const)
  104. {
  105.     return filterInternal(sequence, ConstMemberFunctionWrapper<bool, C>(keep), &Sequence::push_back);
  106. }
  107. // filteredReduced() on sequences
  108. template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor>
  109. QFuture<ResultType> filteredReduced(const Sequence &sequence,
  110.                                     KeepFunctor keep,
  111.                                     ReduceFunctor reduce,
  112.                                     ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
  113. {
  114.     return startFilteredReduced<ResultType>(sequence, keep, reduce, options);
  115.  }
  116. template <typename ResultType, typename Sequence, typename T, typename ReduceFunctor>
  117. QFuture<ResultType> filteredReduced(const Sequence &sequence,
  118.                                     bool (filter)(T),
  119.                                     ReduceFunctor reduce,
  120.                                     ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
  121. {
  122.     return filteredReduced<ResultType>(sequence,
  123.                                        FunctionWrapper1<bool, T>(filter),
  124.                                        reduce,
  125.                                        options);
  126. }
  127. template <typename ResultType, typename Sequence, typename C, typename ReduceFunctor>
  128. QFuture<ResultType> filteredReduced(const Sequence &sequence,
  129.                                     bool (C::*filter)() const,
  130.                                     ReduceFunctor reduce,
  131.                                     ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
  132. {
  133.     return filteredReduced<ResultType>(sequence,
  134.                                        ConstMemberFunctionWrapper<bool, C>(filter),
  135.                                        reduce,
  136.                                        options);
  137. }
  138. template <typename Sequence, typename KeepFunctor, typename T, typename U, typename V>
  139. QFuture<U> filteredReduced(const Sequence &sequence,
  140.                            KeepFunctor keep,
  141.                            T (reduce)(U &, V),
  142.                            ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
  143. {
  144.     return filteredReduced<U>(sequence,
  145.                               keep,
  146.                               FunctionWrapper2<T, U &, V>(reduce),
  147.                               options);
  148. }
  149. template <typename Sequence, typename KeepFunctor, typename T, typename C, typename U>
  150. QFuture<C> filteredReduced(const Sequence &sequence,
  151.                            KeepFunctor keep,
  152.                            T (C::*reduce)(U),
  153.                            ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
  154. {
  155.     return filteredReduced<C>(sequence,
  156.                               keep,
  157.                               MemberFunctionWrapper1<T, C, U>(reduce),
  158.                               options);
  159. }
  160. template <typename Sequence, typename T, typename U, typename V, typename W>
  161. QFuture<V> filteredReduced(const Sequence &sequence,
  162.                            bool (keep)(T),
  163.                            U (reduce)(V &, W),
  164.                            ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
  165. {
  166.     return filteredReduced<V>(sequence,
  167.                               FunctionWrapper1<bool, T>(keep),
  168.                               FunctionWrapper2<U, V &, W>(reduce),
  169.                               options);
  170. }
  171. template <typename Sequence, typename C, typename T, typename U, typename V>
  172. QFuture<U> filteredReduced(const Sequence &sequence,
  173.                            bool (C::*keep)() const,
  174.                            T (reduce)(U &, V),
  175.                            ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
  176. {
  177.     return filteredReduced<U>(sequence,
  178.                               ConstMemberFunctionWrapper<bool, C>(keep),
  179.                               FunctionWrapper2<T, U &, V>(reduce),
  180.                               options);
  181. }
  182. template <typename Sequence, typename T, typename U, typename C, typename V>
  183. QFuture<C> filteredReduced(const Sequence &sequence,
  184.                            bool (keep)(T),
  185.                            U (C::*reduce)(V),
  186.                            ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
  187. {
  188.     return filteredReduced<C>(sequence,
  189.                               FunctionWrapper1<bool, T>(keep),
  190.                               MemberFunctionWrapper1<U, C, V>(reduce),
  191.                               options);
  192. }
  193. template <typename Sequence, typename C, typename T, typename D, typename U>
  194. QFuture<D> filteredReduced(const Sequence &sequence,
  195.                            bool (C::*keep)() const,
  196.                            T (D::*reduce)(U),
  197.                            ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
  198. {
  199.     return filteredReduced<D>(sequence,
  200.                               ConstMemberFunctionWrapper<bool, C>(keep),
  201.                               MemberFunctionWrapper1<T, D, U>(reduce),
  202.                               options);
  203. }
  204. // filteredReduced() on iterators
  205. template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor>
  206. QFuture<ResultType> filteredReduced(Iterator begin,
  207.                                     Iterator end,
  208.                                     KeepFunctor keep,
  209.                                     ReduceFunctor reduce,
  210.                                     ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
  211. {
  212.    return startFilteredReduced<ResultType>(begin, end, keep, reduce, options);
  213. }
  214. template <typename ResultType, typename Iterator, typename T, typename ReduceFunctor>
  215. QFuture<ResultType> filteredReduced(Iterator begin,
  216.                                     Iterator end,
  217.                                     bool (filter)(T),
  218.                                     ReduceFunctor reduce,
  219.                                     ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
  220. {
  221.     return filteredReduced<ResultType>(begin,
  222.                                        end,
  223.                                        FunctionWrapper1<bool, T>(filter),
  224.                                        reduce,
  225.                                        options);
  226. }
  227. template <typename ResultType, typename Iterator, typename C, typename ReduceFunctor>
  228. QFuture<ResultType> filteredReduced(Iterator begin,
  229.                                     Iterator end,
  230.                                     bool (C::*filter)() const,
  231.                                     ReduceFunctor reduce,
  232.                                     ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
  233. {
  234.     return filteredReduced<ResultType>(begin,
  235.                                        end,
  236.                                        ConstMemberFunctionWrapper<bool, C>(filter),
  237.                                        reduce,
  238.                                        options);
  239. }
  240. template <typename Iterator, typename KeepFunctor, typename T, typename U, typename V>
  241. QFuture<U> filteredReduced(Iterator begin,
  242.                            Iterator end,
  243.                            KeepFunctor keep,
  244.                            T (reduce)(U &, V),
  245.                            ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
  246. {
  247.     return filteredReduced<U>(begin,
  248.                               end,
  249.                               keep,
  250.                               FunctionWrapper2<T, U &, V>(reduce),
  251.                               options);
  252. }
  253. template <typename Iterator, typename KeepFunctor, typename T, typename C, typename U>
  254. QFuture<C> filteredReduced(Iterator begin,
  255.                            Iterator end,
  256.                            KeepFunctor keep,
  257.                            T (C::*reduce)(U),
  258.                            ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
  259. {
  260.     return filteredReduced<C>(begin,
  261.                               end,
  262.                               keep,
  263.                               MemberFunctionWrapper1<T, C, U>(reduce),
  264.                               options);
  265. }
  266. template <typename Iterator, typename T, typename U, typename V, typename W>
  267. QFuture<V> filteredReduced(Iterator begin,
  268.                            Iterator end,
  269.                            bool (keep)(T),
  270.                            U (reduce)(V &, W),
  271.                            ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
  272. {
  273.     return filteredReduced<V>(begin,
  274.                               end,
  275.                               FunctionWrapper1<bool, T>(keep),
  276.                               FunctionWrapper2<U, V &, W>(reduce),
  277.                               options);
  278. }
  279. template <typename Iterator, typename C, typename T, typename U, typename V>
  280. QFuture<U> filteredReduced(Iterator begin,
  281.                            Iterator end,
  282.                            bool (C::*keep)() const,
  283.                            T (reduce)(U &, V),
  284.                            ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
  285. {
  286.     return filteredReduced<U>(begin,
  287.                               end,
  288.                               ConstMemberFunctionWrapper<bool, C>(keep),
  289.                               FunctionWrapper2<T, U &, V>(reduce),
  290.                               options);
  291. }
  292. template <typename Iterator, typename T, typename U, typename C, typename V>
  293. QFuture<C> filteredReduced(Iterator begin,
  294.                            Iterator end,
  295.                            bool (keep)(T),
  296.                            U (C::*reduce)(V),
  297.                            ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
  298. {
  299.     return filteredReduced<C>(begin,
  300.                               end,
  301.                               FunctionWrapper1<bool, T>(keep),
  302.                               MemberFunctionWrapper1<U, C, V>(reduce),
  303.                               options);
  304. }
  305. template <typename Iterator, typename C, typename T, typename D, typename U>
  306. QFuture<D> filteredReduced(Iterator begin,
  307.                            Iterator end,
  308.                            bool (C::*keep)() const,
  309.                            T (D::*reduce)(U),
  310.                            ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
  311. {
  312.     return filteredReduced<D>(begin,
  313.                               end,
  314.                               ConstMemberFunctionWrapper<bool, C>(keep),
  315.                               MemberFunctionWrapper1<T, D, U>(reduce),
  316.                               options);
  317. }
  318. // filtered() on sequences
  319. template <typename Sequence, typename KeepFunctor>
  320. QFuture<typename Sequence::value_type> filtered(const Sequence &sequence, KeepFunctor keep)
  321. {
  322.     return startFiltered(sequence, keep);
  323. }
  324. template <typename Sequence, typename T>
  325. QFuture<typename Sequence::value_type> filtered(const Sequence &sequence, bool (keep)(T))
  326. {
  327.     return startFiltered(sequence, FunctionWrapper1<bool, T>(keep));
  328. }
  329. template <typename Sequence, typename C>
  330. QFuture<typename Sequence::value_type> filtered(const Sequence &sequence, bool (C::*keep)() const)
  331. {
  332.     return startFiltered(sequence, ConstMemberFunctionWrapper<bool, C>(keep));
  333. }
  334. // filtered() on iterators
  335. template <typename Iterator, typename KeepFunctor>
  336. QFuture<typename qValueType<Iterator>::value_type> filtered(Iterator begin, Iterator end, KeepFunctor keep)
  337. {
  338.     return startFiltered(begin, end, keep);
  339. }
  340. template <typename Iterator, typename T>
  341. QFuture<typename qValueType<Iterator>::value_type> filtered(Iterator begin, Iterator end, bool (keep)(T))
  342. {
  343.     return startFiltered(begin, end, FunctionWrapper1<bool, T>(keep));
  344. }
  345. template <typename Iterator, typename C>
  346. QFuture<typename qValueType<Iterator>::value_type> filtered(Iterator begin,
  347.                                                 Iterator end,
  348.                                                 bool (C::*keep)() const)
  349. {
  350.     return startFiltered(begin, end, ConstMemberFunctionWrapper<bool, C>(keep));
  351. }
  352. // blocking filter() on sequences
  353. template <typename Sequence, typename KeepFunctor>
  354. void blockingFilter(Sequence &sequence, KeepFunctor keep)
  355. {
  356.     filterInternal(sequence, keep, &Sequence::push_back).startBlocking();
  357. }
  358. template <typename Sequence, typename T>
  359. void blockingFilter(Sequence &sequence, bool (keep)(T))
  360. {
  361.     filterInternal(sequence, FunctionWrapper1<bool, T>(keep), &Sequence::push_back)
  362.         .startBlocking();
  363. }
  364. template <typename Sequence, typename C>
  365. void blockingFilter(Sequence &sequence, bool (C::*keep)() const)
  366. {
  367.     filterInternal(sequence,
  368.                    ConstMemberFunctionWrapper<bool, C>(keep),
  369.                    &Sequence::push_back)
  370.         .startBlocking();
  371. }
  372. // blocking filteredReduced() on sequences
  373. template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor>
  374. ResultType blockingFilteredReduced(const Sequence &sequence,
  375.                                    KeepFunctor keep,
  376.                                    ReduceFunctor reduce,
  377.                                    ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
  378. {
  379.     return startFilteredReduced<ResultType>(sequence, keep, reduce, options)
  380.         .startBlocking();
  381. }
  382. template <typename ResultType, typename Sequence, typename T, typename ReduceFunctor>
  383. ResultType blockingFilteredReduced(const Sequence &sequence,
  384.                                    bool (filter)(T),
  385.                                    ReduceFunctor reduce,
  386.                                    ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
  387. {
  388.     return blockingFilteredReduced<ResultType>
  389.         (sequence,
  390.          FunctionWrapper1<bool, T>(filter),
  391.          reduce,
  392.          options);
  393. }
  394. template <typename ResultType, typename Sequence, typename C, typename ReduceFunctor>
  395. ResultType blockingFilteredReduced(const Sequence &sequence,
  396.                                    bool (C::*filter)() const,
  397.                                    ReduceFunctor reduce,
  398.                                    ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
  399. {
  400.     return blockingFilteredReduced<ResultType>
  401.         (sequence,
  402.          ConstMemberFunctionWrapper<bool, C>(filter),
  403.          reduce,
  404.          options);
  405. }
  406. template <typename Sequence, typename KeepFunctor, typename T, typename U, typename V>
  407. U blockingFilteredReduced(const Sequence &sequence,
  408.                           KeepFunctor keep,
  409.                           T (reduce)(U &, V),
  410.                           ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
  411. {
  412.     return blockingFilteredReduced<U>
  413.         (sequence,
  414.          keep,
  415.          FunctionWrapper2<T, U &, V>(reduce),
  416.          options);
  417. }
  418. template <typename Sequence, typename KeepFunctor, typename T, typename C, typename U>
  419. C blockingFilteredReduced(const Sequence &sequence,
  420.                           KeepFunctor keep,
  421.                           T (C::*reduce)(U),
  422.                           ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
  423. {
  424.     return blockingFilteredReduced<C>
  425.         (sequence,
  426.          keep,
  427.          MemberFunctionWrapper1<T, C, U>(reduce),
  428.          options);
  429. }
  430. template <typename Sequence, typename T, typename U, typename V, typename W>
  431. V blockingFilteredReduced(const Sequence &sequence,
  432.                           bool (keep)(T),
  433.                           U (reduce)(V &, W),
  434.                           ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
  435. {
  436.     return blockingFilteredReduced<V>
  437.         (sequence,
  438.          FunctionWrapper1<bool, T>(keep),
  439.          FunctionWrapper2<U, V &, W>(reduce),
  440.          options);
  441. }
  442. template <typename Sequence, typename C, typename T, typename U, typename V>
  443. U blockingFilteredReduced(const Sequence &sequence,
  444.                           bool (C::*keep)() const,
  445.                           T (reduce)(U &, V),
  446.                           ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
  447. {
  448.     return blockingFilteredReduced<U>
  449.         (sequence,
  450.          ConstMemberFunctionWrapper<bool, C>(keep),
  451.          FunctionWrapper2<T, U &, V>(reduce),
  452.          options);
  453. }
  454. template <typename Sequence, typename T, typename U, typename C, typename V>
  455. C blockingFilteredReduced(const Sequence &sequence,
  456.                           bool (keep)(T),
  457.                           U (C::*reduce)(V),
  458.                           ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
  459. {
  460.     return blockingFilteredReduced<C>
  461.         (sequence,
  462.          FunctionWrapper1<bool, T>(keep),
  463.          MemberFunctionWrapper1<U, C, V>(reduce),
  464.          options);
  465. }
  466. template <typename Sequence, typename C, typename T, typename D, typename U>
  467. D blockingFilteredReduced(const Sequence &sequence,
  468.                           bool (C::*keep)() const,
  469.                           T (D::*reduce)(U),
  470.                           ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
  471. {
  472.     return blockingFilteredReduced<D>
  473.         (sequence,
  474.          ConstMemberFunctionWrapper<bool, C>(keep),
  475.          MemberFunctionWrapper1<T, D, U>(reduce),
  476.          options);
  477. }
  478. // blocking filteredReduced() on iterators
  479. template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor>
  480. ResultType blockingFilteredReduced(Iterator begin,
  481.                                    Iterator end,
  482.                                    KeepFunctor keep,
  483.                                    ReduceFunctor reduce,
  484.                                    ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
  485. {
  486.     return startFilteredReduced<ResultType>(begin, end, keep, reduce, options)
  487.         .startBlocking();
  488. }
  489. template <typename ResultType, typename Iterator, typename T, typename ReduceFunctor>
  490. ResultType blockingFilteredReduced(Iterator begin,
  491.                                    Iterator end,
  492.                                    bool (filter)(T),
  493.                                    ReduceFunctor reduce,
  494.                                    ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
  495. {
  496.     return blockingFilteredReduced<ResultType>
  497.         (begin,
  498.          end,
  499.          FunctionWrapper1<bool, T>(filter),
  500.          reduce,
  501.          options);
  502. }
  503. template <typename ResultType, typename Iterator, typename C, typename ReduceFunctor>
  504. ResultType blockingFilteredReduced(Iterator begin,
  505.                                    Iterator end,
  506.                                    bool (C::*filter)() const,
  507.                                    ReduceFunctor reduce,
  508.                                    ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
  509. {
  510.     return blockingFilteredReduced<ResultType>
  511.         (begin,
  512.          end,
  513.          ConstMemberFunctionWrapper<bool, C>(filter),
  514.          reduce,
  515.          options);
  516. }
  517. template <typename Iterator, typename KeepFunctor, typename T, typename U, typename V>
  518. U blockingFilteredReduced(Iterator begin,
  519.                           Iterator end,
  520.                           KeepFunctor keep,
  521.                           T (reduce)(U &, V),
  522.                           ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
  523. {
  524.     return blockingFilteredReduced<U>
  525.         (begin,
  526.          end,
  527.          keep,
  528.          FunctionWrapper2<T, U &, V>(reduce),
  529.          options);
  530. }
  531. template <typename Iterator, typename KeepFunctor, typename T, typename C, typename U>
  532. C blockingFilteredReduced(Iterator begin,
  533.                           Iterator end,
  534.                           KeepFunctor keep,
  535.                           T (C::*reduce)(U),
  536.                           ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
  537. {
  538.     return blockingFilteredReduced<C>
  539.         (begin,
  540.          end,
  541.          keep,
  542.          MemberFunctionWrapper1<T, C, U>(reduce),
  543.          options);
  544. }
  545. template <typename Iterator, typename T, typename U, typename V, typename W>
  546. V blockingFilteredReduced(Iterator begin,
  547.                           Iterator end,
  548.                           bool (keep)(T),
  549.                           U (reduce)(V &, W),
  550.                           ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
  551. {
  552.     return blockingFilteredReduced<V>
  553.         (begin,
  554.          end,
  555.          FunctionWrapper1<bool, T>(keep),
  556.          FunctionWrapper2<U, V &, W>(reduce),
  557.          options);
  558. }
  559. template <typename Iterator, typename C, typename T, typename U, typename V>
  560. U blockingFilteredReduced(Iterator begin,
  561.                           Iterator end,
  562.                           bool (C::*keep)() const,
  563.                           T (reduce)(U &, V),
  564.                           ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
  565. {
  566.     return blockingFilteredReduced<U>
  567.         (begin,
  568.          end,
  569.          ConstMemberFunctionWrapper<bool, C>(keep),
  570.          FunctionWrapper2<T, U &, V>(reduce),
  571.          options);
  572. }
  573. template <typename Iterator, typename T, typename U, typename C, typename V>
  574. C blockingFilteredReduced(Iterator begin,
  575.                           Iterator end,
  576.                           bool (keep)(T),
  577.                           U (C::*reduce)(V),
  578.                           ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
  579. {
  580.     return blockingFilteredReduced<C>
  581.         (begin,
  582.          end,
  583.          FunctionWrapper1<bool, T>(keep),
  584.          MemberFunctionWrapper1<U, C, V>(reduce),
  585.          options);
  586. }
  587. template <typename Iterator, typename C, typename T, typename D, typename U>
  588. D blockingFilteredReduced(Iterator begin,
  589.                           Iterator end,
  590.                           bool (C::*keep)() const,
  591.                           T (D::*reduce)(U),
  592.                           ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
  593. {
  594.     return blockingFilteredReduced<D>
  595.         (begin,
  596.          end,
  597.          ConstMemberFunctionWrapper<bool, C>(keep),
  598.          MemberFunctionWrapper1<T, D, U>(reduce),
  599.          options);
  600. }
  601. // blocking filtered() on sequences
  602. template <typename Sequence, typename KeepFunctor>
  603. Sequence blockingFiltered(const Sequence &sequence, KeepFunctor keep)
  604. {
  605.     return blockingFilteredReduced(sequence, keep, &Sequence::push_back, OrderedReduce);
  606. }
  607. template <typename Sequence, typename T>
  608. Sequence blockingFiltered(const Sequence &sequence, bool (keep)(T))
  609. {
  610.     return blockingFilteredReduced(sequence, keep, &Sequence::push_back, OrderedReduce);
  611. }
  612. template <typename Sequence, typename C>
  613. Sequence blockingFiltered(const Sequence &sequence, bool (C::*filter)() const)
  614. {
  615.     return blockingFilteredReduced(sequence,
  616.                                    filter,
  617.                                    &Sequence::push_back,
  618.                                    OrderedReduce);
  619. }
  620. // blocking filtered() on iterators
  621. template <typename OutputSequence, typename Iterator, typename KeepFunctor>
  622. OutputSequence blockingFiltered(Iterator begin, Iterator end, KeepFunctor keep)
  623. {
  624.     return blockingFilteredReduced(begin,
  625.                                    end,
  626.                                    keep,
  627.                                    &OutputSequence::push_back,
  628.                                    OrderedReduce);
  629. }
  630. template <typename OutputSequence, typename Iterator, typename T>
  631. OutputSequence blockingFiltered(Iterator begin, Iterator end, bool (keep)(T))
  632. {
  633.     return blockingFilteredReduced(begin,
  634.                                    end,
  635.                                    keep,
  636.                                    &OutputSequence::push_back,
  637.                                    OrderedReduce);
  638. }
  639. template <typename OutputSequence, typename Iterator, typename C>
  640. OutputSequence blockingFiltered(Iterator begin, Iterator end, bool (C::*filter)() const)
  641. {
  642.     return blockingFilteredReduced(begin,
  643.                                    end,
  644.                                    filter,
  645.                                    &OutputSequence::push_back,
  646.                                    OrderedReduce);
  647. }
  648. } // namespace QtConcurrent
  649. #endif // qdoc
  650. QT_END_NAMESPACE
  651. QT_END_HEADER
  652. #endif // QT_NO_CONCURRENT
  653. #endif