7#include <QtCore/qglobal.h>
8#include <QtCore/qtypeinfo.h>
9#include <QtCore/qtaggedpointer.h>
11#if !defined(QT_LEAN_HEADERS) || QT_LEAN_HEADERS < 1
12# include <QtCore/qmetacontainer.h>
18 template<
typename Type,
typename Storage = Type>
21 enum Tag :
bool { Const, Mutable };
22 QTaggedPointer<Storage, Tag> m_pointer;
59 return reinterpret_cast<
const Type *>(m_pointer.data());
64 return m_pointer.tag() == Mutable ?
reinterpret_cast<Type *>(m_pointer.data()) :
nullptr;
69template<
class Iterator,
typename IteratorCategory>
76 const auto metaContainer =
this->metaContainer();
77 if constexpr (std::is_base_of_v<std::random_access_iterator_tag, IteratorCategory>) {
78 if (!metaContainer.hasRandomAccessIterator()) {
79 qFatal(
"You cannot use this iterator as a random access iterator");
80 this->clearIterator();
84 if constexpr (std::is_base_of_v<std::bidirectional_iterator_tag, IteratorCategory>) {
85 if (!metaContainer.hasBidirectionalIterator()) {
86 qFatal(
"You cannot use this iterator as a bidirectional iterator");
87 this->clearIterator();
91 if constexpr (std::is_base_of_v<std::forward_iterator_tag, IteratorCategory>) {
92 if (!metaContainer.hasForwardIterator()) {
93 qFatal(
"You cannot use this iterator as a forward iterator");
94 this->clearIterator();
98 if constexpr (std::is_base_of_v<std::input_iterator_tag, IteratorCategory>) {
99 if (!metaContainer.hasInputIterator()) {
100 qFatal(
"You cannot use this iterator as an input iterator");
101 this->clearIterator();
105 Q_UNUSED(metaContainer);
128template<
class Container>
131template<
class Container>
135 QtPrivate::QConstPreservingPointer<QIterable<Container>> m_iterable;
136 void *m_iterator =
nullptr;
151 other.m_iterator =
nullptr;
164 if (
this != &other) {
166 m_iterable = std::move(other.m_iterable);
167 m_iterator = std::move(other.m_iterator);
168 other.m_iterator =
nullptr;
175 if (
this != &other) {
177 m_iterable = other.m_iterable;
185 return m_iterable.mutablePointer();
190 return m_iterable.constPointer();
222template<
class Container>
231 Q_ASSERT(iterable !=
nullptr);
236 return this->metaContainer().compareIterator(
this->constIterator(), o.constIterator());
241 return !
this->metaContainer().compareIterator(
this->constIterator(), o.constIterator());
246 this->metaContainer().advanceIterator(
this->mutableIterator(), 1);
252 QIterable<Container> *iterable =
this->mutableIterable();
253 const Container metaContainer =
this->metaContainer();
254 QIterator result(iterable, metaContainer.begin(iterable->mutableIterable()));
255 metaContainer.copyIterator(result.mutableIterator(),
this->constIterator());
256 metaContainer.advanceIterator(
this->mutableIterator(), 1);
262 this->metaContainer().advanceIterator(
this->mutableIterator(), -1);
268 QIterable<Container> *iterable =
this->mutableIterable();
269 const Container metaContainer =
this->metaContainer();
270 QIterator result(iterable, metaContainer.begin(iterable->mutableIterable()));
271 metaContainer.copyIterator(result.mutableIterator(),
this->constIterator());
272 metaContainer.advanceIterator(
this->mutableIterator(), -1);
278 this->metaContainer().advanceIterator(
this->mutableIterator(), j);
284 this->metaContainer().advanceIterator(
this->mutableIterator(), -j);
290 QIterable<Container> *iterable =
this->mutableIterable();
291 const Container metaContainer =
this->metaContainer();
292 QIterator result(iterable, metaContainer.begin(iterable->mutableIterable()));
293 metaContainer.copyIterator(result.mutableIterator(),
this->constIterator());
294 metaContainer.advanceIterator(result.mutableIterator(), j);
300 QIterable<Container> *iterable =
this->mutableIterable();
301 const Container metaContainer =
this->metaContainer();
302 QIterator result(iterable, metaContainer.begin(iterable->mutableIterable()));
303 metaContainer.copyIterator(result.mutableIterator(),
this->constIterator());
304 metaContainer.advanceIterator(result.mutableIterator(), -j);
310 return this->metaContainer().diffIterator(
this->constIterator(), j.constIterator());
316template<
class Container>
329 return this->metaContainer().compareConstIterator(
330 this->constIterator(), o.constIterator());
335 return !
this->metaContainer().compareConstIterator(
336 this->constIterator(), o.constIterator());
341 this->metaContainer().advanceConstIterator(
this->mutableIterator(), 1);
347 const Container metaContainer =
this->metaContainer();
348 QConstIterator result(
this->constIterable(), metaContainer.constBegin(
349 this->constIterable()->constIterable()));
350 metaContainer.copyConstIterator(result.mutableIterator(),
this->constIterator());
351 metaContainer.advanceConstIterator(
this->mutableIterator(), 1);
357 this->metaContainer().advanceConstIterator(
this->mutableIterator(), -1);
363 const Container metaContainer =
this->metaContainer();
364 QConstIterator result(
this->constIterable(), metaContainer.constBegin(
365 this->constIterable()->constIterable()));
366 metaContainer.copyConstIterator(result.mutableIterator(),
this->constIterator());
367 metaContainer.advanceConstIterator(
this->mutableIterator(), -1);
373 this->metaContainer().advanceConstIterator(
this->mutableIterator(), j);
379 this->metaContainer().advanceConstIterator(
this->mutableIterator(), -j);
385 const Container metaContainer =
this->metaContainer();
387 this->constIterable(),
388 metaContainer.constBegin(
this->constIterable()->constIterable()));
389 metaContainer.copyConstIterator(result.mutableIterator(),
this->constIterator());
390 metaContainer.advanceConstIterator(result.mutableIterator(), j);
396 const Container metaContainer =
this->metaContainer();
397 QConstIterator result(
this->constIterable(), metaContainer.constBegin(
398 this->constIterable()->constIterable()));
399 metaContainer.copyConstIterator(result.mutableIterator(),
this->constIterator());
400 metaContainer.advanceConstIterator(result.mutableIterator(), -j);
406 return this->metaContainer().diffIterator(
this->constIterator(), j.constIterator());
415template<
class Container>
438 template<
typename Pointer>
439 QIterable(
const Container &metaContainer, Pointer iterable)
444 QIterable(
const Container &metaContainer, qsizetype alignment,
const void *p)
449 QIterable(
const Container &metaContainer, qsizetype alignment,
void *p)
\inmodule QtCore QBaseIterator forms the common base class for all iterators operating on subclasses ...
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 QSequentialIterable::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.
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
const Type * constPointer() const
Type * mutablePointer() const
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...