CopperSpice API  1.7.4
QtConcurrent Namespace Reference

Provides high-level APIs to write multi-threaded programs without using low-level threading primitives. More...

Classes

class  Exception
 The QtConcurrent::Exception class provides a base class for exceptions that can transferred across threads More...
 
class  UnhandledException
 Unhandled exception in a worker thread More...
 

Typedefs

using ReduceOptions = QFlags< ReduceOption >
 

Enums

enum  ReduceOption
 

Functions

template<typename Sequence , typename KeepFunctor >
void blockingFilter (Sequence &sequence, KeepFunctor keep)
 
template<typename Sequence , typename KeepFunctor >
Sequence blockingFiltered (const Sequence &sequence, KeepFunctor keep)
 
template<typename OutputSequence , typename Iterator , typename KeepFunctor >
OutputSequence blockingFiltered (Iterator begin, Iterator end, KeepFunctor keep)
 
template<typename ResultType , typename Sequence , typename KeepFunctor , typename ReduceFunctor >
ResultType blockingFilteredReduced (const Sequence &sequence, KeepFunctor keep, ReduceFunctor reduce, ReduceOptions reduceOptions=ReduceOptions (UnorderedReduce|SequentialReduce))
 
template<typename ResultType , typename Iterator , typename KeepFunctor , typename ReduceFunctor >
ResultType blockingFilteredReduced (Iterator begin, Iterator end, KeepFunctor keep, ReduceFunctor reduce, ReduceOptions reduceOptions=ReduceOptions (UnorderedReduce|SequentialReduce))
 
template<typename Iterator , typename MapFunctor >
void blockingMap (Iterator begin, Iterator end, MapFunctor map)
 
template<typename Sequence , typename MapFunctor >
void blockingMap (Sequence &sequence, MapFunctor map)
 
template<typename OutputSequence , typename InputSequence , typename MapFunctor >
OutputSequence blockingMapped (const InputSequence &sequence, MapFunctor map)
 
template<typename Sequence , typename Iterator , typename MapFunctor >
Sequence blockingMapped (Iterator begin, Iterator end, MapFunctor map)
 
template<typename ResultType , typename Sequence , typename MapFunctor , typename ReduceFunctor >
ResultType blockingMappedReduced (const Sequence &sequence, MapFunctor map, ReduceFunctor reduce, ReduceOptions reduceOptions=ReduceOptions (UnorderedReduce|SequentialReduce))
 
template<typename ResultType , typename Iterator , typename MapFunctor , typename ReduceFunctor >
ResultType blockingMappedReduced (Iterator begin, Iterator end, MapFunctor map, ReduceFunctor reduce, QtConcurrent::ReduceOptions reduceOptions=QtConcurrent::ReduceOptions (QtConcurrent::UnorderedReduce| QtConcurrent::SequentialReduce))
 
template<typename Sequence , typename KeepFunctor >
QFuture< void > filter (Sequence &sequence, KeepFunctor keep)
 
template<typename Sequence , typename KeepFunctor >
QFuture< typename Sequence::value_type > filtered (const Sequence &sequence, KeepFunctor keep)
 
template<typename Iterator , typename KeepFunctor >
QFuture< typename qValueType< Iterator >::value_type > filtered (Iterator begin, Iterator end, KeepFunctor keep)
 
template<typename ResultType , typename Sequence , typename KeepFunctor , typename ReduceFunctor >
QFuture< ResultType > filteredReduced (const Sequence &sequence, KeepFunctor keep, ReduceFunctor reduce, ReduceOptions reduceOptions=ReduceOptions (UnorderedReduce|SequentialReduce))
 
template<typename ResultType , typename Iterator , typename KeepFunctor , typename ReduceFunctor >
QFuture< ResultType > filteredReduced (Iterator begin, Iterator end, KeepFunctor keep, ReduceFunctor reduce, ReduceOptions reduceOptions=ReduceOptions (UnorderedReduce|SequentialReduce))
 
template<typename Iterator , typename MapFunctor >
QFuture< void > map (Iterator begin, Iterator end, MapFunctor map)
 
template<typename Sequence , typename MapFunctor >
QFuture< void > map (Sequence &sequence, MapFunctor map)
 
template<typename Sequence , typename MapFunctor >
QFuture< typename QtPrivate::MapResultType< void, MapFunctor >::ResultType > mapped (const Sequence &sequence, MapFunctor map)
 
template<typename Iterator , typename MapFunctor >
QFuture< typename QtPrivate::MapResultType< void, MapFunctor >::ResultType > mapped (Iterator begin, Iterator end, MapFunctor map)
 
