diff -r 000000000000 -r 1918ee327afb src/corelib/concurrent/qtconcurrentmap.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/corelib/concurrent/qtconcurrentmap.h Mon Jan 11 14:00:40 2010 +0000 @@ -0,0 +1,780 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QTCONCURRENT_MAP_H +#define QTCONCURRENT_MAP_H + +#include + +#ifndef QT_NO_CONCURRENT + +#include +#include +#include +#include + +QT_BEGIN_HEADER +QT_BEGIN_NAMESPACE + +QT_MODULE(Core) + +#ifdef qdoc + +namespace QtConcurrent { + + QFuture map(Sequence &sequence, MapFunction function); + QFuture map(Iterator begin, Iterator end, MapFunction function); + + template + QFuture mapped(const Sequence &sequence, MapFunction function); + template + QFuture mapped(ConstIterator begin, ConstIterator end, MapFunction function); + + template + QFuture mappedReduced(const Sequence &sequence, + MapFunction function, + ReduceFunction function, + QtConcurrent::ReduceOptions options = UnorderedReduce | SequentialReduce); + template + QFuture 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 + T blockingMapped(const Sequence &sequence, MapFunction function); + template + T blockingMapped(ConstIterator begin, ConstIterator end, MapFunction function); + + template + T blockingMappedReduced(const Sequence &sequence, + MapFunction function, + ReduceFunction function, + QtConcurrent::ReduceOptions options = UnorderedReduce | SequentialReduce); + template + T blockingMappedReduced(ConstIterator begin, + ConstIterator end, + MapFunction function, + ReduceFunction function, + QtConcurrent::ReduceOptions options = UnorderedReduce | SequentialReduce); + +} // namespace QtConcurrent + +#else + +namespace QtConcurrent { + +// map() on sequences +template +QFuture map(Sequence &sequence, MapFunctor map) +{ + return startMap(sequence.begin(), sequence.end(), map); +} + +template +QFuture map(Sequence &sequence, T (map)(U)) +{ + return startMap(sequence.begin(), sequence.end(), FunctionWrapper1(map)); +} + +template +QFuture map(Sequence &sequence, T (C::*map)()) +{ + return startMap(sequence.begin(), sequence.end(), MemberFunctionWrapper(map)); +} + +// map() on iterators +template +QFuture map(Iterator begin, Iterator end, MapFunctor map) +{ + return startMap(begin, end, map); +} + +template +QFuture map(Iterator begin, Iterator end, T (map)(U)) +{ + return startMap(begin, end, FunctionWrapper1(map)); +} + +template +QFuture map(Iterator begin, Iterator end, T (C::*map)()) +{ + return startMap(begin, end, MemberFunctionWrapper(map)); +} + +// mappedReduced() for sequences. +template +QFuture mappedReduced(const Sequence &sequence, + MapFunctor map, + ReduceFunctor reduce, + ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) +{ + return startMappedReduced + (sequence, map, reduce, options); +} + +template +QFuture mappedReduced(const Sequence &sequence, + MapFunctor map, + T (reduce)(U &, V), + ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) +{ + return startMappedReduced + (sequence, map, FunctionWrapper2(reduce), options); +} + +template +QFuture mappedReduced(const Sequence &sequence, + MapFunctor map, + T (C::*reduce)(U), + ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) +{ + return startMappedReduced + (sequence, map, MemberFunctionWrapper1(reduce), options); +} + +template +QFuture mappedReduced(const Sequence &sequence, + T (map)(U), + ReduceFunctor reduce, + ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) +{ + return startMappedReduced + (sequence, FunctionWrapper1(map), reduce, options); +} + +template +QFuture mappedReduced(const Sequence &sequence, + T (C::*map)() const, + ReduceFunctor reduce, + ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) +{ + return startMappedReduced + (sequence, ConstMemberFunctionWrapper(map), reduce, options); +} + +template +QFuture mappedReduced(const Sequence &sequence, + T (map)(U), + V (reduce)(W &, X), + ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) +{ + return startMappedReduced + (sequence, FunctionWrapper1(map), FunctionWrapper2(reduce), options); +} + +template +QFuture mappedReduced(const Sequence &sequence, + T (C::*map)() const, + U (reduce)(V &, W), + ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) +{ + return startMappedReduced (sequence, ConstMemberFunctionWrapper(map), + FunctionWrapper2(reduce), options); +} + +template +QFuture mappedReduced(const Sequence &sequence, + T (map)(U), + V (C::*reduce)(W), + ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) +{ + return startMappedReduced (sequence, FunctionWrapper1(map), + MemberFunctionWrapper1(reduce), options); +} + +template +QFuture mappedReduced(const Sequence &sequence, + T (C::*map)() const, + U (D::*reduce)(V), + ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) +{ + return startMappedReduced(sequence, ConstMemberFunctionWrapper(map), + MemberFunctionWrapper1(reduce), options); +} + +// mappedReduced() for iterators +template +QFuture mappedReduced(Iterator begin, + Iterator end, + MapFunctor map, + ReduceFunctor reduce, + ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) +{ + return startMappedReduced + (begin, end, map, reduce, options); +} + +template +QFuture mappedReduced(Iterator begin, + Iterator end, + MapFunctor map, + T (reduce)(U &, V), + ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) +{ + return startMappedReduced + (begin, end, map, FunctionWrapper2(reduce), options); +} + +template +QFuture mappedReduced(Iterator begin, + Iterator end, + MapFunctor map, + T (C::*reduce)(U), + ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) +{ + return startMappedReduced + (begin, end, map, MemberFunctionWrapper1(reduce), options); +} + +template +QFuture mappedReduced(Iterator begin, + Iterator end, + T (map)(U), + ReduceFunctor reduce, + ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) +{ + return startMappedReduced + (begin, end, FunctionWrapper1(map), reduce, options); +} + +template +QFuture mappedReduced(Iterator begin, + Iterator end, + T (C::*map)() const, + ReduceFunctor reduce, + ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) +{ + return startMappedReduced + (begin, end, ConstMemberFunctionWrapper(map), reduce, options); +} + +template +QFuture mappedReduced(Iterator begin, + Iterator end, + T (map)(U), + V (reduce)(W &, X), + ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) +{ + return startMappedReduced + (begin, end, FunctionWrapper1(map), FunctionWrapper2(reduce), options); +} + +template +QFuture mappedReduced(Iterator begin, + Iterator end, + T (C::*map)() const, + U (reduce)(V &, W), + ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) +{ + return startMappedReduced(begin, end, ConstMemberFunctionWrapper(map), + FunctionWrapper2(reduce), options); +} + +template +QFuture mappedReduced(Iterator begin, + Iterator end, + T (map)(U), + V (C::*reduce)(W), + ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) +{ + return startMappedReduced + (begin, end, FunctionWrapper1(map), MemberFunctionWrapper1(reduce), options); +} + +template +QFuture mappedReduced(Iterator begin, + Iterator end, + T (C::*map)() const, + U (D::*reduce)(V), + ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) +{ + return startMappedReduced(begin, end, ConstMemberFunctionWrapper(map), + MemberFunctionWrapper1(reduce), options); +} + +// mapped() for sequences +template +QFuture mapped(const Sequence &sequence, MapFunctor map) +{ + return startMapped(sequence, map); +} + +template +QFuture mapped(const Sequence &sequence, T (map)(U)) +{ + return startMapped(sequence, FunctionWrapper1(map)); +} + +template +QFuture mapped(const Sequence &sequence, T (C::*map)() const) +{ + return startMapped(sequence, ConstMemberFunctionWrapper(map)); +} + +// mapped() for iterator ranges. +template +QFuture mapped(Iterator begin, Iterator end, MapFunctor map) +{ + return startMapped(begin, end, map); +} + +template +QFuture mapped(Iterator begin, Iterator end, T (map)(U)) +{ + return startMapped(begin, end, FunctionWrapper1(map)); +} + +template +QFuture mapped(Iterator begin, Iterator end, T (C::*map)() const) +{ + return startMapped(begin, end, ConstMemberFunctionWrapper(map)); +} + + +template +void blockingMap(Sequence &sequence, MapFunctor map) +{ + startMap(sequence.begin(), sequence.end(), map).startBlocking(); +} + +template +void blockingMap(Sequence &sequence, T (map)(U)) +{ + startMap(sequence.begin(), sequence.end(), QtConcurrent::FunctionWrapper1(map)).startBlocking(); +} + +template +void blockingMap(Sequence &sequence, T (C::*map)()) +{ + startMap(sequence.begin(), sequence.end(), QtConcurrent::MemberFunctionWrapper(map)).startBlocking(); +} + +template +void blockingMap(Iterator begin, Iterator end, MapFunctor map) +{ + startMap(begin, end, map).startBlocking(); +} + +template +void blockingMap(Iterator begin, Iterator end, T (map)(U)) +{ + startMap(begin, end, QtConcurrent::FunctionWrapper1(map)).startBlocking(); +} + +template +void blockingMap(Iterator begin, Iterator end, T (C::*map)()) +{ + startMap(begin, end, QtConcurrent::MemberFunctionWrapper(map)).startBlocking(); +} + +template +ResultType blockingMappedReduced(const Sequence &sequence, + MapFunctor map, + ReduceFunctor reduce, + ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) +{ + return QtConcurrent::startMappedReduced + (sequence, map, reduce, options).startBlocking(); +} + +template +U blockingMappedReduced(const Sequence &sequence, + MapFunctor map, + T (reduce)(U &, V), + QtConcurrent::ReduceOptions options = QtConcurrent::ReduceOptions(QtConcurrent::UnorderedReduce | QtConcurrent::SequentialReduce)) +{ + return QtConcurrent::startMappedReduced + (sequence, + map, + QtConcurrent::FunctionWrapper2(reduce), + options) + .startBlocking(); +} + +template +C blockingMappedReduced(const Sequence &sequence, + MapFunctor map, + T (C::*reduce)(U), + QtConcurrent::ReduceOptions options = QtConcurrent::ReduceOptions(QtConcurrent::UnorderedReduce | QtConcurrent::SequentialReduce)) +{ + return QtConcurrent::startMappedReduced + (sequence, + map, + QtConcurrent::MemberFunctionWrapper1(reduce), + options) + .startBlocking(); +} + +template +ResultType blockingMappedReduced(const Sequence &sequence, + T (map)(U), + ReduceFunctor reduce, + QtConcurrent::ReduceOptions options = QtConcurrent::ReduceOptions(QtConcurrent::UnorderedReduce | QtConcurrent::SequentialReduce)) +{ + return QtConcurrent::startMappedReduced + (sequence, + QtConcurrent::FunctionWrapper1(map), + reduce, + options) + .startBlocking(); +} + +template +ResultType blockingMappedReduced(const Sequence &sequence, + T (C::*map)() const, + ReduceFunctor reduce, + QtConcurrent::ReduceOptions options = QtConcurrent::ReduceOptions(QtConcurrent::UnorderedReduce | QtConcurrent::SequentialReduce)) +{ + return QtConcurrent::startMappedReduced + (sequence, + QtConcurrent::ConstMemberFunctionWrapper(map), + reduce, + options) + .startBlocking(); +} + +template +W blockingMappedReduced(const Sequence &sequence, + T (map)(U), + V (reduce)(W &, X), + QtConcurrent::ReduceOptions options = QtConcurrent::ReduceOptions(QtConcurrent::UnorderedReduce | QtConcurrent::SequentialReduce)) +{ + return QtConcurrent::startMappedReduced + (sequence, + QtConcurrent::FunctionWrapper1(map), + QtConcurrent::FunctionWrapper2(reduce), + options) + .startBlocking(); +} + +template +V blockingMappedReduced(const Sequence &sequence, + T (C::*map)() const, + U (reduce)(V &, W), + QtConcurrent::ReduceOptions options = QtConcurrent::ReduceOptions(QtConcurrent::UnorderedReduce | QtConcurrent::SequentialReduce)) +{ + return QtConcurrent::startMappedReduced + (sequence, + QtConcurrent::ConstMemberFunctionWrapper(map), + QtConcurrent::FunctionWrapper2(reduce), + options) + .startBlocking(); +} + +template +C blockingMappedReduced(const Sequence &sequence, + T (map)(U), + V (C::*reduce)(W), + QtConcurrent::ReduceOptions options = QtConcurrent::ReduceOptions(QtConcurrent::UnorderedReduce | QtConcurrent::SequentialReduce)) +{ + return QtConcurrent::startMappedReduced + (sequence, + QtConcurrent::FunctionWrapper1(map), + QtConcurrent::MemberFunctionWrapper1(reduce), + options) + .startBlocking(); +} + +template +D blockingMappedReduced(const Sequence &sequence, + T (C::*map)() const, + U (D::*reduce)(V), + QtConcurrent::ReduceOptions options = QtConcurrent::ReduceOptions(QtConcurrent::UnorderedReduce | QtConcurrent::SequentialReduce)) +{ + return QtConcurrent::startMappedReduced + (sequence, + QtConcurrent::ConstMemberFunctionWrapper(map), + QtConcurrent::MemberFunctionWrapper1(reduce), + options) + .startBlocking(); +} + +template +ResultType blockingMappedReduced(Iterator begin, + Iterator end, + MapFunctor map, + ReduceFunctor reduce, + QtConcurrent::ReduceOptions options = QtConcurrent::ReduceOptions(QtConcurrent::UnorderedReduce | QtConcurrent::SequentialReduce)) +{ + return QtConcurrent::startMappedReduced + (begin, end, map, reduce, options).startBlocking(); +} + +template +U blockingMappedReduced(Iterator begin, + Iterator end, + MapFunctor map, + T (reduce)(U &, V), + QtConcurrent::ReduceOptions options = QtConcurrent::ReduceOptions(QtConcurrent::UnorderedReduce | QtConcurrent::SequentialReduce)) +{ + return QtConcurrent::startMappedReduced + (begin, + end, + map, + QtConcurrent::FunctionWrapper2(reduce), + options) + .startBlocking(); +} + +template +C blockingMappedReduced(Iterator begin, + Iterator end, + MapFunctor map, + T (C::*reduce)(U), + QtConcurrent::ReduceOptions options = QtConcurrent::ReduceOptions(QtConcurrent::UnorderedReduce | QtConcurrent::SequentialReduce)) +{ + return QtConcurrent::startMappedReduced + (begin, + end, + map, + QtConcurrent::MemberFunctionWrapper1(reduce), + options) + .startBlocking(); +} + +template +ResultType blockingMappedReduced(Iterator begin, + Iterator end, + T (map)(U), + ReduceFunctor reduce, + QtConcurrent::ReduceOptions options = QtConcurrent::ReduceOptions(QtConcurrent::UnorderedReduce | QtConcurrent::SequentialReduce)) +{ + return QtConcurrent::startMappedReduced + (begin, + end, + QtConcurrent::FunctionWrapper1(map), + reduce, + options) + .startBlocking(); +} + +template +ResultType blockingMappedReduced(Iterator begin, + Iterator end, + T (C::*map)() const, + ReduceFunctor reduce, + QtConcurrent::ReduceOptions options = QtConcurrent::ReduceOptions(QtConcurrent::UnorderedReduce | QtConcurrent::SequentialReduce)) +{ + return QtConcurrent::startMappedReduced + (begin, + end, + QtConcurrent::ConstMemberFunctionWrapper(map), + reduce, + options) + .startBlocking(); +} + +template +W blockingMappedReduced(Iterator begin, + Iterator end, + T (map)(U), + V (reduce)(W &, X), + QtConcurrent::ReduceOptions options = QtConcurrent::ReduceOptions(QtConcurrent::UnorderedReduce | QtConcurrent::SequentialReduce)) +{ + return QtConcurrent::startMappedReduced + (begin, + end, + QtConcurrent::FunctionWrapper1(map), + QtConcurrent::FunctionWrapper2(reduce), + options) + .startBlocking(); +} + +template +V blockingMappedReduced(Iterator begin, + Iterator end, + T (C::*map)() const, + U (reduce)(V &, W), + QtConcurrent::ReduceOptions options = QtConcurrent::ReduceOptions(QtConcurrent::UnorderedReduce | QtConcurrent::SequentialReduce)) +{ + return QtConcurrent::startMappedReduced + (begin, + end, + QtConcurrent::ConstMemberFunctionWrapper(map), + QtConcurrent::FunctionWrapper2(reduce), + options) + .startBlocking(); +} + +template +C blockingMappedReduced(Iterator begin, + Iterator end, + T (map)(U), + V (C::*reduce)(W), + QtConcurrent::ReduceOptions options = QtConcurrent::ReduceOptions(QtConcurrent::UnorderedReduce | QtConcurrent::SequentialReduce)) +{ + return QtConcurrent::startMappedReduced + (begin, + end, + QtConcurrent::FunctionWrapper1(map), + QtConcurrent::MemberFunctionWrapper1(reduce), + options) + .startBlocking(); +} + +template +D blockingMappedReduced(Iterator begin, + Iterator end, + T (C::*map)() const, + U (D::*reduce)(V), + QtConcurrent::ReduceOptions options = QtConcurrent::ReduceOptions(QtConcurrent::UnorderedReduce | QtConcurrent::SequentialReduce)) +{ + return QtConcurrent::startMappedReduced + (begin, + end, + QtConcurrent::ConstMemberFunctionWrapper(map), + QtConcurrent::MemberFunctionWrapper1(reduce), + options) + .startBlocking(); +} + +// mapped() for sequences with a different putput sequence type. +template +OutputSequence blockingMapped(const InputSequence &sequence, MapFunctor map) +{ + return blockingMappedReduced(sequence, map, &OutputSequence::push_back, + QtConcurrent::OrderedReduce); +} + +template +OutputSequence blockingMapped(const InputSequence &sequence, T (map)(U)) +{ + return blockingMappedReduced(sequence, map, &OutputSequence::push_back, + QtConcurrent::OrderedReduce); +} + +template +OutputSequence blockingMapped(const InputSequence &sequence, T (C::*map)() const) +{ + return blockingMappedReduced(sequence, map, &OutputSequence::push_back, + QtConcurrent::OrderedReduce); +} +#ifndef QT_NO_TEMPLATE_TEMPLATE_PARAMETERS + +// overloads for changing the container value type: +template