diff options
Diffstat (limited to 'src/concurrent')
19 files changed, 379 insertions, 176 deletions
diff --git a/src/concurrent/doc/qtconcurrent.qdocconf b/src/concurrent/doc/qtconcurrent.qdocconf index d8ee963ef5..356d602a7c 100644 --- a/src/concurrent/doc/qtconcurrent.qdocconf +++ b/src/concurrent/doc/qtconcurrent.qdocconf @@ -36,6 +36,8 @@ exampledirs += ../../../examples/qtconcurrent \ ../ \ snippets +manifestmeta.highlighted.names = "QtConcurrent/QtConcurrent Progress Dialog Example" + excludedirs += ../../../examples/widgets/doc imagedirs += images diff --git a/src/concurrent/doc/snippets/code/src_concurrent_qtconcurrentfilter.cpp b/src/concurrent/doc/snippets/code/src_concurrent_qtconcurrentfilter.cpp index 9b15eeaa99..3cc1fe836c 100644 --- a/src/concurrent/doc/snippets/code/src_concurrent_qtconcurrentfilter.cpp +++ b/src/concurrent/doc/snippets/code/src_concurrent_qtconcurrentfilter.cpp @@ -169,5 +169,17 @@ struct StartsWith }; QList<QString> strings = ...; -QFuture<QString> fooString = QtConcurrent::filtered(images, StartsWith(QLatin1String("Foo"))); +QFuture<QString> fooString = QtConcurrent::filtered(strings, StartsWith(QLatin1String("Foo"))); //! [13] + +//! [14] +struct StringTransform +{ + void operator()(QString &result, const QString &value); +}; + +QFuture<QString> fooString = + QtConcurrent::filteredReduced<QString>(strings, + StartsWith(QLatin1String("Foo")), + StringTransform()); +//! [14] diff --git a/src/concurrent/doc/snippets/code/src_concurrent_qtconcurrentmap.cpp b/src/concurrent/doc/snippets/code/src_concurrent_qtconcurrentmap.cpp index 183b82bb9a..9cf82c786a 100644 --- a/src/concurrent/doc/snippets/code/src_concurrent_qtconcurrentmap.cpp +++ b/src/concurrent/doc/snippets/code/src_concurrent_qtconcurrentmap.cpp @@ -157,6 +157,18 @@ QFuture<QSet<int> > totalColorDistribution = QtConcurrent::mappedReduced(images, QImage QImage::scaledToWidth(int width, Qt::TransformationMode) const; //! [10] +//! [11] +struct ImageTransform +{ + void operator()(QImage &result, const QImage &value); +}; + +QFuture<QImage> thumbNails = + QtConcurrent::mappedReduced<QImage>(images, + Scaled(100), + ImageTransform(), + QtConcurrent::SequentialReduce); +//! [11] //! [13] QList<QImage> images = ...; diff --git a/src/concurrent/qtconcurrentexception.h b/src/concurrent/qtconcurrentexception.h index 03dd7ec498..9da53fd9e2 100644 --- a/src/concurrent/qtconcurrentexception.h +++ b/src/concurrent/qtconcurrentexception.h @@ -41,18 +41,17 @@ #define QTCONCURRENT_EXCEPTION_H #include <QtConcurrent/qtconcurrent_global.h> - -#ifndef QT_NO_QFUTURE - #include <QtCore/qexception.h> +QT_REQUIRE_CONFIG(concurrent); + QT_BEGIN_NAMESPACE namespace QtConcurrent { -#ifndef QT_NO_EXCEPTIONS +#if !defined(QT_NO_EXCEPTIONS) || defined(Q_CLANG_QDOC) typedef Q_DECL_DEPRECATED QException Exception; typedef Q_DECL_DEPRECATED QUnhandledException UnhandledException; @@ -63,6 +62,4 @@ typedef Q_DECL_DEPRECATED QUnhandledException UnhandledException; QT_END_NAMESPACE -#endif // QT_NO_QFUTURE - #endif diff --git a/src/concurrent/qtconcurrentfilter.cpp b/src/concurrent/qtconcurrentfilter.cpp index 3e3ed7cf68..c0cbbd3f3d 100644 --- a/src/concurrent/qtconcurrentfilter.cpp +++ b/src/concurrent/qtconcurrentfilter.cpp @@ -142,12 +142,19 @@ \section2 Using Function Objects QtConcurrent::filter(), QtConcurrent::filtered(), and - QtConcurrent::filteredReduced() accept function objects, which can be used to + QtConcurrent::filteredReduced() accept function objects + for the filter function. These function objects can be used to add state to a function call. The result_type typedef must define the result type of the function call operator: \snippet code/src_concurrent_qtconcurrentfilter.cpp 13 + For the reduce function, function objects are not directly + supported. Function objects can, however, be used + when the type of the reduction result is explicitly specified: + + \snippet code/src_concurrent_qtconcurrentfilter.cpp 14 + \section2 Wrapping Functions that Take Multiple Arguments If you want to use a filter function takes more than one argument, you can @@ -168,7 +175,49 @@ */ /*! - \fn QFuture<void> QtConcurrent::filter(Sequence &sequence, FilterFunction filterFunction) + \class QtConcurrent::qValueType + \inmodule QtConcurrent + \internal +*/ + +/*! + \class QtConcurrent::qValueType<const T*> + \inmodule QtConcurrent + \internal +*/ + + +/*! + \class QtConcurrent::qValueType<T*> + \inmodule QtConcurrent + \internal +*/ + +/*! + \class QtConcurrent::FilterKernel + \inmodule QtConcurrent + \internal +*/ + +/*! + \class QtConcurrent::FilteredReducedKernel + \inmodule QtConcurrent + \internal +*/ + +/*! + \class QtConcurrent::FilteredEachKernel + \inmodule QtConcurrent + \internal +*/ + +/*! + \fn [QtConcurrent-1] template <typename Sequence, typename KeepFunctor, typename ReduceFunctor> ThreadEngineStarter<void> QtConcurrent::filterInternal(Sequence &sequence, KeepFunctor keep, ReduceFunctor reduce) + \internal +*/ + +/*! + \fn template <typename Sequence, typename KeepFunctor> QFuture<void> QtConcurrent::filter(Sequence &sequence, KeepFunctor filterFunction) Calls \a filterFunction once for each item in \a sequence. If \a filterFunction returns \c true, the item is kept in \a sequence; @@ -178,7 +227,7 @@ */ /*! - \fn QFuture<T> QtConcurrent::filtered(const Sequence &sequence, FilterFunction filterFunction) + \fn template <typename Sequence, typename KeepFunctor> QFuture<Sequence::value_type> QtConcurrent::filtered(const Sequence &sequence, KeepFunctor filterFunction) Calls \a filterFunction once for each item in \a sequence and returns a new Sequence of kept items. If \a filterFunction returns \c true, a copy of @@ -189,7 +238,7 @@ */ /*! - \fn QFuture<T> QtConcurrent::filtered(ConstIterator begin, ConstIterator end, FilterFunction filterFunction) + \fn template <typename Iterator, typename KeepFunctor> QFuture<typename QtConcurrent::qValueType<Iterator>::value_type> QtConcurrent::filtered(Iterator begin, Iterator end, KeepFunctor filterFunction) Calls \a filterFunction once for each item from \a begin to \a end and returns a new Sequence of kept items. If \a filterFunction returns \c true, a @@ -200,7 +249,7 @@ */ /*! - \fn QFuture<T> QtConcurrent::filteredReduced(const Sequence &sequence, FilterFunction filterFunction, ReduceFunction reduceFunction, QtConcurrent::ReduceOptions reduceOptions) + \fn template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor> QFuture<ResultType> QtConcurrent::filteredReduced(const Sequence &sequence, KeepFunctor filterFunction, ReduceFunctor reduceFunction, QtConcurrent::ReduceOptions reduceOptions) Calls \a filterFunction once for each item in \a sequence. If \a filterFunction returns \c true for an item, that item is then passed to @@ -218,7 +267,7 @@ */ /*! - \fn QFuture<T> QtConcurrent::filteredReduced(ConstIterator begin, ConstIterator end, FilterFunction filterFunction, ReduceFunction reduceFunction, QtConcurrent::ReduceOptions reduceOptions) + \fn template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor> QFuture<ResultType> QtConcurrent::filteredReduced(Iterator begin, Iterator end, KeepFunctor filterFunction, ReduceFunctor reduceFunction, QtConcurrent::ReduceOptions reduceOptions) Calls \a filterFunction once for each item from \a begin to \a end. If \a filterFunction returns \c true for an item, that item is then passed to @@ -236,7 +285,7 @@ */ /*! - \fn void QtConcurrent::blockingFilter(Sequence &sequence, FilterFunction filterFunction) + \fn template <typename Sequence, typename KeepFunctor> void QtConcurrent::blockingFilter(Sequence &sequence, KeepFunctor filterFunction) Calls \a filterFunction once for each item in \a sequence. If \a filterFunction returns \c true, the item is kept in \a sequence; @@ -248,7 +297,7 @@ */ /*! - \fn Sequence QtConcurrent::blockingFiltered(const Sequence &sequence, FilterFunction filterFunction) + \fn template <typename Sequence, typename KeepFunctor> Sequence QtConcurrent::blockingFiltered(const Sequence &sequence, KeepFunctor filterFunction) Calls \a filterFunction once for each item in \a sequence and returns a new Sequence of kept items. If \a filterFunction returns \c true, a copy of @@ -261,7 +310,7 @@ */ /*! - \fn Sequence QtConcurrent::blockingFiltered(ConstIterator begin, ConstIterator end, FilterFunction filterFunction) + \fn template <typename OutputSequence, typename Iterator, typename KeepFunctor> OutputSequence QtConcurrent::blockingFiltered(Iterator begin, Iterator end, KeepFunctor filterFunction) Calls \a filterFunction once for each item from \a begin to \a end and returns a new Sequence of kept items. If \a filterFunction returns \c true, a @@ -275,7 +324,7 @@ */ /*! - \fn T QtConcurrent::blockingFilteredReduced(const Sequence &sequence, FilterFunction filterFunction, ReduceFunction reduceFunction, QtConcurrent::ReduceOptions reduceOptions) + \fn template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor> ResultType QtConcurrent::blockingFilteredReduced(const Sequence &sequence, KeepFunctor filterFunction, ReduceFunctor reduceFunction, QtConcurrent::ReduceOptions reduceOptions) Calls \a filterFunction once for each item in \a sequence. If \a filterFunction returns \c true for an item, that item is then passed to @@ -295,7 +344,7 @@ */ /*! - \fn T QtConcurrent::blockingFilteredReduced(ConstIterator begin, ConstIterator end, FilterFunction filterFunction, ReduceFunction reduceFunction, QtConcurrent::ReduceOptions reduceOptions) + \fn template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor> ResultType QtConcurrent::blockingFilteredReduced(Iterator begin, Iterator end, KeepFunctor filterFunction, ReduceFunctor reduceFunction, QtConcurrent::ReduceOptions reduceOptions) Calls \a filterFunction once for each item from \a begin to \a end. If \a filterFunction returns \c true for an item, that item is then passed to @@ -314,3 +363,24 @@ \sa filteredReduced(), {Concurrent Filter and Filter-Reduce} */ + +/*! + \fn [QtConcurrent-2] ThreadEngineStarter<typename qValueType<Iterator>::value_type> QtConcurrent::startFiltered(Iterator begin, Iterator end, KeepFunctor functor) + \internal +*/ + +/*! + \fn [QtConcurrent-3] ThreadEngineStarter<typename Sequence::value_type> QtConcurrent::startFiltered(const Sequence &sequence, KeepFunctor functor) + \internal +*/ + +/*! + \fn [QtConcurrent-4] ThreadEngineStarter<ResultType> QtConcurrent::startFilteredReduced(const Sequence & sequence, MapFunctor mapFunctor, ReduceFunctor reduceFunctor, ReduceOptions options) + \internal +*/ + +/*! + \fn [QtConcurrent-5] ThreadEngineStarter<ResultType> QtConcurrent::startFilteredReduced(Iterator begin, Iterator end, MapFunctor mapFunctor, ReduceFunctor reduceFunctor, ReduceOptions options) + \internal +*/ + diff --git a/src/concurrent/qtconcurrentfilter.h b/src/concurrent/qtconcurrentfilter.h index e09f3b4abc..acc794fad8 100644 --- a/src/concurrent/qtconcurrentfilter.h +++ b/src/concurrent/qtconcurrentfilter.h @@ -42,62 +42,16 @@ #include <QtConcurrent/qtconcurrent_global.h> -#ifndef QT_NO_CONCURRENT +#if !defined(QT_NO_CONCURRENT) || defined(Q_CLANG_QDOC) #include <QtConcurrent/qtconcurrentfilterkernel.h> #include <QtConcurrent/qtconcurrentfunctionwrappers.h> QT_BEGIN_NAMESPACE - -#ifdef Q_QDOC - -namespace QtConcurrent { - - QFuture<void> filter(Sequence &sequence, FilterFunction filterFunction); - - template <typename T> - QFuture<T> filtered(const Sequence &sequence, FilterFunction filterFunction); - template <typename T> - QFuture<T> filtered(ConstIterator begin, ConstIterator end, FilterFunction filterFunction); - - template <typename T> - QFuture<T> filteredReduced(const Sequence &sequence, - FilterFunction filterFunction, - ReduceFunction reduceFunction, - QtConcurrent::ReduceOptions reduceOptions = UnorderedReduce | SequentialReduce); - template <typename T> - QFuture<T> filteredReduced(ConstIterator begin, - ConstIterator end, - FilterFunction filterFunction, - ReduceFunction reduceFunction, - QtConcurrent::ReduceOptions reduceOptions = UnorderedReduce | SequentialReduce); - - void blockingFilter(Sequence &sequence, FilterFunction filterFunction); - - template <typename Sequence> - Sequence blockingFiltered(const Sequence &sequence, FilterFunction filterFunction); - template <typename Sequence> - Sequence blockingFiltered(ConstIterator begin, ConstIterator end, FilterFunction filterFunction); - - template <typename T> - T blockingFilteredReduced(const Sequence &sequence, - FilterFunction filterFunction, - ReduceFunction reduceFunction, - QtConcurrent::ReduceOptions reduceOptions = UnorderedReduce | SequentialReduce); - template <typename T> - T blockingFilteredReduced(ConstIterator begin, - ConstIterator end, - FilterFunction filterFunction, - ReduceFunction reduceFunction, - QtConcurrent::ReduceOptions reduceOptions = UnorderedReduce | SequentialReduce); - -} // namespace QtConcurrent - -#else - namespace QtConcurrent { +//! [QtConcurrent-1] template <typename Sequence, typename KeepFunctor, typename ReduceFunctor> ThreadEngineStarter<void> filterInternal(Sequence &sequence, KeepFunctor keep, ReduceFunctor reduce) { @@ -122,6 +76,7 @@ QFuture<ResultType> filteredReduced(const Sequence &sequence, return startFilteredReduced<ResultType>(sequence, QtPrivate::createFunctionWrapper(keep), QtPrivate::createFunctionWrapper(reduce), options); } +#ifndef Q_CLANG_QDOC template <typename Sequence, typename KeepFunctor, typename ReduceFunctor> QFuture<typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType> filteredReduced(const Sequence &sequence, KeepFunctor keep, @@ -134,6 +89,7 @@ QFuture<typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType> filtere QtPrivate::createFunctionWrapper(reduce), options); } +#endif // filteredReduced() on iterators template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor> @@ -146,6 +102,7 @@ QFuture<ResultType> filteredReduced(Iterator begin, return startFilteredReduced<ResultType>(begin, end, QtPrivate::createFunctionWrapper(keep), QtPrivate::createFunctionWrapper(reduce), options); } +#ifndef Q_CLANG_QDOC template <typename Iterator, typename KeepFunctor, typename ReduceFunctor> QFuture<typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType> filteredReduced(Iterator begin, Iterator end, @@ -159,6 +116,7 @@ QFuture<typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType> filtere QtPrivate::createFunctionWrapper(reduce), options); } +#endif // filtered() on sequences template <typename Sequence, typename KeepFunctor> @@ -192,6 +150,7 @@ ResultType blockingFilteredReduced(const Sequence &sequence, .startBlocking(); } +#ifndef Q_CLANG_QDOC template <typename Sequence, typename KeepFunctor, typename ReduceFunctor> typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType blockingFilteredReduced(const Sequence &sequence, KeepFunctor keep, @@ -204,6 +163,7 @@ typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType blockingFiltered QtPrivate::createFunctionWrapper(reduce), options); } +#endif // blocking filteredReduced() on iterators template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor> @@ -221,6 +181,7 @@ ResultType blockingFilteredReduced(Iterator begin, .startBlocking(); } +#ifndef Q_CLANG_QDOC template <typename Iterator, typename KeepFunctor, typename ReduceFunctor> typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType blockingFilteredReduced(Iterator begin, Iterator end, @@ -235,6 +196,7 @@ typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType blockingFiltered options) .startBlocking(); } +#endif // blocking filtered() on sequences template <typename Sequence, typename KeepFunctor> @@ -255,8 +217,6 @@ OutputSequence blockingFiltered(Iterator begin, Iterator end, KeepFunctor keep) } // namespace QtConcurrent -#endif // Q_QDOC - QT_END_NAMESPACE #endif // QT_NO_CONCURRENT diff --git a/src/concurrent/qtconcurrentfilterkernel.h b/src/concurrent/qtconcurrentfilterkernel.h index bd474fc0c9..4ef5ac0cee 100644 --- a/src/concurrent/qtconcurrentfilterkernel.h +++ b/src/concurrent/qtconcurrentfilterkernel.h @@ -42,7 +42,7 @@ #include <QtConcurrent/qtconcurrent_global.h> -#ifndef QT_NO_CONCURRENT +#if !defined(QT_NO_CONCURRENT) || defined (Q_CLANG_QDOC) #include <QtConcurrent/qtconcurrentiteratekernel.h> #include <QtConcurrent/qtconcurrentmapkernel.h> @@ -51,7 +51,6 @@ QT_BEGIN_NAMESPACE -#ifndef Q_QDOC namespace QtConcurrent { @@ -292,6 +291,7 @@ public: } }; +//! [QtConcurrent-2] template <typename Iterator, typename KeepFunctor> inline ThreadEngineStarter<typename qValueType<Iterator>::value_type> @@ -300,6 +300,7 @@ startFiltered(Iterator begin, Iterator end, KeepFunctor functor) return startThreadEngine(new FilteredEachKernel<Iterator, KeepFunctor>(begin, end, functor)); } +//! [QtConcurrent-3] template <typename Sequence, typename KeepFunctor> inline ThreadEngineStarter<typename Sequence::value_type> startFiltered(const Sequence &sequence, KeepFunctor functor) @@ -311,6 +312,7 @@ startFiltered(const Sequence &sequence, KeepFunctor functor) return startThreadEngine(new SequenceHolderType(sequence, functor)); } +//! [QtConcurrent-4] template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor> inline ThreadEngineStarter<ResultType> startFilteredReduced(const Sequence & sequence, MapFunctor mapFunctor, ReduceFunctor reduceFunctor, @@ -324,6 +326,7 @@ inline ThreadEngineStarter<ResultType> startFilteredReduced(const Sequence & seq } +//! [QtConcurrent-5] template <typename ResultType, typename Iterator, typename MapFunctor, typename ReduceFunctor> inline ThreadEngineStarter<ResultType> startFilteredReduced(Iterator begin, Iterator end, MapFunctor mapFunctor, ReduceFunctor reduceFunctor, @@ -337,7 +340,6 @@ inline ThreadEngineStarter<ResultType> startFilteredReduced(Iterator begin, Iter } // namespace QtConcurrent -#endif // Q_QDOC QT_END_NAMESPACE diff --git a/src/concurrent/qtconcurrentfunctionwrappers.h b/src/concurrent/qtconcurrentfunctionwrappers.h index 111933410b..0f9eb46999 100644 --- a/src/concurrent/qtconcurrentfunctionwrappers.h +++ b/src/concurrent/qtconcurrentfunctionwrappers.h @@ -43,13 +43,10 @@ #include <QtConcurrent/qtconcurrentcompilertest.h> #include <QtCore/QStringList> -#ifndef QT_NO_CONCURRENT +#if !defined(QT_NO_CONCURRENT) || defined(Q_CLANG_QDOC) QT_BEGIN_NAMESPACE - -#ifndef Q_QDOC - namespace QtConcurrent { template <typename T> @@ -375,7 +372,6 @@ struct MapResultType<QStringList, U(C::*)() const noexcept> } // namespace QtPrivate. -#endif //Q_QDOC QT_END_NAMESPACE diff --git a/src/concurrent/qtconcurrentiteratekernel.cpp b/src/concurrent/qtconcurrentiteratekernel.cpp index 52218f794b..11bdb7e8cd 100644 --- a/src/concurrent/qtconcurrentiteratekernel.cpp +++ b/src/concurrent/qtconcurrentiteratekernel.cpp @@ -43,7 +43,7 @@ #include "private/qfunctions_p.h" -#ifndef QT_NO_CONCURRENT +#if !defined(QT_NO_CONCURRENT) || defined(Q_CLANG_QDOC) QT_BEGIN_NAMESPACE @@ -64,6 +64,54 @@ static double elapsed(qint64 after, qint64 before) namespace QtConcurrent { +/*! + \class QtConcurrent::Median + \inmodule QtConcurrent + \internal + */ + +/*! + \class QtConcurrent::MedianDouble + \inmodule QtConcurrent + \internal + */ + +/*! + \class QtConcurrent::BlockSizeManager + \inmodule QtConcurrent + \internal + */ + +/*! + \class QtConcurrent::BlockSizeManagerV2 + \inmodule QtConcurrent + \internal + */ + +/*! + \class QtConcurrent::ResultReporter + \inmodule QtConcurrent + \internal + */ + +/*! \fn bool QtConcurrent::selectIteration(std::bidirectional_iterator_tag) + \internal + */ + +/*! \fn bool QtConcurrent::selectIteration(std::forward_iterator_tag) + \internal + */ + +/*! \fn bool QtConcurrent::selectIteration(std::random_access_iterator_tag) + \internal + */ + +/*! + \class QtConcurrent::IterateKernel + \inmodule QtConcurrent + \internal + */ + /*! \internal */ diff --git a/src/concurrent/qtconcurrentiteratekernel.h b/src/concurrent/qtconcurrentiteratekernel.h index dbd000e8ba..b543833776 100644 --- a/src/concurrent/qtconcurrentiteratekernel.h +++ b/src/concurrent/qtconcurrentiteratekernel.h @@ -42,7 +42,7 @@ #include <QtConcurrent/qtconcurrent_global.h> -#ifndef QT_NO_CONCURRENT +#if !defined(QT_NO_CONCURRENT) || defined(Q_CLANG_QDOC) #include <QtCore/qatomic.h> #include <QtConcurrent/qtconcurrentmedian.h> @@ -53,7 +53,6 @@ QT_BEGIN_NAMESPACE -#ifndef Q_QDOC namespace QtConcurrent { @@ -159,7 +158,7 @@ public: inline ResultReporter(ThreadEngine<void> *) { } inline void reserveSpace(int) { } inline void reportResults(int) { } - inline void * getPointer() { return Q_NULLPTR; } + inline void * getPointer() { return nullptr; } }; inline bool selectIteration(std::bidirectional_iterator_tag) @@ -323,7 +322,6 @@ public: } // namespace QtConcurrent -#endif //Q_QDOC QT_END_NAMESPACE diff --git a/src/concurrent/qtconcurrentmap.cpp b/src/concurrent/qtconcurrentmap.cpp index 884bf4b4f9..a8f1d6496e 100644 --- a/src/concurrent/qtconcurrentmap.cpp +++ b/src/concurrent/qtconcurrentmap.cpp @@ -53,6 +53,72 @@ */ /*! + \enum QtConcurrent::ReduceQueueLimits + \internal + */ + +/*! + \class QtConcurrent::ReduceKernel + \inmodule QtConcurrent + \internal +*/ + +/*! + \class QtConcurrent::SequenceHolder2 + \inmodule QtConcurrent + \internal +*/ + +/*! + \class QtConcurrent::MapKernel + \inmodule QtConcurrent + \internal +*/ + +/*! + \class QtConcurrent::MappedReducedKernel + \inmodule QtConcurrent + \internal +*/ + +/*! + \class QtConcurrent::MappedEachKernel + \inmodule QtConcurrent + \internal +*/ + +/*! + \class QtConcurrent::SequenceHolder1 + \inmodule QtConcurrent + \internal +*/ + +/*! + \fn [qtconcurrentmapkernel-1] ThreadEngineStarter<void> QtConcurrent::startMap(Iterator begin, Iterator end, Functor functor) + \internal +*/ + +/*! + \fn [qtconcurrentmapkernel-2] ThreadEngineStarter<T> QtConcurrent::startMapped(Iterator begin, Iterator end, Functor functor) + \internal +*/ + +/*! + \fn [qtconcurrentmapkernel-3] ThreadEngineStarter<T> QtConcurrent::startMapped(const Sequence &sequence, Functor functor) + \internal +*/ + +/*! + \fn [qtconcurrentmapkernel-4] ThreadEngineStarter<ResultType> QtConcurrent::startMappedReduced(const Sequence & sequence, MapFunctor mapFunctor, ReduceFunctor reduceFunctor, ReduceOptions options) + \internal +*/ + +/*! + \fn [qtconcurrentmapkernel-5] ThreadEngineStarter<ResultType> QtConcurrent::startMappedReduced(Iterator begin, Iterator end, MapFunctor mapFunctor, ReduceFunctor reduceFunctor, ReduceOptions options) + \internal +*/ + +/*! \enum QtConcurrent::ReduceOption This enum specifies the order of which results from the map or filter function are passed to the reduce function. @@ -192,12 +258,19 @@ \section2 Using Function Objects QtConcurrent::map(), QtConcurrent::mapped(), and - QtConcurrent::mappedReduced() accept function objects, which can be used to + QtConcurrent::mappedReduced() accept function objects + for the map function. These function objects can be used to add state to a function call. The result_type typedef must define the result type of the function call operator: \snippet code/src_concurrent_qtconcurrentmap.cpp 14 + For the reduce function, function objects are not directly + supported. Function objects can, however, be used + when the type of the reduction result is explicitly specified: + + \snippet code/src_concurrent_qtconcurrentmap.cpp 11 + \section2 Wrapping Functions that Take Multiple Arguments If you want to use a map function that takes more than one argument you can @@ -218,7 +291,7 @@ */ /*! - \fn QFuture<void> QtConcurrent::map(Sequence &sequence, MapFunction function) + \fn template <typename Sequence, typename MapFunctor> QFuture<void> QtConcurrent::map(Sequence &sequence, MapFunctor function) Calls \a function once for each item in \a sequence. The \a function is passed a reference to the item, so that any modifications done to the item @@ -228,7 +301,7 @@ */ /*! - \fn QFuture<void> QtConcurrent::map(Iterator begin, Iterator end, MapFunction function) + \fn template <typename Iterator, typename MapFunctor> QFuture<void> QtConcurrent::map(Iterator begin, Iterator end, MapFunctor function) Calls \a function once for each item from \a begin to \a end. The \a function is passed a reference to the item, so that any modifications @@ -238,7 +311,7 @@ */ /*! - \fn QFuture<T> QtConcurrent::mapped(const Sequence &sequence, MapFunction function) + \fn template <typename Sequence, typename MapFunctor> QFuture<typename QtPrivate::MapResultType<void, MapFunctor>::ResultType> QtConcurrent::mapped(const Sequence &sequence, MapFunctor function) Calls \a function once for each item in \a sequence and returns a future with each mapped item as a result. You can use QFuture::const_iterator or @@ -248,7 +321,7 @@ */ /*! - \fn QFuture<T> QtConcurrent::mapped(ConstIterator begin, ConstIterator end, MapFunction function) + \fn template <typename Iterator, typename MapFunctor> QFuture<typename QtPrivate::MapResultType<void, MapFunctor>::ResultType> QtConcurrent::mapped(Iterator begin, Iterator end, MapFunctor function) Calls \a function once for each item from \a begin to \a end and returns a future with each mapped item as a result. You can use @@ -258,9 +331,7 @@ */ /*! - \fn QFuture<T> QtConcurrent::mappedReduced(const Sequence &sequence, - MapFunction mapFunction, ReduceFunction reduceFunction, - QtConcurrent::ReduceOptions reduceOptions) + \fn template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor> QFuture<ResultType> QtConcurrent::mappedReduced(const Sequence &sequence, MapFunctor mapFunction, ReduceFunctor reduceFunction, QtConcurrent::ReduceOptions reduceOptions) Calls \a mapFunction once for each item in \a sequence. The return value of each \a mapFunction is passed to \a reduceFunction. @@ -273,9 +344,7 @@ */ /*! - \fn QFuture<T> QtConcurrent::mappedReduced(ConstIterator begin, - ConstIterator end, MapFunction mapFunction, ReduceFunction reduceFunction, - QtConcurrent::ReduceOptions reduceOptions) + \fn template <typename ResultType, typename Iterator, typename MapFunctor, typename ReduceFunctor> QFuture<ResultType> QtConcurrent::mappedReduced(Iterator begin, Iterator end, MapFunctor mapFunction, ReduceFunctor reduceFunction, QtConcurrent::ReduceOptions reduceOptions) Calls \a mapFunction once for each item from \a begin to \a end. The return value of each \a mapFunction is passed to \a reduceFunction. @@ -290,7 +359,7 @@ */ /*! - \fn void QtConcurrent::blockingMap(Sequence &sequence, MapFunction function) + \fn template <typename Sequence, typename MapFunctor> void QtConcurrent::blockingMap(Sequence &sequence, MapFunctor function) Calls \a function once for each item in \a sequence. The \a function is passed a reference to the item, so that any modifications done to the item @@ -302,7 +371,7 @@ */ /*! - \fn void QtConcurrent::blockingMap(Iterator begin, Iterator end, MapFunction function) + \fn template <typename Iterator, typename MapFunctor> void QtConcurrent::blockingMap(Iterator begin, Iterator end, MapFunctor function) Calls \a function once for each item from \a begin to \a end. The \a function is passed a reference to the item, so that any modifications @@ -315,10 +384,10 @@ */ /*! - \fn T QtConcurrent::blockingMapped(const Sequence &sequence, MapFunction function) + \fn template <typename OutputSequence, typename InputSequence, typename MapFunctor> OutputSequence QtConcurrent::blockingMapped(const InputSequence &sequence, MapFunctor function) - Calls \a function once for each item in \a sequence and returns a Sequence containing - the results. The type of the results will match the type returned my the MapFunction. + Calls \a function once for each item in \a sequence and returns an OutputSequence containing + the results. The type of the results will match the type returned my the MapFunctor. \note This function will block until all items in the sequence have been processed. @@ -326,7 +395,7 @@ */ /*! - \fn T QtConcurrent::blockingMapped(ConstIterator begin, ConstIterator end, MapFunction function) + \fn template <typename Sequence, typename Iterator, typename MapFunctor> Sequence QtConcurrent::blockingMapped(Iterator begin, Iterator end, MapFunctor function) Calls \a function once for each item from \a begin to \a end and returns a container with the results. Specify the type of container as the a template @@ -343,7 +412,7 @@ */ /*! - \fn T QtConcurrent::blockingMappedReduced(const Sequence &sequence, MapFunction mapFunction, ReduceFunction reduceFunction, QtConcurrent::ReduceOptions reduceOptions) + \fn template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor> ResultType QtConcurrent::blockingMappedReduced(const Sequence &sequence, MapFunctor mapFunction, ReduceFunctor reduceFunction, QtConcurrent::ReduceOptions reduceOptions) Calls \a mapFunction once for each item in \a sequence. The return value of each \a mapFunction is passed to \a reduceFunction. @@ -358,7 +427,7 @@ */ /*! - \fn T QtConcurrent::blockingMappedReduced(ConstIterator begin, ConstIterator end, MapFunction mapFunction, ReduceFunction reduceFunction, QtConcurrent::ReduceOptions reduceOptions) + \fn template <typename ResultType, typename Iterator, typename MapFunctor, typename ReduceFunctor> ResultType QtConcurrent::blockingMappedReduced(Iterator begin, Iterator end, MapFunctor mapFunction, ReduceFunctor reduceFunction, QtConcurrent::ReduceOptions reduceOptions) Calls \a mapFunction once for each item from \a begin to \a end. The return value of each \a mapFunction is passed to \a reduceFunction. @@ -372,3 +441,39 @@ \sa blockingMappedReduced(), {Concurrent Map and Map-Reduce} */ + +/*! + \class QtConcurrent::FunctionWrapper0 + \inmodule QtConcurrent + \internal +*/ + +/*! + \class QtConcurrent::FunctionWrapper1 + \inmodule QtConcurrent + \internal +*/ + +/*! + \class QtConcurrent::FunctionWrapper2 + \inmodule QtConcurrent + \internal +*/ + +/*! + \class QtConcurrent::MemberFunctionWrapper + \inmodule QtConcurrent + \internal +*/ + +/*! + \class QtConcurrent::MemberFunctionWrapper1 + \inmodule QtConcurrent + \internal +*/ + +/*! + \class QtConcurrent::ConstMemberFunctionWrapper + \inmodule QtConcurrent + \internal +*/ diff --git a/src/concurrent/qtconcurrentmap.h b/src/concurrent/qtconcurrentmap.h index f8acf31f1d..ed1f7cedd1 100644 --- a/src/concurrent/qtconcurrentmap.h +++ b/src/concurrent/qtconcurrentmap.h @@ -42,7 +42,7 @@ #include <QtConcurrent/qtconcurrent_global.h> -#ifndef QT_NO_CONCURRENT +#if !defined(QT_NO_CONCURRENT) || defined(Q_CLANG_QDOC) #include <QtConcurrent/qtconcurrentmapkernel.h> #include <QtConcurrent/qtconcurrentreducekernel.h> @@ -52,53 +52,6 @@ QT_BEGIN_NAMESPACE -#ifdef Q_QDOC - -namespace QtConcurrent { - - QFuture<void> map(Sequence &sequence, MapFunction function); - QFuture<void> map(Iterator begin, Iterator end, MapFunction function); - - template <typename T> - QFuture<T> mapped(const Sequence &sequence, MapFunction function); - template <typename T> - QFuture<T> mapped(ConstIterator begin, ConstIterator end, MapFunction function); - - template <typename T> - QFuture<T> mappedReduced(const Sequence &sequence, - MapFunction function, - ReduceFunction function, - QtConcurrent::ReduceOptions options = UnorderedReduce | SequentialReduce); - template <typename T> - QFuture<T> mappedReduced(ConstIterator begin, - ConstIterator end, - MapFunction function, - ReduceFunction function, - QtConcurrent::ReduceOptions options = UnorderedReduce | SequentialReduce); - - void blockingMap(Sequence &sequence, MapFunction function); - void blockingMap(Iterator begin, Iterator end, MapFunction function); - - template <typename T> - T blockingMapped(const Sequence &sequence, MapFunction function); - template <typename T> - T blockingMapped(ConstIterator begin, ConstIterator end, MapFunction function); - - template <typename T> - T blockingMappedReduced(const Sequence &sequence, - MapFunction function, - ReduceFunction function, - QtConcurrent::ReduceOptions options = UnorderedReduce | SequentialReduce); - template <typename T> - T blockingMappedReduced(ConstIterator begin, - ConstIterator end, - MapFunction function, - ReduceFunction function, - QtConcurrent::ReduceOptions options = UnorderedReduce | SequentialReduce); - -} // namespace QtConcurrent - -#else namespace QtConcurrent { @@ -306,7 +259,6 @@ typename QtPrivate::MapResultType<Iterator, MapFunctor>::ResultType blockingMapp } // namespace QtConcurrent -#endif // Q_QDOC QT_END_NAMESPACE diff --git a/src/concurrent/qtconcurrentmapkernel.h b/src/concurrent/qtconcurrentmapkernel.h index fa162f7c34..e8df668791 100644 --- a/src/concurrent/qtconcurrentmapkernel.h +++ b/src/concurrent/qtconcurrentmapkernel.h @@ -42,7 +42,7 @@ #include <QtConcurrent/qtconcurrent_global.h> -#ifndef QT_NO_CONCURRENT +#if !defined(QT_NO_CONCURRENT) || defined (Q_CLANG_QDOC) #include <QtConcurrent/qtconcurrentiteratekernel.h> #include <QtConcurrent/qtconcurrentreducekernel.h> @@ -50,7 +50,6 @@ QT_BEGIN_NAMESPACE -#ifndef Q_QDOC namespace QtConcurrent { // map kernel, works with both parallel-for and parallel-while @@ -191,12 +190,14 @@ public: } }; +//! [qtconcurrentmapkernel-1] template <typename Iterator, typename Functor> inline ThreadEngineStarter<void> startMap(Iterator begin, Iterator end, Functor functor) { return startThreadEngine(new MapKernel<Iterator, Functor>(begin, end, functor)); } +//! [qtconcurrentmapkernel-2] template <typename T, typename Iterator, typename Functor> inline ThreadEngineStarter<T> startMapped(Iterator begin, Iterator end, Functor functor) { @@ -225,6 +226,7 @@ struct SequenceHolder1 : public Base } }; +//! [qtconcurrentmapkernel-3] template <typename T, typename Sequence, typename Functor> inline ThreadEngineStarter<T> startMapped(const Sequence &sequence, Functor functor) { @@ -235,6 +237,7 @@ inline ThreadEngineStarter<T> startMapped(const Sequence &sequence, Functor func return startThreadEngine(new SequenceHolderType(sequence, functor)); } +//! [qtconcurrentmapkernel-4] template <typename IntermediateType, typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor> inline ThreadEngineStarter<ResultType> startMappedReduced(const Sequence & sequence, MapFunctor mapFunctor, ReduceFunctor reduceFunctor, @@ -247,6 +250,7 @@ inline ThreadEngineStarter<ResultType> startMappedReduced(const Sequence & seque return startThreadEngine(new SequenceHolderType(sequence, mapFunctor, reduceFunctor, options)); } +//! [qtconcurrentmapkernel-5] template <typename IntermediateType, typename ResultType, typename Iterator, typename MapFunctor, typename ReduceFunctor> inline ThreadEngineStarter<ResultType> startMappedReduced(Iterator begin, Iterator end, MapFunctor mapFunctor, ReduceFunctor reduceFunctor, @@ -259,7 +263,6 @@ inline ThreadEngineStarter<ResultType> startMappedReduced(Iterator begin, Iterat } // namespace QtConcurrent -#endif //Q_QDOC QT_END_NAMESPACE diff --git a/src/concurrent/qtconcurrentmedian.h b/src/concurrent/qtconcurrentmedian.h index d0f832812c..87e6b2935d 100644 --- a/src/concurrent/qtconcurrentmedian.h +++ b/src/concurrent/qtconcurrentmedian.h @@ -42,7 +42,7 @@ #include <QtConcurrent/qtconcurrent_global.h> -#ifndef QT_NO_CONCURRENT +#if !defined(QT_NO_CONCURRENT) ||defined(Q_CLANG_QDOC) #include <QtCore/qvector.h> @@ -51,7 +51,6 @@ QT_BEGIN_NAMESPACE -#ifndef Q_QDOC namespace QtConcurrent { @@ -195,7 +194,6 @@ private: } // namespace QtConcurrent -#endif //Q_QDOC QT_END_NAMESPACE diff --git a/src/concurrent/qtconcurrentreducekernel.h b/src/concurrent/qtconcurrentreducekernel.h index c5003a2a0e..d1a283eb53 100644 --- a/src/concurrent/qtconcurrentreducekernel.h +++ b/src/concurrent/qtconcurrentreducekernel.h @@ -42,7 +42,7 @@ #include <QtConcurrent/qtconcurrent_global.h> -#ifndef QT_NO_CONCURRENT +#if !defined(QT_NO_CONCURRENT) || defined(Q_CLANG_QDOC) #include <QtCore/qatomic.h> #include <QtCore/qlist.h> @@ -57,8 +57,6 @@ QT_BEGIN_NAMESPACE namespace QtConcurrent { -#ifndef Q_QDOC - /* The ReduceQueueStartLimit and ReduceQueueThrottleLimit constants limit the reduce queue size for MapReduce. When the number of @@ -66,10 +64,17 @@ namespace QtConcurrent { MapReduce won't start any new threads, and when it exceeds ReduceQueueThrottleLimit running threads will be stopped. */ +#ifdef Q_CLANG_QDOC +enum ReduceQueueLimits { + ReduceQueueStartLimit = 20, + ReduceQueueThrottleLimit = 30 +}; +#else enum { ReduceQueueStartLimit = 20, ReduceQueueThrottleLimit = 30 }; +#endif // IntermediateResults holds a block of intermediate results from a // map or filter functor. The begin/end offsets indicates the origin @@ -82,8 +87,6 @@ public: QVector<T> vector; }; -#endif // Q_QDOC - enum ReduceOption { UnorderedReduce = 0x1, OrderedReduce = 0x2, @@ -91,10 +94,9 @@ enum ReduceOption { // ParallelReduce = 0x8 }; Q_DECLARE_FLAGS(ReduceOptions, ReduceOption) +#ifndef Q_CLANG_QDOC Q_DECLARE_OPERATORS_FOR_FLAGS(ReduceOptions) - -#ifndef Q_QDOC - +#endif // supports both ordered and out-of-order reduction template <typename ReduceFunctor, typename ReduceResultType, typename T> class ReduceKernel @@ -239,8 +241,6 @@ struct SequenceHolder2 : public Base } }; -#endif //Q_QDOC - } // namespace QtConcurrent QT_END_NAMESPACE diff --git a/src/concurrent/qtconcurrentrun.cpp b/src/concurrent/qtconcurrentrun.cpp index 1d8f7afe85..e2e3b3f3af 100644 --- a/src/concurrent/qtconcurrentrun.cpp +++ b/src/concurrent/qtconcurrentrun.cpp @@ -115,6 +115,15 @@ */ /*! + \typedef Function + \internal + + This typedef is a dummy required to make the \c Function + type name known so that clang doesn't reject functions + that use it. +*/ + +/*! \fn QFuture<T> QtConcurrent::run(Function function, ...); Equivalent to diff --git a/src/concurrent/qtconcurrentrun.h b/src/concurrent/qtconcurrentrun.h index c0c0e66913..7963294ebf 100644 --- a/src/concurrent/qtconcurrentrun.h +++ b/src/concurrent/qtconcurrentrun.h @@ -43,15 +43,16 @@ #include <QtConcurrent/qtconcurrentcompilertest.h> -#ifndef QT_NO_CONCURRENT +#if !defined(QT_NO_CONCURRENT) || defined(Q_CLANG_QDOC) #include <QtConcurrent/qtconcurrentrunbase.h> #include <QtConcurrent/qtconcurrentstoredfunctioncall.h> QT_BEGIN_NAMESPACE +#ifdef Q_CLANG_QDOC -#ifdef Q_QDOC +typedef int Function; namespace QtConcurrent { @@ -919,7 +920,7 @@ QFuture<T> run(QThreadPool *pool, const Class *object, T (Class::*fn)(Param1, Pa } //namespace QtConcurrent -#endif // Q_QDOC +#endif // Q_CLANG_QDOC QT_END_NAMESPACE diff --git a/src/concurrent/qtconcurrentthreadengine.cpp b/src/concurrent/qtconcurrentthreadengine.cpp index c7791f8571..8d6bd0efb2 100644 --- a/src/concurrent/qtconcurrentthreadengine.cpp +++ b/src/concurrent/qtconcurrentthreadengine.cpp @@ -39,12 +39,52 @@ #include "qtconcurrentthreadengine.h" -#ifndef QT_NO_CONCURRENT +#if !defined(QT_NO_CONCURRENT) || defined(Q_CLANG_QDOC) QT_BEGIN_NAMESPACE namespace QtConcurrent { +/*! + \class QtConcurrent::ThreadEngineBarrier + \inmodule QtConcurrent + \internal +*/ + +/*! + \enum QtConcurrent::ThreadFunctionResult + \internal +*/ + +/*! + \class QtConcurrent::ThreadEngineBase + \inmodule QtConcurrent + \internal +*/ + +/*! + \class QtConcurrent::ThreadEngine + \inmodule QtConcurrent + \internal +*/ + +/*! + \class QtConcurrent::ThreadEngineStarterBase + \inmodule QtConcurrent + \internal +*/ + +/*! + \class QtConcurrent::ThreadEngineStarter + \inmodule QtConcurrent + \internal +*/ + +/*! + \fn [qtconcurrentthreadengine-1] template <typename ThreadEngine> ThreadEngineStarter<typename ThreadEngine::ResultType> QtConcurrent::startThreadEngine(ThreadEngine *threadEngine) + \internal +*/ + ThreadEngineBarrier::ThreadEngineBarrier() :count(0) { } diff --git a/src/concurrent/qtconcurrentthreadengine.h b/src/concurrent/qtconcurrentthreadengine.h index f915e9adfd..69e42018e6 100644 --- a/src/concurrent/qtconcurrentthreadengine.h +++ b/src/concurrent/qtconcurrentthreadengine.h @@ -42,7 +42,7 @@ #include <QtConcurrent/qtconcurrent_global.h> -#ifndef QT_NO_CONCURRENT +#if !defined(QT_NO_CONCURRENT) ||defined(Q_CLANG_QDOC) #include <QtCore/qthreadpool.h> #include <QtCore/qfuture.h> @@ -55,8 +55,6 @@ QT_BEGIN_NAMESPACE -#ifndef Q_QDOC - namespace QtConcurrent { // The ThreadEngineBarrier counts worker threads, and allows one @@ -113,7 +111,7 @@ private: void startThreads(); void threadExit(); bool threadThrottleExit(); - void run() Q_DECL_OVERRIDE; + void run() override; virtual void asynchronousFinish() = 0; #ifndef QT_NO_EXCEPTIONS void handleException(const QException &exception); @@ -132,7 +130,7 @@ class ThreadEngine : public virtual ThreadEngineBase public: typedef T ResultType; - virtual T *result() { return Q_NULLPTR; } + virtual T *result() { return nullptr; } QFutureInterface<T> *futureInterfaceTyped() { @@ -173,7 +171,7 @@ public: return future; } - void asynchronousFinish() Q_DECL_OVERRIDE + void asynchronousFinish() override { finish(); futureInterfaceTyped()->reportFinished(result()); @@ -259,6 +257,7 @@ public: } }; +//! [qtconcurrentthreadengine-1] template <typename ThreadEngine> inline ThreadEngineStarter<typename ThreadEngine::ResultType> startThreadEngine(ThreadEngine *threadEngine) { @@ -267,7 +266,6 @@ inline ThreadEngineStarter<typename ThreadEngine::ResultType> startThreadEngine( } // namespace QtConcurrent -#endif //Q_QDOC QT_END_NAMESPACE |