8#include <QtCore/qglobal.h>
9#include <QtCore/qtypeinfo.h>
10#include <QtCore/qtaggedpointer.h>
15 template<
typename Type,
typename Storage = Type>
18 enum Tag :
bool { Const, Mutable };
19 QTaggedPointer<Storage, Tag> m_pointer;
56 return reinterpret_cast<
const Type *>(m_pointer.data());
61 return m_pointer.tag() == Mutable ?
reinterpret_cast<Type *>(m_pointer.data()) :
nullptr;
74template<
class Iterator,
typename IteratorCategory>
81 [[maybe_unused]]
const auto metaContainer =
this->metaContainer();
82 if constexpr (std::is_base_of_v<std::random_access_iterator_tag, IteratorCategory>) {
83 if (!metaContainer.hasRandomAccessIterator()) {
84 qFatal(
"You cannot use this iterator as a random access iterator");
85 this->clearIterator();
89 if constexpr (std::is_base_of_v<std::bidirectional_iterator_tag, IteratorCategory>) {
90 if (!metaContainer.hasBidirectionalIterator()) {
91 qFatal(
"You cannot use this iterator as a bidirectional iterator");
92 this->clearIterator();
96 if constexpr (std::is_base_of_v<std::forward_iterator_tag, IteratorCategory>) {
97 if (!metaContainer.hasForwardIterator()) {
98 qFatal(
"You cannot use this iterator as a forward iterator");
99 this->clearIterator();
103 if constexpr (std::is_base_of_v<std::input_iterator_tag, IteratorCategory>) {
104 if (!metaContainer.hasInputIterator()) {
105 qFatal(
"You cannot use this iterator as an input iterator");
106 this->clearIterator();
131template<
class Container>
134template<
class Container>
138 QtPrivate::QConstPreservingPointer<QIterable<Container>> m_iterable;
139 void *m_iterator =
nullptr;
154 other.m_iterator =
nullptr;
167 if (
this != &other) {
169 m_iterable = std::move(other.m_iterable);
170 m_iterator = std::move(other.m_iterator);
171 other.m_iterator =
nullptr;
178 if (
this != &other) {
180 m_iterable = other.m_iterable;
188 return m_iterable.mutablePointer();
193 return m_iterable.constPointer();
225template<
class Container>
234 Q_ASSERT(iterable !=
nullptr);
239 return this->metaContainer().compareIterator(
this->constIterator(), o.constIterator());
244 return !
this->metaContainer().compareIterator(
this->constIterator(), o.constIterator());
249 this->metaContainer().advanceIterator(
this->mutableIterator(), 1);
255 QIterable<Container> *iterable =
this->mutableIterable();
256 const Container metaContainer =
this->metaContainer();
257 QIterator result(iterable, metaContainer.begin(iterable->mutableIterable()));
258 metaContainer.copyIterator(result.mutableIterator(),
this->constIterator());
259 metaContainer.advanceIterator(
this->mutableIterator(), 1);
265 this->metaContainer().advanceIterator(
this->mutableIterator(), -1);
271 QIterable<Container> *iterable =
this->mutableIterable();
272 const Container metaContainer =
this->metaContainer();
273 QIterator result(iterable, metaContainer.begin(iterable->mutableIterable()));
274 metaContainer.copyIterator(result.mutableIterator(),
this->constIterator());
275 metaContainer.advanceIterator(
this->mutableIterator(), -1);
281 this->metaContainer().advanceIterator(
this->mutableIterator(), j);
287 this->metaContainer().advanceIterator(
this->mutableIterator(), -j);
293 QIterable<Container> *iterable =
this->mutableIterable();
294 const Container metaContainer =
this->metaContainer();
295 QIterator result(iterable, metaContainer.begin(iterable->mutableIterable()));
296 metaContainer.copyIterator(result.mutableIterator(),
this->constIterator());
297 metaContainer.advanceIterator(result.mutableIterator(), j);
303 QIterable<Container> *iterable =
this->mutableIterable();
304 const Container metaContainer =
this->metaContainer();
305 QIterator result(iterable, metaContainer.begin(iterable->mutableIterable()));
306 metaContainer.copyIterator(result.mutableIterator(),
this->constIterator());
307 metaContainer.advanceIterator(result.mutableIterator(), -j);
313 return this->metaContainer().diffIterator(
this->constIterator(), j.constIterator());
319template<
class Container>
332 return this->metaContainer().compareConstIterator(
333 this->constIterator(), o.constIterator());
338 return !
this->metaContainer().compareConstIterator(
339 this->constIterator(), o.constIterator());
344 this->metaContainer().advanceConstIterator(
this->mutableIterator(), 1);
350 const Container metaContainer =
this->metaContainer();
351 QConstIterator result(
this->constIterable(), metaContainer.constBegin(
352 this->constIterable()->constIterable()));
353 metaContainer.copyConstIterator(result.mutableIterator(),
this->constIterator());
354 metaContainer.advanceConstIterator(
this->mutableIterator(), 1);
360 this->metaContainer().advanceConstIterator(
this->mutableIterator(), -1);
366 const Container metaContainer =
this->metaContainer();
367 QConstIterator result(
this->constIterable(), metaContainer.constBegin(
368 this->constIterable()->constIterable()));
369 metaContainer.copyConstIterator(result.mutableIterator(),
this->constIterator());
370 metaContainer.advanceConstIterator(
this->mutableIterator(), -1);
376 this->metaContainer().advanceConstIterator(
this->mutableIterator(), j);
382 this->metaContainer().advanceConstIterator(
this->mutableIterator(), -j);
388 const Container metaContainer =
this->metaContainer();
390 this->constIterable(),
391 metaContainer.constBegin(
this->constIterable()->constIterable()));
392 metaContainer.copyConstIterator(result.mutableIterator(),
this->constIterator());
393 metaContainer.advanceConstIterator(result.mutableIterator(), j);
399 const Container metaContainer =
this->metaContainer();
400 QConstIterator result(
this->constIterable(), metaContainer.constBegin(
401 this->constIterable()->constIterable()));
402 metaContainer.copyConstIterator(result.mutableIterator(),
this->constIterator());
403 metaContainer.advanceConstIterator(result.mutableIterator(), -j);
409 return this->metaContainer().diffIterator(
this->constIterator(), j.constIterator());
418template<
class Container>
441 template<
typename Pointer>
442 QIterable(
const Container &metaContainer, Pointer iterable)
447 QIterable(
const Container &metaContainer, qsizetype alignment,
const void *p)
452 QIterable(
const Container &metaContainer, qsizetype alignment,
void *p)
506#if QT_VERSION >= QT_VERSION_CHECK(7
, 0
, 0
)
\inmodule QtCore QBaseIterator<Container> forms the common base class for all iterators operating on ...
QBaseIterator(QBaseIterator &&other)
QBaseIterator & operator=(QBaseIterator &&other)
QBaseIterator(QIterable< Container > *iterable, void *iterator)
const QIterable< Container > * constIterable() const
const void * constIterator() const
Returns a const pointer to the internal native iterator.
Container metaContainer() const
QBaseIterator & operator=(const QBaseIterator &other)
void * mutableIterator()
Returns a non-const pointer to the internal native iterator.
QIterable< Container > * mutableIterable() const
QBaseIterator(const QIterable< Container > *iterable, void *iterator)
QBaseIterator(const QBaseIterator &other)
void initIterator(const void *copy)
bool canForwardIterate() const
Returns whether it is possible to iterate over the container in forward direction.
QIterable(const Container &metaContainer, Pointer iterable)
QConstIterator< Container > constEnd() const
Returns a Qterable::QConstIterator for the end of the container.
const void * constIterable() const
QIterator< Container > mutableEnd()
Returns a QMetaSequence::Iterable::iterator for the end of the container.
QIterable(const Container &metaContainer, qsizetype alignment, const void *p)
Container m_metaContainer
bool canReverseIterate() const
Returns whether it is possible to iterate over the container in reverse.
QIterable(const Container &metaContainer, const T *p)
QConstIterator< Container > constBegin() const
Returns a QConstIterator for the beginning of the container.
bool canInputIterate() const
Returns whether the container has an input iterator.
bool canRandomAccessIterate() const
Returns whether it is possible to efficiently skip over multiple values using and iterator.
void clear()
Clears the container.
Container metaContainer() const
QtPrivate::QConstPreservingPointer< void, quint16 > m_iterable
QIterable(const Container &metaContainer, T *p)
QIterable(const Container &metaContainer, qsizetype alignment, void *p)
qsizetype size() const
Returns the number of values in the container.
QIterator< Container > mutableBegin()
Returns a QIterator for the beginning of the container.
QTaggedIterator is a template class that wraps an iterator and exposes standard iterator traits.
QTaggedIterator & operator-=(qsizetype j)
Makes the iterator go back by j items.
friend QTaggedIterator operator+(qsizetype j, const QTaggedIterator &k)
Returns an iterator to the item at j positions forward from iterator k.
bool operator<(const QTaggedIterator &j)
QTaggedIterator operator+(qsizetype j) const
Returns an iterator to the item at j positions forward from this iterator.
QTaggedIterator operator--(int x)
This is an overloaded member function, provided for convenience. It differs from the above function o...
bool operator!=(const QTaggedIterator &o) const
Returns true if other points to a different item than this iterator; otherwise returns false.
QTaggedIterator operator++(int x)
This is an overloaded member function, provided for convenience. It differs from the above function o...
bool operator<=(const QTaggedIterator &j)
bool operator==(const QTaggedIterator &o) const
Returns true if other points to the same item as this iterator; otherwise returns false.
QTaggedIterator & operator--()
The prefix {–} operator ({–it}) makes the preceding item current and returns an iterator to the new c...
QTaggedIterator & operator+=(qsizetype j)
Advances the iterator by j items.
QTaggedIterator & operator++()
The prefix {++} operator ({++it}) advances the iterator to the next item in the container and returns...
bool operator>(const QTaggedIterator &j)
QTaggedIterator operator-(qsizetype j) const
Returns an iterator to the item at j positions backward from this iterator.
QTaggedIterator(Iterator &&it)
Constructs a QTaggedIterator from an iterator or QConstIterator it.
IteratorCategory iterator_category
bool operator>=(const QTaggedIterator &j)
qsizetype operator-(const QTaggedIterator &j) const
Returns the distance between this iterator and j.
const Type * constPointer() const
Type * mutablePointer() const
Q_CORE_EXPORT void warnSynthesizedIterableAccess(SynthesizedAccessFunction function)
SynthesizedAccessFunction
The QConstIterator allows iteration over a container in a QVariant.
bool operator==(const QConstIterator &o) const
Returns true if other points to the same item as this iterator; otherwise returns false.
QConstIterator & operator+=(qsizetype j)
Advances the iterator by j items.
QConstIterator(const QIterable< Container > *iterable, void *iterator)
Creates a QConstIterator to wrap iterator, operating on iterable.
QConstIterator operator++(int)
This is an overloaded member function, provided for convenience. It differs from the above function o...
friend QConstIterator operator+(qsizetype j, const QConstIterator &k)
QConstIterator operator+(qsizetype j) const
Returns an iterator to the item at j positions forward from this iterator.
QConstIterator operator--(int)
This is an overloaded member function, provided for convenience. It differs from the above function o...
bool operator!=(const QConstIterator &o) const
Returns true if other points to a different item than this iterator; otherwise returns false.
qsizetype operator-(const QConstIterator &j) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
QConstIterator & operator-=(qsizetype j)
Makes the iterator go back by j items.
QConstIterator & operator--()
The prefix {–} operator ({–it}) makes the preceding item current and returns an iterator to the new c...
QConstIterator & operator++()
The prefix {++} operator ({++it}) advances the iterator to the next item in the container and returns...
QConstIterator operator-(qsizetype j) const
Returns an iterator to the item at j positions backward from this iterator.
The QIterator is a template class that allows iteration over a container in a QVariant.
bool operator==(const QIterator &o) const
Returns true if other points to the same item as this iterator; otherwise returns false.
friend QIterator operator+(qsizetype j, const QIterator &k)
Returns an iterator to the item at j positions forward from iterator k.
QIterator & operator+=(qsizetype j)
Advances the iterator by j items.
bool operator!=(const QIterator &o) const
Returns true if other points to a different item than this iterator; otherwise returns false.
QIterator operator-(qsizetype j) const
Returns an iterator to the item at j positions backward from this iterator.
QIterator & operator--()
The prefix {–} operator ({–it}) makes the preceding item current and returns an iterator to the new c...
qsizetype operator-(const QIterator &j) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
QIterator & operator-=(qsizetype j)
Makes the iterator go back by j items.
QIterator(QIterable< Container > *iterable, void *iterator)
Creates an iterator from an iterable and a pointer to a native iterator.
QIterator operator++(int)
This is an overloaded member function, provided for convenience. It differs from the above function o...
QIterator operator+(qsizetype j) const
Returns an iterator to the item at j positions forward from this iterator.
QIterator & operator++()
The prefix {++} operator ({++it}) advances the iterator to the next item in the container and returns...
QIterator operator--(int)
This is an overloaded member function, provided for convenience. It differs from the above function o...