42 #ifndef QTCONCURRENT_RESULTSTORE_H 43 #define QTCONCURRENT_RESULTSTORE_H 45 #include <QtCore/qglobal.h> 49 #include <QtCore/qmap.h> 50 #include <QtCore/qdebug.h> 72 ResultItem(
const void *_result,
int _count) : m_count(_count), result(_result) { }
73 ResultItem(
const void *_result) : m_count(0), result(_result) { }
74 ResultItem() : m_count(0), result(0) { }
75 bool isValid()
const {
return result != 0; }
76 bool isVector()
const {
return m_count != 0; }
77 int count()
const {
return (m_count == 0) ? 1 : m_count; }
87 int vectorIndex()
const;
88 int resultIndex()
const;
90 ResultIteratorBase operator++();
91 int batchSize()
const;
92 void batchedAdvance();
93 bool operator==(
const ResultIteratorBase &other)
const;
94 bool operator!=(
const ResultIteratorBase &other)
const;
95 bool isVector()
const;
96 bool canIncrementVectorIndex()
const;
102 template <
typename T>
103 class ResultIterator :
public ResultIteratorBase
106 ResultIterator(
const ResultIteratorBase &
base)
107 : ResultIteratorBase(base) { }
109 const T &value()
const 114 const T *pointer()
const 116 if (mapIterator.value().isVector())
117 return &(
reinterpret_cast<const QVector<T> *
>(mapIterator.value().result)->
at(m_vectorIndex));
119 return reinterpret_cast<const T *
>(mapIterator.value().result);
127 void setFilterMode(
bool enable);
128 bool filterMode()
const;
129 int addResult(
int index,
const void *result);
130 int addResults(
int index,
const void *results,
int vectorSize,
int logicalCount);
131 ResultIteratorBase begin()
const;
132 ResultIteratorBase
end()
const;
133 bool hasNextResult()
const;
134 ResultIteratorBase resultAt(
int index)
const;
135 bool contains(
int index)
const;
137 virtual ~ResultStoreBase() { };
140 int insertResultItem(
int index, ResultItem &resultItem);
141 void insertResultItemIfValid(
int index, ResultItem &resultItem);
142 void syncPendingResults();
143 void syncResultCount();
144 int updateInsertIndex(
int index,
int _count);
156 template <
typename T>
157 class ResultStore :
public ResultStoreBase
162 ResultStore(
const ResultStoreBase &
base)
163 : ResultStoreBase(base) { }
165 int addResult(
int index,
const T *result)
168 return ResultStoreBase::addResult(index, result);
170 return ResultStoreBase::addResult(index,
new T(*result));
173 int addResults(
int index,
const QVector<T> *results)
175 return ResultStoreBase::addResults(index,
new QVector<T>(*results), results->
count(), results->
count());
178 int addResults(
int index,
const QVector<T> *results,
int totalCount)
180 if (m_filterMode && totalCount && !results->
count())
181 return ResultStoreBase::addResults(index, 0, 0, totalCount);
183 return ResultStoreBase::addResults(index,
new QVector<T>(*results), results->
count(), totalCount);
186 int addCanceledResult(
int index)
188 return addResult(index, 0);
191 int addCanceledResults(
int index,
int _count)
194 return addResults(index, &empty, _count);
197 ResultIterator<T> begin()
const 199 return static_cast<ResultIterator<T>
>(ResultStoreBase::begin());
202 ResultIterator<T>
end()
const 207 ResultIterator<T> resultAt(
int index)
const 209 return static_cast<ResultIterator<T>
>(ResultStoreBase::resultAt(index));
215 while (mapIterator != m_results.constEnd()) {
216 if (mapIterator.
value().isVector())
217 delete reinterpret_cast<const QVector<T> *
>(mapIterator.
value().result);
219 delete reinterpret_cast<const T *
>(mapIterator.
value().result);
240 #endif // QT_NO_CONCURRENT #define QT_END_NAMESPACE
This macro expands to.
int count(const T &t) const
Returns the number of occurrences of value in the vector.
#define at(className, varName)
static void clear(QVariant::Private *d)
bool operator!=(QBool b1, bool b2)
The QVector class is a template class that provides a dynamic array.
#define QT_BEGIN_NAMESPACE
This macro expands to.
The QMap::const_iterator class provides an STL-style const iterator for QMap and QMultiMap.
The QtConcurrent namespace provides high-level APIs that make it possible to write multi-threaded pro...
const T & value() const
Returns the current item's value.
static const KeyPair *const end
bool operator==(QBool b1, bool b2)
The QMap class is a template class that provides a skip-list-based dictionary.