template<typename ResultType , typename Sequence , typename MapFunctor , typename ReduceFunctor >
QFuture< ResultType > mappedReduced (const Sequence &sequence, MapFunctor map, ReduceFunctor reduce, ReduceOptions reduceOptions=ReduceOptions (UnorderedReduce|SequentialReduce))
 
template<typename ResultType , typename Iterator , typename MapFunctor , typename ReduceFunctor >
QFuture< ResultType > mappedReduced (Iterator begin, Iterator end, MapFunctor map, ReduceFunctor reduce, ReduceOptions reduceOptions=ReduceOptions (UnorderedReduce|SequentialReduce))
 
template<class T , class Function , class... Args>
QFuture< T > run (Function function, Args...)
 

Detailed Description

The QtConcurrent namespace provides high level APIs which makes it possible to write multithreaded programs without using low-level threading primitives. For additional information refer to Concurrent Threads in the threading documentation.

See also
QtConcurrent::filtered()

Typedef Documentation

Typedef for QFlags<ReduceOption>. It stores an OR combination of ReduceOption values.

Enumeration Type Documentation

This enum specifies the order of which results from the map or filter function are passed to the reduce function.

ConstantValueDescription
QtConcurrent::UnorderedReduce 0x1 Reduction is done in an arbitrary order.
QtConcurrent::OrderedReduce 0x2 Reduction is done in the order of the original sequence.
QtConcurrent::SequentialReduce 0x4 Reduction is done sequentially: only one thread will enter the reduce function at a time.

Function Documentation

template<typename Sequence , typename KeepFunctor >
void QtConcurrent::blockingFilter< Sequence, KeepFunctor > ( Sequence &  sequence,
KeepFunctor  keep 
)

Calls keep once for each element in sequence. If keep returns true the element is kept in the sequence Otherwise the element is removed from the sequence. This method will block until all elements in the the sequence have been processed.

template<typename Sequence , typename KeepFunctor >
Sequence QtConcurrent::blockingFiltered< Sequence, KeepFunctor > ( const Sequence &  sequence,
KeepFunctor  keep 
)

Calls keep once for each element in sequence and returns a new Sequence of kept elements. If keep returns true, a copy of the corresponding element is put in the new Sequence. Otherwise, the element will not appear in the new Sequence. This method will block until all elements in the the sequence have been processed.

See also
QtConcurrent::filtered()
template<typename OutputSequence , typename Iterator , typename KeepFunctor >
Sequence QtConcurrent::blockingFiltered< OutputSequence, Iterator, KeepFunctor > ( Iterator  begin,
Iterator  end,
KeepFunctor  keep 
)

Calls keep once for each element from begin to end and returns a new Sequence of kept elements. If keep returns true a copy of the element is put in the new Sequence. Otherwise, the element will not appear in the new Sequence. This method will block until all elements in the the sequence have been processed.

See also
QtConcurrent::filtered()
template<typename ResultType , typename Sequence , typename KeepFunctor , typename ReduceFunctor >
T QtConcurrent::blockingFilteredReduced< ResultType, Sequence, KeepFunctor, ReduceFunctor > ( const Sequence &  sequence,
KeepFunctor  keep,
ReduceFunctor  reduce,
QtConcurrent::ReduceOptions  reduceOptions = ReduceOptions(UnorderedReduce | SequentialReduce) 
)

Calls keep once for each element in sequence. If keep returns true, the element is passed to reduce. The return value is the result of the final call to reduce. This method will block until all elements in the the sequence have been processed.

While keep is called concurrently only one thread at a time will call reduce. The order in which reduce is called is undefined if reduceOptions is QtConcurrent::UnorderedReduce. If reduceOptions is QtConcurrent::OrderedReduce, reduce is called in the order of the original sequence.

See also
QtConcurrent::filteredReduced()
template<typename ResultType , typename Iterator , typename KeepFunctor , typename ReduceFunctor >
T QtConcurrent::blockingFilteredReduced< ResultType, Iterator, KeepFunctor, ReduceFunctor > ( Iterator  begin,
Iterator  end,
KeepFunctor  keep,
ReduceFunctor  reduce,
QtConcurrent::ReduceOptions  reduceOptions = ReduceOptions(UnorderedReduce | SequentialReduce) 
)

Calls keep once for each element from begin to end. If keep returns true, the element is passed to reduce. The return value is the result of the final call to reduce. This method will block until all elements in the the sequence have been processed.

While keep is called concurrently only one thread at a time will call reduce. The order in which reduce is called is undefined if reduceOptions is QtConcurrent::UnorderedReduce. If reduceOptions is QtConcurrent::OrderedReduce, reduce is called in the order of the original sequence.

