summaryrefslogtreecommitdiffstats
path: root/src/xml/dom/qdom.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/xml/dom/qdom.h')
-rw-r--r--src/xml/dom/qdom.h102
1 files changed, 102 insertions, 0 deletions
diff --git a/src/xml/dom/qdom.h b/src/xml/dom/qdom.h
index 22a8f41d8ca..c7213074e25 100644
--- a/src/xml/dom/qdom.h
+++ b/src/xml/dom/qdom.h
@@ -7,8 +7,11 @@
#include <QtXml/qtxmlglobal.h>
#include <QtCore/qcompare.h>
+#include <QtCore/qcontainertools_impl.h>
#include <QtCore/qstring.h>
+#include <iterator>
+
#if QT_CONFIG(dom)
class tst_QDom;
@@ -237,6 +240,105 @@ private:
Q_XML_EXPORT friend bool comparesEqual(const QDomNodeList &lhs, const QDomNodeList &rhs) noexcept;
Q_DECLARE_EQUALITY_COMPARABLE(QDomNodeList)
+ int noexceptLength() const noexcept;
+
+ class It
+ {
+ const QDomNodeList *list;
+ int i;
+
+ friend class QDomNodeList;
+ explicit constexpr It(const QDomNodeList *lp, int ii) noexcept : list(lp), i(ii) {}
+
+ friend constexpr bool comparesEqual(const It &lhs, const It &rhs)
+ { Q_ASSERT(lhs.list == rhs.list); return lhs.i == rhs.i; }
+ friend constexpr Qt::strong_ordering compareThreeWay(const It &lhs, const It &rhs)
+ { Q_ASSERT(lhs.list == rhs.list); return Qt::compareThreeWay(lhs.i, rhs.i); }
+ // macro variant does not exist: Q_DECLARE_STRONGLY_ORDERED_LITERAL_TYPE_NON_NOEXCEPT(It)
+ friend constexpr bool operator==(It lhs, It rhs) {
+ return comparesEqual(lhs, rhs);
+ }
+#ifdef __cpp_lib_three_way_comparison
+ friend constexpr std::strong_ordering operator<=>(It lhs, It rhs) {
+ return compareThreeWay(lhs, rhs);
+ }
+#else
+ friend constexpr bool operator!=(It lhs, It rhs) {
+ return !comparesEqual(lhs, rhs);
+ }
+ friend constexpr bool operator<(It lhs, It rhs) {
+ return is_lt(compareThreeWay(lhs, rhs));
+ }
+ friend constexpr bool operator<=(It lhs, It rhs) {
+ return is_lteq(compareThreeWay(lhs, rhs));
+ }
+ friend constexpr bool operator>(It lhs, It rhs) {
+ return is_gt(compareThreeWay(lhs, rhs));
+ }
+ friend constexpr bool operator>=(It lhs, It rhs) {
+ return is_gteq(compareThreeWay(lhs, rhs));
+ }
+#endif
+
+ public:
+ // Rule Of Zero applies
+ It() = default;
+
+ using iterator_category = std::random_access_iterator_tag;
+ using value_type = QDomNode;
+ using element_type = const QDomNode;
+ using difference_type = qptrdiff; // difference to [container.reqmts]
+ using size_type = int; // difference to [container.reqmts]
+ using reference = value_type; // difference to [container.reqmts]
+ using pointer = QtPrivate::ArrowProxy<reference>;
+
+ reference operator*() const { return list->item(i); }
+ pointer operator->() const { return { **this }; }
+
+ It &operator++() { ++i; return *this; }
+ It operator++(int) { auto copy = *this; ++*this; return copy; }
+
+ It &operator--() { --i; return *this; }
+ It operator--(int) { auto copy = *this; --*this; return copy; }
+
+ It &operator+=(difference_type n) { i += n; return *this; }
+ friend It operator+(It it, difference_type n) { it += n; return it; }
+ friend It operator+(difference_type n, It it) { return it + n; }
+
+ It &operator-=(difference_type n) { i -= n; return *this; }
+ friend It operator-(It it, difference_type n) { it -= n; return it; }
+
+ friend difference_type operator-(It lhs, It rhs)
+ { Q_ASSERT(lhs.list == rhs.list); return lhs.i - rhs.i; }
+
+ reference operator[](difference_type n) const { return *(*this + n); }
+ };
+
+public:
+ using const_iterator = It;
+ using const_reverse_iterator = std::reverse_iterator<const_iterator>;
+
+ using value_type = It::value_type;
+ using difference_type = It::difference_type;
+ using size_type = It::size_type;
+ using reference = It::reference;
+ using const_reference = reference;
+ using pointer = It::pointer;
+ using const_pointer = pointer;
+
+ [[nodiscard]] const_iterator begin() const noexcept { return It{this, 0}; }
+ [[nodiscard]] const_iterator end() const noexcept { return It{this, noexceptLength()}; }
+ [[nodiscard]] const_iterator cbegin() const noexcept { return begin(); }
+ [[nodiscard]] const_iterator cend() const noexcept { return end(); }
+
+ [[nodiscard]] const_reverse_iterator rbegin() const noexcept { return const_reverse_iterator{end()}; }
+ [[nodiscard]] const_reverse_iterator rend() const noexcept { return const_reverse_iterator{begin()}; }
+ [[nodiscard]] const_reverse_iterator crbegin() const noexcept { return rbegin(); }
+ [[nodiscard]] const_reverse_iterator crend() const noexcept { return rend(); }
+
+ [[nodiscard]] const_iterator constBegin() const noexcept { return begin(); }
+ [[nodiscard]] const_iterator constEnd() const noexcept { return end(); }
+
private:
QDomNodeListPrivate* impl;
QDomNodeList(QDomNodeListPrivate*);