CopperSpice API  1.7.2
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))
 
QFuture< T > run (Function function, Args...)
 

Detailed Description

The QtConcurrent namespace provides high-level APIs which makes it possible to write multi-threaded 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::UnorderedReduce0x1Reduction is done in an arbitrary order.
QtConcurrent::OrderedReduce0x2Reduction is done in the order of the original sequence.
QtConcurrent::SequentialReduce0x4Reduction is done sequentially: only one thread will enter the reduce function at a time.

The ReduceOptions type is a typedef for QFlags<ReduceOption>. It stores an OR combination of ReduceOption values.

Function Documentation

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

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

Note: This function will block until all items in 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 item in sequence and returns a new Sequence of kept items. If keep returns true, a copy of the item is put in the new Sequence. Otherwise, the item will not appear in the new Sequence.

Note: This function will block until all items in 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 item from begin to end and returns a new Sequence of kept items. If keep returns true, a copy of the item is put in the new Sequence. Otherwise, the item will not appear in the new Sequence.

Note: This function will block until the iterator reaches the end of the sequence being 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 item in sequence. If keep returns true for an item, that item is then passed to reduce. In other words, the return value is the result of reduce for each item where keep returns true.

Note that 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.

Note: This method will block until all items in the sequence have been processed.

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 item from begin to end. If keep returns true for an item, that item is then passed to reduce. In other words, the return value is the result of reduce for each item where keep returns true.

Note that 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 reduceFunction is called in the order of the original sequence.

Note: This function will block until the iterator reaches the end of the sequence being processed.

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 item from begin to end. The map is passed a reference to the item, so that any modifications done to the item will appear in the sequence which the iterators belong to.

Note: This function will block until the iterator reaches the end of the sequence being processed.

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

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

Note: This function will block until all items in 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 item in sequence and returns a Sequence containing the results. The type of the results will match the type returned my the MapFunction.

Note: This function will block until all items in 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 item from begin to end and returns a container with the results. Specify the type of container as the a template argument, like this:

QList<int> ints = QtConcurrent::blockingMapped<QList<int> >(beginIterator, endIterator, fn);

Note: This function will block until the iterator reaches the end of the sequence being processed.

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 item in sequence. The return value of each map is passed to reduce.

Note that 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.

Note: This function will block until all items in the sequence have been processed.

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 item 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 the iterator reaches the end of the sequence being 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 item in sequence. If filterFunction returns true the item is kept in sequence, otherwise the item 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 item in sequence and returns a new Sequence of kept items. If keep returns true a copy of the item is put in the new Sequence. Otherwise, the item 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 item from begin to end and returns a new Sequence of kept items. If keep returns true, a copy of the item is put in the new Sequence. Otherwise, the item 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 item in sequence. If keep returns true for an item, that item is then passed to reduce. In other words, the return value is the result of reduce for each item where keep returns true.

Note that 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 item from begin to end. If keep returns true for an item, that item is then passed to reduce. In other words, the return value is the result of reduce for each item where keep returns true.

Note that 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 item from begin to end. The map is passed a reference to the item, so that any modifications done to the item 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 item in sequence. The map is passed a reference to the item, so that any modifications done to the item 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 item in sequence and returns a future with each mapped item 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 item from begin to end and returns a future with each mapped item 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 item in sequence. The return value of each map is passed to reduce.

Note that 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 item from begin to end. The return value of each map is passed to reduce.

Note that 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.

Note: QtConcurrent::OrderedReduce results in the ordered reduction.

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

Runs function in a separate thread. The thread is taken from the global QThreadPool. Note that the function may not run immediately; the function 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() function.

Note that the QFuture returned by QtConcurrent::run() does not support canceling, pausing, or progress reporting. The QFuture returned can only be used to query for the running/finished status and the return value of the function.