See also
QtConcurrent::filteredReduced()
template<typename Iterator , typename MapFunctor >
void QtConcurrent::blockingMap< Iterator, MapFunctor > ( Iterator  begin,
Iterator  end,
MapFunctor  map 
)

Calls map once for each element from begin to end. The map is passed a reference to the element, so any modifications done to the element will appear in the sequence which the iterators belong to. This method will block until all elements in the the sequence have been processed.

See also
QtConcurrent::map()
template<typename Sequence , typename MapFunctor >
void QtConcurrent::blockingMap< Sequence, MapFunctor > ( Sequence &  sequence,
MapFunctor  map 
)

Calls map once for each element in sequence. The map is passed a reference to the element so that any modifications done to the element will appear in sequence. This method will block until all elements in the the sequence have been processed.

See also
QtConcurrent::map()
template<typename OutputSequence , typename InputSequence , typename MapFunctor >
T QtConcurrent::blockingMapped< OutputSequence, InputSequence, MapFunctor > ( const InputSequence &  sequence,
MapFunctor  map 
)

Calls map once for each element in sequence and returns a Sequence containing the results. The type of the results will match the type returned by the MapFunction. This method will block until all elements in the the sequence have been processed.

See also
QtConcurrent::mapped()
template<typename Sequence , typename Iterator , typename MapFunctor >
T QtConcurrent::blockingMapped< Sequence, Iterator, MapFunctor > ( Iterator  begin,
Iterator  end,
MapFunctor  map 
)

Calls map once for each element from begin to end and returns a container with the results. This method will block until all elements in the the sequence have been processed.

Specify the type of container as the a template argument as shown in this example.

QList<int> ints = QtConcurrent::blockingMapped<QList<int> >(beginIterator, endIterator, fn);
See also
QtConcurrent::mapped()
template<typename ResultType , typename Sequence , typename MapFunctor , typename ReduceFunctor >
T QtConcurrent::blockingMappedReduced< ResultType, Sequence, MapFunctor, ReduceFunctor > ( const Sequence &  sequence,
MapFunctor  map,
ReduceFunctor  reduce,
QtConcurrent::ReduceOptions  reduceOptions = ReduceOptions(UnorderedReduce | SequentialReduce) 
)

Calls map once for each element in sequence. The return value of each map is passed to reduce. This method will block until all elements in the the sequence have been processed. While map is called concurrently, only one thread at a time will call reduce. The order in which reduce is called is determined by reduceOptions.

See also
QtConcurrent::mapped()
template<typename ResultType , typename Iterator , typename MapFunctor , typename ReduceFunctor >
T QtConcurrent::blockingMappedReduced< ResultType, Iterator, MapFunctor, ReduceFunctor > ( Iterator  begin,
Iterator  end,
MapFunctor  map,
ReduceFunctor  reduce,
QtConcurrent::ReduceOptions  reduceOptions = QtConcurrent::ReduceOptions(QtConcurrent::UnorderedReduce |            QtConcurrent::SequentialReduce) 
)

Calls map once for each element from begin to end. The return value of each map is passed to reduce. While map is called concurrently, only one thread at a time will call reduce. The order in which reduce is called is undefined. This method will block until all elements in the the sequence have been processed.

See also
QtConcurrent::blockingMappedReduced()
template<typename Sequence , typename KeepFunctor >
QFuture< void > QtConcurrent::filter< Sequence, KeepFunctor > ( Sequence &  sequence,
KeepFunctor  keep 
)

Calls keep once for each element in sequence. If filterFunction returns true the element is kept in sequence, otherwise the element is removed from sequence.

template<typename Sequence , typename KeepFunctor >
QFuture< T > QtConcurrent::filtered< Sequence, KeepFunctor > ( const Sequence &  sequence,
KeepFunctor  keep 
)

Calls keep once for each element in sequence and returns a new Sequence of kept elements. If keep returns true a copy of the element is put in the new Sequence. Otherwise, the element will not appear in the new Sequence.

template<typename Iterator , typename KeepFunctor >
QFuture< T > QtConcurrent::filtered< Iterator, KeepFunctor > ( Iterator  begin,
Iterator  end,
KeepFunctor  keep 
)

Calls keep once for each element from begin to end and returns a new Sequence of kept elements. If keep returns true, a copy of the element is put in the new Sequence. Otherwise, the element will not appear in the new Sequence.

template<typename ResultType , typename Sequence , typename KeepFunctor , typename ReduceFunctor >
QFuture< T > QtConcurrent::filteredReduced< ResultType, Sequence, KeepFunctor, ReduceFunctor > ( const Sequence &  sequence,
KeepFunctor  keep,
ReduceFunctor  reduce,
QtConcurrent::ReduceOptions  reduceOptions = ReduceOptions(UnorderedReduce | SequentialReduce) 
)

