Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/QtCore/qsequentialiterable.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 // Copyright (C) 2020 The Qt Company Ltd.
0002 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
0003 
0004 #ifndef QSEQUENTIALITERABLE_H
0005 #define QSEQUENTIALITERABLE_H
0006 
0007 #include <QtCore/qiterable.h>
0008 #include <QtCore/qvariant.h>
0009 
0010 QT_BEGIN_NAMESPACE
0011 
0012 class Q_CORE_EXPORT QSequentialIterator : public QIterator<QMetaSequence>
0013 {
0014 public:
0015     using value_type = QVariant;
0016     using reference = QVariantRef<QSequentialIterator>;
0017     using pointer = QVariantPointer<QSequentialIterator>;
0018 
0019     QSequentialIterator(QIterator &&it)
0020         : QIterator(std::move(it))
0021     {}
0022 
0023     QVariantRef<QSequentialIterator> operator*() const;
0024     QVariantPointer<QSequentialIterator> operator->() const;
0025 };
0026 
0027 class Q_CORE_EXPORT QSequentialConstIterator : public QConstIterator<QMetaSequence>
0028 {
0029 public:
0030     using value_type = QVariant;
0031     using reference = const QVariant &;
0032     using pointer = QVariantConstPointer;
0033 
0034     QSequentialConstIterator(QConstIterator &&it)
0035         : QConstIterator(std::move(it))
0036     {}
0037 
0038     QVariant operator*() const;
0039     QVariantConstPointer operator->() const;
0040 };
0041 
0042 class Q_CORE_EXPORT QSequentialIterable : public QIterable<QMetaSequence>
0043 {
0044 public:
0045     using iterator = QTaggedIterator<QSequentialIterator, void>;
0046     using const_iterator = QTaggedIterator<QSequentialConstIterator, void>;
0047 
0048     using RandomAccessIterator = QTaggedIterator<iterator, std::random_access_iterator_tag>;
0049     using BidirectionalIterator = QTaggedIterator<iterator, std::bidirectional_iterator_tag>;
0050     using ForwardIterator = QTaggedIterator<iterator, std::forward_iterator_tag>;
0051     using InputIterator = QTaggedIterator<iterator, std::input_iterator_tag>;
0052 
0053     using RandomAccessConstIterator = QTaggedIterator<const_iterator, std::random_access_iterator_tag>;
0054     using BidirectionalConstIterator = QTaggedIterator<const_iterator, std::bidirectional_iterator_tag>;
0055     using ForwardConstIterator = QTaggedIterator<const_iterator, std::forward_iterator_tag>;
0056     using InputConstIterator = QTaggedIterator<const_iterator, std::input_iterator_tag>;
0057 
0058     template<class T>
0059     QSequentialIterable(const T *p)
0060         : QIterable(QMetaSequence::fromContainer<T>(), p)
0061     {
0062         Q_UNUSED(m_revision);
0063     }
0064 
0065     template<class T>
0066     QSequentialIterable(T *p)
0067         : QIterable(QMetaSequence::fromContainer<T>(), p)
0068     {
0069     }
0070 
0071     QSequentialIterable()
0072         : QIterable(QMetaSequence(), nullptr)
0073     {
0074     }
0075 
0076     template<typename Pointer>
0077     QSequentialIterable(const QMetaSequence &metaSequence, Pointer iterable)
0078         : QIterable(metaSequence, iterable)
0079     {
0080     }
0081 
0082     // ### Qt7: Pass QMetaType as value rather than const ref.
0083     QSequentialIterable(const QMetaSequence &metaSequence, const QMetaType &metaType,
0084                         void *iterable)
0085         : QIterable(metaSequence, metaType.alignOf(), iterable)
0086     {
0087     }
0088 
0089     // ### Qt7: Pass QMetaType as value rather than const ref.
0090     QSequentialIterable(const QMetaSequence &metaSequence, const QMetaType &metaType,
0091                         const void *iterable)
0092         : QIterable(metaSequence, metaType.alignOf(), iterable)
0093     {
0094     }
0095 
0096     QSequentialIterable(QIterable<QMetaSequence> &&other) : QIterable(std::move(other)) {}
0097 
0098     QSequentialIterable &operator=(QIterable<QMetaSequence> &&other)
0099     {
0100         QIterable::operator=(std::move(other));
0101         return *this;
0102     }
0103 
0104     const_iterator begin() const { return constBegin(); }
0105     const_iterator end() const { return constEnd(); }
0106 
0107     const_iterator constBegin() const { return const_iterator(QIterable::constBegin()); }
0108     const_iterator constEnd() const { return const_iterator(QIterable::constEnd()); }
0109 
0110     iterator mutableBegin() { return iterator(QIterable::mutableBegin()); }
0111     iterator mutableEnd() { return iterator(QIterable::mutableEnd()); }
0112 
0113     QVariant at(qsizetype idx) const;
0114     void set(qsizetype idx, const QVariant &value);
0115 
0116     enum Position { Unspecified, AtBegin, AtEnd };
0117     void addValue(const QVariant &value, Position position = Unspecified);
0118     void removeValue(Position position = Unspecified);
0119 
0120     QMetaType valueMetaType() const;
0121 };
0122 
0123 template<>
0124 inline QVariantRef<QSequentialIterator>::operator QVariant() const
0125 {
0126     if (m_pointer == nullptr)
0127         return QVariant();
0128     const QMetaType metaType(m_pointer->metaContainer().valueMetaType());
0129     QVariant v(metaType);
0130     void *dataPtr = metaType == QMetaType::fromType<QVariant>() ? &v : v.data();
0131     m_pointer->metaContainer().valueAtIterator(m_pointer->constIterator(), dataPtr);
0132     return v;
0133 }
0134 
0135 template<>
0136 inline QVariantRef<QSequentialIterator> &QVariantRef<QSequentialIterator>::operator=(
0137         const QVariant &value)
0138 {
0139     if (m_pointer == nullptr)
0140         return *this;
0141 
0142     QtPrivate::QVariantTypeCoercer coercer;
0143     m_pointer->metaContainer().setValueAtIterator(
0144                 m_pointer->constIterator(),
0145                 coercer.coerce(value, m_pointer->metaContainer().valueMetaType()));
0146     return *this;
0147 }
0148 
0149 Q_DECLARE_TYPEINFO(QSequentialIterable, Q_RELOCATABLE_TYPE);
0150 Q_DECLARE_TYPEINFO(QSequentialIterable::iterator, Q_RELOCATABLE_TYPE);
0151 Q_DECLARE_TYPEINFO(QSequentialIterable::const_iterator, Q_RELOCATABLE_TYPE);
0152 
0153 QT_END_NAMESPACE
0154 
0155 #endif // QSEQUENTIALITERABLE_H