LeechCraft 0.6.70-17609-g3dde4097dd
Modular cross-platform feature rich live environment.
Loading...
Searching...
No Matches
domchildrenrange.h
Go to the documentation of this file.
1/**********************************************************************
2 * LeechCraft - modular cross-platform feature rich internet client.
3 * Copyright (C) 2006-2014 Georg Rudoy
4 *
5 * Distributed under the Boost Software License, Version 1.0.
6 * (See accompanying file LICENSE or copy at https://www.boost.org/LICENSE_1_0.txt)
7 **********************************************************************/
8
9#pragma once
10
11#include <QDomElement>
12#include <QString>
13#include "sllconfig.h"
14
15namespace LC::Util
16{
43 * @sa DomDescendants()
44 */
45 inline auto DomChildren (const QDomNode& parent, const QString& tag)
46 {
47 struct Iterator
48 {
49#pragma GCC diagnostic push
50#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
51 using difference_type = ptrdiff_t;
52 using value_type = QDomElement;
53 using reference = QDomElement&;
54 using iterator_category = std::forward_iterator_tag;
55#pragma GCC diagnostic pop
56
57 QDomElement Elem_;
58 const QString Tag_;
59
60 bool operator== (const Iterator& other) const
61 {
62 return Elem_ == other.Elem_;
63 }
64
65 Iterator& operator++ ()
66 {
67 Elem_ = Elem_.nextSiblingElement (Tag_);
68 return *this;
69 }
70
71 QDomElement& operator* ()
72 {
73 return Elem_;
74 }
75 };
76
77 struct Range
78 {
79 const Iterator Begin_;
80
81 auto begin () const { return Begin_; }
82 auto end () const { return Iterator {}; }
83 };
84
85 auto firstChild = parent.firstChildElement (tag);
86 return Range { { firstChild, tag } };
87 }
88
101 UTIL_SLL_API QVector<QDomElement> DomDescendants (const QDomElement& parent, const QString& tag);
102}
auto operator==(const T &left, const T &right)
Definition common.h:38
auto DomChildren(const QDomNode &parent, const QString &tag)
Creates a range iterating over direct children named tag.
QVector< QDomElement > DomDescendants(const QDomElement &parent, const QString &tag)
Creates a vector with all descendants of parent named tag.
#define UTIL_SLL_API
Definition sllconfig.h:16