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

系统编程

开发平台:

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_MAP_H
  38. #define QTCONCURRENT_MAP_H
  39. #include <QtCore/qglobal.h>
  40. #ifndef QT_NO_CONCURRENT
  41. #include <QtCore/qtconcurrentmapkernel.h>
  42. #include <QtCore/qtconcurrentreducekernel.h>
  43. #include <QtCore/qtconcurrentfunctionwrappers.h>
  44. #include <QtCore/qstringlist.h>
  45. QT_BEGIN_HEADER
  46. QT_BEGIN_NAMESPACE
  47. QT_MODULE(Core)
  48. #ifdef qdoc
  49. namespace QtConcurrent {
  50.     QFuture<void> map(Sequence &sequence, MapFunction function);
  51.     QFuture<void> map(Iterator begin, Iterator end, MapFunction function);
  52.     template <typename T>
  53.     QFuture<T> mapped(const Sequence &sequence, MapFunction function);
  54.     template <typename T>
  55.     QFuture<T> mapped(ConstIterator begin, ConstIterator end, MapFunction function);
  56.     template <typename T>
  57.     QFuture<T> mappedReduced(const Sequence &sequence,
  58.                              MapFunction function,
  59.                              ReduceFunction function,
  60.                              QtConcurrent::ReduceOptions options = UnorderedReduce | SequentialReduce);
  61.     template <typename T>
  62.     QFuture<T> mappedReduced(ConstIterator begin,
  63.                              ConstIterator end,
  64.                              MapFunction function,
  65.                              ReduceFunction function,
  66.                              QtConcurrent::ReduceOptions options = UnorderedReduce | SequentialReduce);
  67.     void blockingMap(Sequence &sequence, MapFunction function);
  68.     void blockingMap(Iterator begin, Iterator end, MapFunction function);
  69.     template <typename T>
  70.     T blockingMapped(const Sequence &sequence, MapFunction function);
  71.     template <typename T>
  72.     T blockingMapped(ConstIterator begin, ConstIterator end, MapFunction function);
  73.     template <typename T>
  74.     T blockingMappedReduced(const Sequence &sequence,
  75.                             MapFunction function,
  76.                             ReduceFunction function,
  77.                             QtConcurrent::ReduceOptions options = UnorderedReduce | SequentialReduce);
  78.     template <typename T>
  79.     T blockingMappedReduced(ConstIterator begin,
  80.                             ConstIterator end,
  81.                             MapFunction function,
  82.                             ReduceFunction function,
  83.                             QtConcurrent::ReduceOptions options = UnorderedReduce | SequentialReduce);
  84. } // namespace QtConcurrent
  85. #else
  86. namespace QtConcurrent {
  87. // map() on sequences
  88. template <typename Sequence, typename MapFunctor>
  89. QFuture<void> map(Sequence &sequence, MapFunctor map)
  90. {
  91.     return startMap(sequence.begin(), sequence.end(), map);
  92. }
  93. template <typename Sequence, typename T, typename U>
  94. QFuture<void> map(Sequence &sequence, T (map)(U))
  95. {
  96.     return startMap(sequence.begin(), sequence.end(), FunctionWrapper1<T, U>(map));
  97. }
  98. template <typename Sequence, typename T, typename C>
  99. QFuture<void> map(Sequence &sequence, T (C::*map)())
  100. {
  101.     return startMap(sequence.begin(), sequence.end(), MemberFunctionWrapper<T, C>(map));
  102. }
  103. // map() on iterators
  104. template <typename Iterator, typename MapFunctor>
  105. QFuture<void> map(Iterator begin, Iterator end, MapFunctor map)
  106. {
  107.     return startMap(begin, end, map);
  108. }
  109. template <typename Iterator, typename T, typename U>
  110. QFuture<void> map(Iterator begin, Iterator end, T (map)(U))
  111. {
  112.     return startMap(begin, end, FunctionWrapper1<T, U>(map));
  113. }
  114. template <typename Iterator, typename T, typename C>
  115. QFuture<void> map(Iterator begin, Iterator end, T (C::*map)())
  116. {
  117.     return startMap(begin, end, MemberFunctionWrapper<T, C>(map));
  118. }
  119. // mappedReduced() for sequences.
  120. template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor>
  121. QFuture<ResultType> mappedReduced(const Sequence &sequence,
  122.                                   MapFunctor map,
  123.                                   ReduceFunctor reduce,
  124.                                   ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
  125. {
  126.     return startMappedReduced<typename MapFunctor::result_type, ResultType>
  127.     (sequence, map, reduce, options);
  128. }
  129. template <typename Sequence, typename MapFunctor, typename T, typename U, typename V>
  130. QFuture<U> mappedReduced(const Sequence &sequence,
  131.                          MapFunctor map,
  132.                          T (reduce)(U &, V),
  133.                          ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
  134. {
  135.     return startMappedReduced<typename MapFunctor::result_type, U>
  136.     (sequence, map, FunctionWrapper2<T, U &, V>(reduce), options);
  137. }
  138. template <typename Sequence, typename MapFunctor, typename T, typename C, typename U>
  139. QFuture<C> mappedReduced(const Sequence &sequence,
  140.                          MapFunctor map,
  141.                          T (C::*reduce)(U),
  142.                          ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
  143. {
  144.     return startMappedReduced<typename MapFunctor::result_type, C>
  145.     (sequence, map, MemberFunctionWrapper1<T, C, U>(reduce), options);
  146. }
  147. template <typename ResultType, typename Sequence, typename T, typename U, typename ReduceFunctor>
  148. QFuture<ResultType> mappedReduced(const Sequence &sequence,
  149.                                   T (map)(U),
  150.                                   ReduceFunctor reduce,
  151.                                   ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
  152. {
  153.     return startMappedReduced<T, ResultType>
  154.     (sequence, FunctionWrapper1<T, U>(map), reduce, options);
  155. }
  156. template <typename ResultType, typename Sequence, typename T, typename C, typename ReduceFunctor>
  157. QFuture<ResultType> mappedReduced(const Sequence &sequence,
  158.                                   T (C::*map)() const,
  159.                                   ReduceFunctor reduce,
  160.                                   ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
  161. {
  162.     return startMappedReduced<T, ResultType>
  163.     (sequence, ConstMemberFunctionWrapper<T, C>(map), reduce, options);
  164. }
  165. template <typename Sequence, typename T, typename U, typename V, typename W, typename X>
  166. QFuture<W> mappedReduced(const Sequence &sequence,
  167.                          T (map)(U),
  168.                          V (reduce)(W &, X),
  169.                          ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
  170. {
  171.     return startMappedReduced<T, W>
  172.     (sequence, FunctionWrapper1<T, U>(map), FunctionWrapper2<V, W &, X>(reduce), options);
  173. }
  174. template <typename Sequence, typename T, typename C, typename U, typename V, typename W>
  175. QFuture<V> mappedReduced(const Sequence &sequence,
  176.                          T (C::*map)() const,
  177.                          U (reduce)(V &, W),
  178.                          ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
  179. {
  180.     return startMappedReduced<T, V> (sequence, ConstMemberFunctionWrapper<T, C>(map),
  181.                                     FunctionWrapper2<U, V &, W>(reduce), options);
  182. }
  183. template <typename Sequence, typename T, typename U, typename V, typename C, typename W>
  184. QFuture<C> mappedReduced(const Sequence &sequence,
  185.                          T (map)(U),
  186.                          V (C::*reduce)(W),
  187.                          ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
  188. {
  189.     return startMappedReduced<T, C> (sequence, FunctionWrapper1<T, U>(map),
  190.                                      MemberFunctionWrapper1<V, C, W>(reduce), options);
  191. }
  192. template <typename Sequence, typename T, typename C, typename U,typename D, typename V>
  193. QFuture<D> mappedReduced(const Sequence &sequence,
  194.                          T (C::*map)() const,
  195.                          U (D::*reduce)(V),
  196.                          ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
  197. {
  198.     return startMappedReduced<T, D>(sequence, ConstMemberFunctionWrapper<T, C>(map),
  199.                                     MemberFunctionWrapper1<U, D, V>(reduce), options);
  200. }
  201. // mappedReduced() for iterators
  202. template <typename ResultType, typename Iterator, typename MapFunctor, typename ReduceFunctor>
  203. QFuture<ResultType> mappedReduced(Iterator begin,
  204.                                   Iterator end,
  205.                                   MapFunctor map,
  206.                                   ReduceFunctor reduce,
  207.                                   ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
  208. {
  209.     return startMappedReduced<ResultType, typename MapFunctor::result_type>
  210.     (begin, end, map, reduce, options);
  211. }
  212. template <typename Iterator, typename MapFunctor, typename T, typename U, typename V>
  213. QFuture<U> mappedReduced(Iterator begin,
  214.                          Iterator end,
  215.                          MapFunctor map,
  216.                          T (reduce)(U &, V),
  217.                          ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
  218. {
  219.     return startMappedReduced<typename MapFunctor::result_type, U>
  220.     (begin, end, map, FunctionWrapper2<T, U &, V>(reduce), options);
  221. }
  222. template <typename Iterator, typename MapFunctor, typename T, typename C, typename U>
  223. QFuture<C> mappedReduced(Iterator begin,
  224.                          Iterator end,
  225.                          MapFunctor map,
  226.                          T (C::*reduce)(U),
  227.                          ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
  228. {
  229.     return startMappedReduced<typename MapFunctor::result_type, C>
  230.     (begin, end, map, MemberFunctionWrapper1<T, C, U>(reduce), options);
  231. }
  232. template <typename ResultType, typename Iterator, typename T, typename U, typename ReduceFunctor>
  233. QFuture<ResultType> mappedReduced(Iterator begin,
  234.                                   Iterator end,
  235.                                   T (map)(U),
  236.                                   ReduceFunctor reduce,
  237.                                   ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
  238. {
  239.     return startMappedReduced<T, ResultType>
  240.     (begin, end, FunctionWrapper1<T, U>(map), reduce, options);
  241. }
  242. template <typename ResultType, typename Iterator, typename T, typename C, typename ReduceFunctor>
  243. QFuture<ResultType> mappedReduced(Iterator begin,
  244.                                   Iterator end,
  245.                                   T (C::*map)() const,
  246.                                   ReduceFunctor reduce,
  247.                                   ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
  248. {
  249.     return startMappedReduced<T, ResultType>
  250.     (begin, end, ConstMemberFunctionWrapper<T, C>(map), reduce, options);
  251. }
  252. template <typename Iterator, typename T, typename U, typename V, typename W, typename X>
  253. QFuture<W> mappedReduced(Iterator begin,
  254.                          Iterator end,
  255.                          T (map)(U),
  256.                          V (reduce)(W &, X),
  257.                          ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
  258. {
  259.     return startMappedReduced<T, W>
  260.     (begin, end, FunctionWrapper1<T, U>(map), FunctionWrapper2<V, W &, X>(reduce), options);
  261. }
  262. template <typename Iterator, typename T, typename C, typename U, typename V, typename W>
  263. QFuture<V> mappedReduced(Iterator begin,
  264.                          Iterator end,
  265.                          T (C::*map)() const,
  266.                          U (reduce)(V &, W),
  267.                          ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
  268. {
  269.     return startMappedReduced<T, V>(begin, end, ConstMemberFunctionWrapper<T, C>(map),
  270.                                    FunctionWrapper2<U, V &, W>(reduce), options);
  271. }
  272. template <typename Iterator, typename T, typename U, typename V, typename C, typename W>
  273. QFuture<C> mappedReduced(Iterator begin,
  274.                          Iterator end,
  275.                          T (map)(U),
  276.                          V (C::*reduce)(W),
  277.                          ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
  278. {
  279.     return startMappedReduced<T, C>
  280.     (begin, end, FunctionWrapper1<T, U>(map), MemberFunctionWrapper1<V, C, W>(reduce), options);
  281. }
  282. template <typename Iterator, typename T, typename C, typename U,typename D, typename V>
  283. QFuture<D> mappedReduced(Iterator begin,
  284.                          Iterator end,
  285.                          T (C::*map)() const,
  286.                          U (D::*reduce)(V),
  287.                          ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
  288. {
  289.     return startMappedReduced<T, D>(begin, end, ConstMemberFunctionWrapper<T, C>(map),
  290.                                     MemberFunctionWrapper1<U, D, V>(reduce), options);
  291. }
  292. // mapped() for sequences
  293. template <typename Sequence, typename MapFunctor>
  294. QFuture<typename MapFunctor::result_type> mapped(const Sequence &sequence, MapFunctor map)
  295. {
  296.     return startMapped<typename MapFunctor::result_type>(sequence, map);
  297. }
  298. template <typename Sequence, typename T, typename U>
  299. QFuture<T> mapped(const Sequence &sequence, T (map)(U))
  300. {
  301.    return startMapped<T>(sequence, FunctionWrapper1<T, U>(map));
  302. }
  303. template <typename Sequence, typename T, typename C>
  304. QFuture<T> mapped(const Sequence &sequence, T (C::*map)() const)
  305. {
  306.     return startMapped<T>(sequence, ConstMemberFunctionWrapper<T, C>(map));
  307. }
  308. // mapped() for iterator ranges.
  309. template <typename Iterator, typename MapFunctor>
  310. QFuture<typename MapFunctor::result_type> mapped(Iterator begin, Iterator end, MapFunctor map)
  311. {
  312.     return startMapped<Q_TYPENAME MapFunctor::result_type>(begin, end, map);
  313. }
  314. template <typename Iterator, typename T, typename U>
  315. QFuture<T> mapped(Iterator begin, Iterator end, T (map)(U))
  316. {
  317.     return startMapped<T>(begin, end, FunctionWrapper1<T, U>(map));
  318. }
  319. template <typename Iterator, typename T, typename C>
  320. QFuture<T> mapped(Iterator begin, Iterator end, T (C::*map)() const)
  321. {
  322.     return startMapped<T>(begin, end, ConstMemberFunctionWrapper<T, C>(map));
  323. }
  324. template <typename Sequence, typename MapFunctor>
  325. void blockingMap(Sequence &sequence, MapFunctor map)
  326. {
  327.     startMap(sequence.begin(), sequence.end(), map).startBlocking();
  328. }
  329. template <typename Sequence, typename T, typename U>
  330. void blockingMap(Sequence &sequence, T (map)(U))
  331. {
  332.     startMap(sequence.begin(), sequence.end(), QtConcurrent::FunctionWrapper1<T, U>(map)).startBlocking();
  333. }
  334. template <typename Sequence, typename T, typename C>
  335. void blockingMap(Sequence &sequence, T (C::*map)())
  336. {
  337.     startMap(sequence.begin(), sequence.end(), QtConcurrent::MemberFunctionWrapper<T, C>(map)).startBlocking();
  338. }
  339. template <typename Iterator, typename MapFunctor>
  340. void blockingMap(Iterator begin, Iterator end, MapFunctor map)
  341. {
  342.     startMap(begin, end, map).startBlocking();
  343. }
  344. template <typename Iterator, typename T, typename U>
  345. void blockingMap(Iterator begin, Iterator end, T (map)(U))
  346. {
  347.     startMap(begin, end, QtConcurrent::FunctionWrapper1<T, U>(map)).startBlocking();
  348. }
  349. template <typename Iterator, typename T, typename C>
  350. void blockingMap(Iterator begin, Iterator end, T (C::*map)())
  351. {
  352.     startMap(begin, end, QtConcurrent::MemberFunctionWrapper<T, C>(map)).startBlocking();
  353. }
  354. template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor>
  355. ResultType blockingMappedReduced(const Sequence &sequence,
  356.                                  MapFunctor map,
  357.                                  ReduceFunctor reduce,
  358.                                  ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
  359. {
  360.     return QtConcurrent::startMappedReduced<typename MapFunctor::result_type, ResultType>
  361.     (sequence, map, reduce, options).startBlocking();
  362. }
  363. template <typename Sequence, typename MapFunctor, typename T, typename U, typename V>
  364. U blockingMappedReduced(const Sequence &sequence,
  365.                         MapFunctor map,
  366.                         T (reduce)(U &, V),
  367.                         QtConcurrent::ReduceOptions options = QtConcurrent::ReduceOptions(QtConcurrent::UnorderedReduce | QtConcurrent::SequentialReduce))
  368. {
  369.     return QtConcurrent::startMappedReduced<typename MapFunctor::result_type, U>
  370.         (sequence,
  371.          map,
  372.          QtConcurrent::FunctionWrapper2<T, U &, V>(reduce),
  373.          options)
  374.         .startBlocking();
  375. }
  376. template <typename Sequence, typename MapFunctor, typename T, typename C, typename U>
  377. C blockingMappedReduced(const Sequence &sequence,
  378.                         MapFunctor map,
  379.                         T (C::*reduce)(U),
  380.                         QtConcurrent::ReduceOptions options = QtConcurrent::ReduceOptions(QtConcurrent::UnorderedReduce | QtConcurrent::SequentialReduce))
  381. {
  382.     return QtConcurrent::startMappedReduced<typename MapFunctor::result_type, C>
  383.         (sequence,
  384.          map,
  385.          QtConcurrent::MemberFunctionWrapper1<T, C, U>(reduce),
  386.          options)
  387.         .startBlocking();
  388. }
  389. template <typename ResultType, typename Sequence, typename T, typename U, typename ReduceFunctor>
  390. ResultType blockingMappedReduced(const Sequence &sequence,
  391.                                  T (map)(U),
  392.                                  ReduceFunctor reduce,
  393.                                  QtConcurrent::ReduceOptions options = QtConcurrent::ReduceOptions(QtConcurrent::UnorderedReduce | QtConcurrent::SequentialReduce))
  394. {
  395.     return QtConcurrent::startMappedReduced<T, ResultType>
  396.         (sequence,
  397.          QtConcurrent::FunctionWrapper1<T, U>(map),
  398.          reduce,
  399.          options)
  400.         .startBlocking();
  401. }
  402. template <typename ResultType, typename Sequence, typename T, typename C, typename ReduceFunctor>
  403. ResultType blockingMappedReduced(const Sequence &sequence,
  404.                                  T (C::*map)() const,
  405.                                  ReduceFunctor reduce,
  406.                                  QtConcurrent::ReduceOptions options = QtConcurrent::ReduceOptions(QtConcurrent::UnorderedReduce | QtConcurrent::SequentialReduce))
  407. {
  408.     return QtConcurrent::startMappedReduced<T, ResultType>
  409.         (sequence,
  410.          QtConcurrent::ConstMemberFunctionWrapper<T, C>(map),
  411.          reduce,
  412.          options)
  413.         .startBlocking();
  414. }
  415. template <typename Sequence, typename T, typename U, typename V, typename W, typename X>
  416. W blockingMappedReduced(const Sequence &sequence,
  417.                         T (map)(U),
  418.                         V (reduce)(W &, X),
  419.                         QtConcurrent::ReduceOptions options = QtConcurrent::ReduceOptions(QtConcurrent::UnorderedReduce | QtConcurrent::SequentialReduce))
  420. {
  421.     return QtConcurrent::startMappedReduced<T, W>
  422.         (sequence,
  423.          QtConcurrent::FunctionWrapper1<T, U>(map),
  424.          QtConcurrent::FunctionWrapper2<V, W &, X>(reduce),
  425.          options)
  426.         .startBlocking();
  427. }
  428. template <typename Sequence, typename T, typename C, typename U, typename V, typename W>
  429. V blockingMappedReduced(const Sequence &sequence,
  430.                         T (C::*map)() const,
  431.                         U (reduce)(V &, W),
  432.                         QtConcurrent::ReduceOptions options = QtConcurrent::ReduceOptions(QtConcurrent::UnorderedReduce | QtConcurrent::SequentialReduce))
  433. {
  434.     return QtConcurrent::startMappedReduced<T, V>
  435.         (sequence,
  436.          QtConcurrent::ConstMemberFunctionWrapper<T, C>(map),
  437.          QtConcurrent::FunctionWrapper2<U, V &, W>(reduce),
  438.          options)
  439.         .startBlocking();
  440. }
  441. template <typename Sequence, typename T, typename U, typename V, typename C, typename W>
  442. C blockingMappedReduced(const Sequence &sequence,
  443.                         T (map)(U),
  444.                         V (C::*reduce)(W),
  445.                         QtConcurrent::ReduceOptions options = QtConcurrent::ReduceOptions(QtConcurrent::UnorderedReduce | QtConcurrent::SequentialReduce))
  446. {
  447.     return QtConcurrent::startMappedReduced<T, C>
  448.         (sequence,
  449.          QtConcurrent::FunctionWrapper1<T, U>(map),
  450.          QtConcurrent::MemberFunctionWrapper1<V, C, W>(reduce),
  451.          options)
  452.         .startBlocking();
  453. }
  454. template <typename Sequence, typename T, typename C, typename U,typename D, typename V>
  455. D blockingMappedReduced(const Sequence &sequence,
  456.                         T (C::*map)() const,
  457.                         U (D::*reduce)(V),
  458.                         QtConcurrent::ReduceOptions options = QtConcurrent::ReduceOptions(QtConcurrent::UnorderedReduce | QtConcurrent::SequentialReduce))
  459. {
  460.     return QtConcurrent::startMappedReduced<T, D>
  461.         (sequence,
  462.          QtConcurrent::ConstMemberFunctionWrapper<T, C>(map),
  463.          QtConcurrent::MemberFunctionWrapper1<U, D, V>(reduce),
  464.          options)
  465.         .startBlocking();
  466. }
  467. template <typename ResultType, typename Iterator, typename MapFunctor, typename ReduceFunctor>
  468. ResultType blockingMappedReduced(Iterator begin,
  469.                                  Iterator end,
  470.                                  MapFunctor map,
  471.                                  ReduceFunctor reduce,
  472.                                  QtConcurrent::ReduceOptions options = QtConcurrent::ReduceOptions(QtConcurrent::UnorderedReduce | QtConcurrent::SequentialReduce))
  473. {
  474.     return QtConcurrent::startMappedReduced<typename MapFunctor::result_type, ResultType>
  475.         (begin, end, map, reduce, options).startBlocking();
  476. }
  477. template <typename Iterator, typename MapFunctor, typename T, typename U, typename V>
  478. U blockingMappedReduced(Iterator begin,
  479.                         Iterator end,
  480.                         MapFunctor map,
  481.                         T (reduce)(U &, V),
  482.                         QtConcurrent::ReduceOptions options = QtConcurrent::ReduceOptions(QtConcurrent::UnorderedReduce | QtConcurrent::SequentialReduce))
  483. {
  484.     return QtConcurrent::startMappedReduced<typename MapFunctor::result_type, U>
  485.         (begin,
  486.          end,
  487.          map,
  488.          QtConcurrent::FunctionWrapper2<T, U &, V>(reduce),
  489.          options)
  490.         .startBlocking();
  491. }
  492. template <typename Iterator, typename MapFunctor, typename T, typename C, typename U>
  493. C blockingMappedReduced(Iterator begin,
  494.                         Iterator end,
  495.                         MapFunctor map,
  496.                         T (C::*reduce)(U),
  497.                         QtConcurrent::ReduceOptions options = QtConcurrent::ReduceOptions(QtConcurrent::UnorderedReduce | QtConcurrent::SequentialReduce))
  498. {
  499.     return QtConcurrent::startMappedReduced<typename MapFunctor::result_type, C>
  500.         (begin,
  501.          end,
  502.          map,
  503.          QtConcurrent::MemberFunctionWrapper1<T, C, U>(reduce),
  504.          options)
  505.         .startBlocking();
  506. }
  507. template <typename ResultType, typename Iterator, typename T, typename U, typename ReduceFunctor>
  508. ResultType blockingMappedReduced(Iterator begin,
  509.                                  Iterator end,
  510.                                  T (map)(U),
  511.                                  ReduceFunctor reduce,
  512.                                  QtConcurrent::ReduceOptions options = QtConcurrent::ReduceOptions(QtConcurrent::UnorderedReduce | QtConcurrent::SequentialReduce))
  513. {
  514.     return QtConcurrent::startMappedReduced<T, ResultType>
  515.         (begin,
  516.          end,
  517.          QtConcurrent::FunctionWrapper1<T, U>(map),
  518.          reduce,
  519.          options)
  520.         .startBlocking();
  521. }
  522. template <typename ResultType, typename Iterator, typename T, typename C, typename ReduceFunctor>
  523. ResultType blockingMappedReduced(Iterator begin,
  524.                                  Iterator end,
  525.                                  T (C::*map)() const,
  526.                                  ReduceFunctor reduce,
  527.                                  QtConcurrent::ReduceOptions options = QtConcurrent::ReduceOptions(QtConcurrent::UnorderedReduce | QtConcurrent::SequentialReduce))
  528. {
  529.     return QtConcurrent::startMappedReduced<T, ResultType>
  530.         (begin,
  531.          end,
  532.          QtConcurrent::ConstMemberFunctionWrapper<T, C>(map),
  533.          reduce,
  534.          options)
  535.         .startBlocking();
  536. }
  537. template <typename Iterator, typename T, typename U, typename V, typename W, typename X>
  538. W blockingMappedReduced(Iterator begin,
  539.                         Iterator end,
  540.                         T (map)(U),
  541.                         V (reduce)(W &, X),
  542.                         QtConcurrent::ReduceOptions options = QtConcurrent::ReduceOptions(QtConcurrent::UnorderedReduce | QtConcurrent::SequentialReduce))
  543. {
  544.     return QtConcurrent::startMappedReduced<T, W>
  545.         (begin,
  546.          end,
  547.          QtConcurrent::FunctionWrapper1<T, U>(map),
  548.          QtConcurrent::FunctionWrapper2<V, W &, X>(reduce),
  549.          options)
  550.         .startBlocking();
  551. }
  552. template <typename Iterator, typename T, typename C, typename U, typename V, typename W>
  553. V blockingMappedReduced(Iterator begin,
  554.                         Iterator end,
  555.                         T (C::*map)() const,
  556.                         U (reduce)(V &, W),
  557.                         QtConcurrent::ReduceOptions options = QtConcurrent::ReduceOptions(QtConcurrent::UnorderedReduce | QtConcurrent::SequentialReduce))
  558. {
  559.     return QtConcurrent::startMappedReduced<T, V>
  560.         (begin,
  561.          end,
  562.          QtConcurrent::ConstMemberFunctionWrapper<T, C>(map),
  563.          QtConcurrent::FunctionWrapper2<U, V &, W>(reduce),
  564.          options)
  565.         .startBlocking();
  566. }
  567. template <typename Iterator, typename T, typename U, typename V, typename C, typename W>
  568. C blockingMappedReduced(Iterator begin,
  569.                         Iterator end,
  570.                         T (map)(U),
  571.                         V (C::*reduce)(W),
  572.                         QtConcurrent::ReduceOptions options = QtConcurrent::ReduceOptions(QtConcurrent::UnorderedReduce | QtConcurrent::SequentialReduce))
  573. {
  574.     return QtConcurrent::startMappedReduced<T, C>
  575.         (begin,
  576.          end,
  577.          QtConcurrent::FunctionWrapper1<T, U>(map),
  578.          QtConcurrent::MemberFunctionWrapper1<V, C, W>(reduce),
  579.          options)
  580.         .startBlocking();
  581. }
  582. template <typename Iterator, typename T, typename C, typename U,typename D, typename V>
  583. D blockingMappedReduced(Iterator begin,
  584.                         Iterator end,
  585.                         T (C::*map)() const,
  586.                         U (D::*reduce)(V),
  587.                         QtConcurrent::ReduceOptions options = QtConcurrent::ReduceOptions(QtConcurrent::UnorderedReduce | QtConcurrent::SequentialReduce))
  588. {
  589.     return QtConcurrent::startMappedReduced<T, D>
  590.         (begin,
  591.          end,
  592.          QtConcurrent::ConstMemberFunctionWrapper<T, C>(map),
  593.          QtConcurrent::MemberFunctionWrapper1<U, D, V>(reduce),
  594.          options)
  595.         .startBlocking();
  596. }
  597. // mapped() for sequences with a different putput sequence type.
  598. template <typename OutputSequence, typename InputSequence, typename MapFunctor>
  599. OutputSequence blockingMapped(const InputSequence &sequence, MapFunctor map)
  600. {
  601.     return blockingMappedReduced(sequence, map, &OutputSequence::push_back,
  602.                                  QtConcurrent::OrderedReduce);
  603. }
  604. template <typename OutputSequence, typename InputSequence, typename T, typename U>
  605. OutputSequence blockingMapped(const InputSequence &sequence, T (map)(U))
  606. {
  607.     return blockingMappedReduced(sequence, map, &OutputSequence::push_back,
  608.                                  QtConcurrent::OrderedReduce);
  609. }
  610. template <typename OutputSequence, typename InputSequence, typename T, typename C>
  611. OutputSequence blockingMapped(const InputSequence &sequence, T (C::*map)() const)
  612. {
  613.     return blockingMappedReduced(sequence, map, &OutputSequence::push_back,
  614.                                  QtConcurrent::OrderedReduce);
  615. }
  616. #ifndef QT_NO_TEMPLATE_TEMPLATE_PARAMETERS
  617. // overloads for changing the container value type:
  618. template <template <typename> class Sequence, typename MapFunctor, typename T>
  619. Sequence<typename MapFunctor::result_type> blockingMapped(const Sequence<T> &sequence, MapFunctor map)
  620. {
  621.     typedef Sequence<typename MapFunctor::result_type> OutputSequence;
  622.     return blockingMappedReduced(sequence, map, &OutputSequence::push_back,
  623.                                                QtConcurrent::OrderedReduce);
  624. }
  625. template <template <typename> class Sequence, typename T, typename U, typename V>
  626. Sequence<U> blockingMapped(const Sequence<T> &sequence, U (map)(V))
  627. {
  628.     typedef Sequence<U> OutputSequence;
  629.     return blockingMappedReduced(sequence, map, &OutputSequence::push_back,
  630.                                                QtConcurrent::OrderedReduce);
  631. }
  632. template <template <typename> class Sequence, typename T, typename U, typename C>
  633. Sequence<U> blockingMapped(const Sequence<T> &sequence, U (C::*map)() const)
  634. {
  635.     typedef Sequence<U> OutputSequence;
  636.     return blockingMappedReduced(sequence, map, &OutputSequence::push_back,
  637.                                                QtConcurrent::OrderedReduce);
  638. }
  639. #endif // QT_NO_TEMPLATE_TEMPLATE_PARAMETER
  640. // overloads for changing the container value type from a QStringList:
  641. template <typename MapFunctor>
  642. QList<typename MapFunctor::result_type> blockingMapped(const QStringList &sequence, MapFunctor map)
  643. {
  644.     typedef QList<typename MapFunctor::result_type> OutputSequence;
  645.     return blockingMappedReduced(sequence, map, &OutputSequence::push_back,
  646.                                  QtConcurrent::OrderedReduce);
  647. }
  648. template <typename U, typename V>
  649. QList<U> blockingMapped(const QStringList &sequence, U (map)(V))
  650. {
  651.     typedef QList<U> OutputSequence;
  652.     return blockingMappedReduced(sequence, map, &OutputSequence::push_back,
  653.                                  QtConcurrent::OrderedReduce);
  654. }
  655. template <typename U, typename C>
  656. QList<U> blockingMapped(const QStringList &sequence, U (C::*map)() const)
  657. {
  658.     typedef QList<U> OutputSequence;
  659.     return blockingMappedReduced(sequence, map, &OutputSequence::push_back,
  660.                                  QtConcurrent::OrderedReduce);
  661. }
  662. // mapped()  for iterator ranges
  663. template <typename Sequence, typename Iterator, typename MapFunctor>
  664. Sequence blockingMapped(Iterator begin, Iterator end, MapFunctor map)
  665. {
  666.     return blockingMappedReduced(begin, end, map, &Sequence::push_back,
  667.                                  QtConcurrent::OrderedReduce);
  668. }
  669. template <typename Sequence, typename Iterator, typename T, typename U>
  670. Sequence blockingMapped(Iterator begin, Iterator end, T (map)(U))
  671. {
  672.     return blockingMappedReduced(begin, end, map, &Sequence::push_back,
  673.                                  QtConcurrent::OrderedReduce);
  674. }
  675. template <typename Sequence, typename Iterator, typename T, typename C>
  676. Sequence blockingMapped(Iterator begin, Iterator end, T (C::*map)() const)
  677. {
  678.     return blockingMappedReduced(begin, end, map, &Sequence::push_back,
  679.                                  QtConcurrent::OrderedReduce);
  680. }
  681. } // namespace QtConcurrent
  682. #endif // qdoc
  683. QT_END_NAMESPACE
  684. QT_END_HEADER
  685. #endif // QT_NO_CONCURRENT
  686. #endif