Calls keep once for each element in sequence. If keep returns true for an element, that element is then passed to reduce. In other words, the return value is the result of reduce for each element where keep returns true.

While keep is called concurrently, only one thread at a time will call reduce. The order in which reduceFunction is called is undefined if reduceOptions is QtConcurrent::UnorderedReduce. If reduceOptions is QtConcurrent::OrderedReduce, reduce is called in the order of the original sequence.

template<typename ResultType , typename Iterator , typename KeepFunctor , typename ReduceFunctor >
QFuture< T > QtConcurrent::filteredReduced< ResultType, Iterator, KeepFunctor, ReduceFunctor > ( Iterator  begin,
Iterator  end,
KeepFunctor  keep,
ReduceFunctor  reduce,
QtConcurrent::ReduceOptions  reduceOptions = ReduceOptions(UnorderedReduce | SequentialReduce) 
)

Calls keep once for each element from begin to end. If keep returns true for an element, that element is then passed to reduce. In other words, the return value is the result of reduce for each element where keep returns true.

While keep is called concurrently, only one thread at a time will call reduce. The order in which reduce is called is undefined if reduceOptions is QtConcurrent::UnorderedReduce. If reduceOptions is QtConcurrent::OrderedReduce, the reduce is called in the order of the original sequence.

template<typename Iterator , typename MapFunctor >
QFuture< void > QtConcurrent::map< Iterator, MapFunctor > ( Iterator  begin,
Iterator  end,
MapFunctor  map 
)

Calls map once for each element from begin to end. The map is passed a reference to the element, so that any modifications done to the element will appear in the sequence which the iterators belong to.

template<typename Sequence , typename MapFunctor >
QFuture< void > QtConcurrent::map< Sequence, MapFunctor > ( Sequence &  sequence,
MapFunctor  map 
)

Calls map once for each element in sequence. The map is passed a reference to the element, so that any modifications done to the element will appear in sequence.

template<typename Sequence , typename MapFunctor >
QFuture< T > QtConcurrent::mapped< Sequence, MapFunctor > ( const Sequence &  sequence,
MapFunctor  map 
)

Calls map once for each element in sequence and returns a future with each mapped element as a result. You can use QFuture::const_iterator or QFutureIterator to iterate through the results.

template<typename Iterator , typename MapFunctor >
QFuture< T > QtConcurrent::mapped< Iterator, MapFunctor > ( Iterator  begin,
Iterator  end,
MapFunctor  map 
)

Calls map once for each element from begin to end and returns a future with each mapped element as a result. You can use QFuture::const_iterator or QFutureIterator to iterate through the results.

template<typename ResultType , typename Sequence , typename MapFunctor , typename ReduceFunctor >
QFuture< T > QtConcurrent::mappedReduced< ResultType, Sequence, MapFunctor, ReduceFunctor > ( const Sequence &  sequence,
MapFunctor  map,
ReduceFunctor  reduce,
QtConcurrent::ReduceOptions  reduceOptions = ReduceOptions(UnorderedReduce | SequentialReduce) 
)

Calls map once for each element in sequence. The return value of each map is passed to reduce. While map is called concurrently, only one thread at a time will call reduce. The order in which reduceFunction is called is determined by reduceOptions.

template<typename ResultType , typename Iterator , typename MapFunctor , typename ReduceFunctor >
QFuture< T > QtConcurrent::mappedReduced< ResultType, Iterator, MapFunctor, ReduceFunctor > ( Iterator  begin,
Iterator  end,
MapFunctor  map,
ReduceFunctor  reduce,
QtConcurrent::ReduceOptions  reduceOptions = ReduceOptions(UnorderedReduce | SequentialReduce) 
)

Calls map once for each element from begin to end. The return value of each map is passed to reduce. While map is called concurrently, only one thread at a time will call reduce. By default, the order in which reduceFunction is called is undefined.

QtConcurrent::OrderedReduce results in the ordered reduction.

template<class T , class Function , class... Args>
QFuture< T > QtConcurrent::run ( Function  function,
Args...   
)

Runs the given function in a separate thread. The thread is taken from the global QThreadPool. The function may not run immediately and will only be run when a thread is available. T is the same type as the return value of function. Non-void return values can be accessed via the QFuture::result() method.

The QFuture returned by this method does not support canceling, pausing, or progress reporting. The return value can only be used to query for the running/finished status and the return value of the called function.

In order to use this method in your application include the <QtConcurrentRun> header file.