7#include <QtCore/qglobal.h>
8#include <QtCore/qtypeinfo.h>
9#include <QtCore/qtaggedpointer.h>
14 template<
typename Type,
typename Storage = Type>
17 enum Tag :
bool { Const, Mutable };
18 QTaggedPointer<Storage, Tag> m_pointer;
55 return reinterpret_cast<
const Type *>(m_pointer.data());
60 return m_pointer.tag() == Mutable ?
reinterpret_cast<Type *>(m_pointer.data()) :
nullptr;
73template<
class Iterator,
typename IteratorCategory>
80 [[maybe_unused]]
const auto metaContainer =
this->metaContainer();
81 if constexpr (std::is_base_of_v<std::random_access_iterator_tag, IteratorCategory>) {
82 if (!metaContainer.hasRandomAccessIterator()) {
83 qFatal(
"You cannot use this iterator as a random access iterator");
84 this->clearIterator();
88 if constexpr (std::is_base_of_v<std::bidirectional_iterator_tag, IteratorCategory>) {
89 if (!metaContainer.hasBidirectionalIterator()) {
90 qFatal(
"You cannot use this iterator as a bidirectional iterator");
91 this->clearIterator();
95 if constexpr (std::is_base_of_v<std::forward_iterator_tag, IteratorCategory>) {
96 if (!metaContainer.hasForwardIterator()) {
97 qFatal(
"You cannot use this iterator as a forward iterator");
98 this->clearIterator();
102 if constexpr (std::is_base_of_v<std::input_iterator_tag, IteratorCategory>) {
103 if (!metaContainer.hasInputIterator()) {
104 qFatal(
"You cannot use this iterator as an input iterator");
105 this->clearIterator();
130template<
class Container>
133template<
class Container>
137 QtPrivate::QConstPreservingPointer<QIterable<Container>> m_iterable;
138 void *m_iterator =
nullptr;
153 other.m_iterator =
nullptr;
166 if (
this != &other) {
168 m_iterable = std::move(other.m_iterable);
169 m_iterator = std::move(other.m_iterator);
170 other.m_iterator =
nullptr;
177 if (
this != &other) {
179 m_iterable = other.m_iterable;
187 return m_iterable.mutablePointer();
192 return m_iterable.constPointer();
224template<
class Container>
233 Q_ASSERT(iterable !=
nullptr);
238 return this->metaContainer().compareIterator(
this->constIterator(), o.constIterator());
243 return !
this->metaContainer().compareIterator(
this->constIterator(), o.constIterator());
248 this->metaContainer().advanceIterator(
this->mutableIterator(), 1);
254 QIterable<Container> *iterable =
this->mutableIterable();
255 const Container metaContainer =
this->metaContainer();
256 QIterator result(iterable, metaContainer.begin(iterable->mutableIterable()));
257 metaContainer.copyIterator(result.mutableIterator(),
this->constIterator());
258 metaContainer.advanceIterator(
this->mutableIterator(), 1);
264 this->metaContainer().advanceIterator(
this->mutableIterator(), -1);
270 QIterable<Container> *iterable =
this->mutableIterable();
271 const Container metaContainer =
this->metaContainer();
272 QIterator result(iterable, metaContainer.begin(iterable->mutableIterable()));
273 metaContainer.copyIterator(result.mutableIterator(),
this->constIterator());
274 metaContainer.advanceIterator(
this->mutableIterator(), -1);
280 this->metaContainer().advanceIterator(
this->mutableIterator(), j);
286 this->metaContainer().advanceIterator(
this->mutableIterator(), -j);
292 QIterable<Container> *iterable =
this->mutableIterable();
293 const Container metaContainer =
this->metaContainer();
294 QIterator result(iterable, metaContainer.begin(iterable->mutableIterable()));
295 metaContainer.copyIterator(result.mutableIterator(),
this->constIterator());
296 metaContainer.advanceIterator(result.mutableIterator(), j);
302 QIterable<Container> *iterable =
this->mutableIterable();
303 const Container metaContainer =
this->metaContainer();
304 QIterator result(iterable, metaContainer.begin(iterable->mutableIterable()));
305 metaContainer.copyIterator(result.mutableIterator(),
this->constIterator());
306 metaContainer.advanceIterator(result.mutableIterator(), -j);
312 return this->metaContainer().diffIterator(
this->constIterator(), j.constIterator());
318template<
class Container>
331 return this->metaContainer().compareConstIterator(
332 this->constIterator(), o.constIterator());
337 return !
this->metaContainer().compareConstIterator(
338 this->constIterator(), o.constIterator());
343 this->metaContainer().advanceConstIterator(
this->mutableIterator(), 1);
349 const Container metaContainer =
this->metaContainer();
350 QConstIterator result(
this->constIterable(), metaContainer.constBegin(
351 this->constIterable()->constIterable()));
352 metaContainer.copyConstIterator(result.mutableIterator(),
this->constIterator());
353 metaContainer.advanceConstIterator(
this->mutableIterator(), 1);
359 this->metaContainer().advanceConstIterator(
this->mutableIterator(), -1);
365 const Container metaContainer =
this->metaContainer();
366 QConstIterator result(
this->constIterable(), metaContainer.constBegin(
367 this->constIterable()->constIterable()));
368 metaContainer.copyConstIterator(result.mutableIterator(),
this->constIterator());
369 metaContainer.advanceConstIterator(
this->mutableIterator(), -1);
375 this->metaContainer().advanceConstIterator(
this->mutableIterator(), j);
381 this->metaContainer().advanceConstIterator(
this->mutableIterator(), -j);
387 const Container metaContainer =
this->metaContainer();
389 this->constIterable(),
390 metaContainer.constBegin(
this->constIterable()->constIterable()));
391 metaContainer.copyConstIterator(result.mutableIterator(),
this->constIterator());
392 metaContainer.advanceConstIterator(result.mutableIterator(), j);
398 const Container metaContainer =
this->metaContainer();
399 QConstIterator result(
this->constIterable(), metaContainer.constBegin(
400 this->constIterable()->constIterable()));
401 metaContainer.copyConstIterator(result.mutableIterator(),
this->constIterator());
402 metaContainer.advanceConstIterator(result.mutableIterator(), -j);
408 return this->metaContainer().diffIterator(
this->constIterator(), j.constIterator());
417template<
class Container>
440 template<
typename Pointer>
441 QIterable(
const Container &metaContainer, Pointer iterable)
446 QIterable(
const Container &metaContainer, qsizetype alignment,
const void *p)
451 QIterable(
const Container &metaContainer, qsizetype alignment,
void *p)
505#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...