LeechCraft 0.6.70-14794-g33744ae6ce
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 <boost/iterator.hpp>
12#include <boost/iterator/function_input_iterator.hpp>
13#include <boost/range.hpp>
14#include <QDomElement>
15#include <QString>
16
17namespace LC
18{
19namespace Util
20{
21 namespace detail
22 {
23 class DomSiblingsIterator : public boost::iterator_facade<
24 DomSiblingsIterator,
25 QDomElement,
26 boost::single_pass_traversal_tag,
27 const QDomElement&
28 >
29 {
30 QDomElement Elem_;
31 const QString TagName_;
32 public:
33 DomSiblingsIterator () = default;
34
35 DomSiblingsIterator (const QDomElement& firstChild, const QString& tagName)
36 : Elem_ { firstChild }
37 , TagName_ { tagName }
38 {
39 }
40
41 void increment ()
42 {
43 Elem_ = Elem_.nextSiblingElement (TagName_);
44 }
45
46 const QDomElement& dereference () const
47 {
48 return Elem_;
49 }
50
51 bool equal (const DomSiblingsIterator& other) const
52 {
53 return Elem_ == other.Elem_;
54 }
55 };
56 }
57
84 inline auto DomChildren (const QDomNode& parent, const QString& tag)
85 {
86 auto child = parent.firstChildElement (tag);
87 return boost::make_iterator_range<detail::DomSiblingsIterator> ({ child, tag }, {});
88 }
89}
90}
DomSiblingsIterator(const QDomElement &firstChild, const QString &tagName)
bool equal(const DomSiblingsIterator &other) const
const QDomElement & dereference() const
auto DomChildren(const QDomNode &parent, const QString &tag)
Creates a range iterating over direct children named tag.
Definition: constants.h:15