LeechCraft  0.6.70-16373-g319c272718
Modular cross-platform feature rich live environment.
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 
15 namespace LC::Util
16 {
45  inline auto DomChildren (const QDomNode& parent, const QString& tag)
46  {
47  struct Iterator
48  {
49  using difference_type = ptrdiff_t;
50  using value_type = QDomElement;
51  using reference = QDomElement&;
52  using iterator_category = std::forward_iterator_tag;
53 
54  QDomElement Elem_;
55  const QString Tag_;
56 
57  bool operator== (const Iterator& other) const
58  {
59  return Elem_ == other.Elem_;
60  }
61 
62  Iterator& operator++ ()
63  {
64  Elem_ = Elem_.nextSiblingElement (Tag_);
65  return *this;
66  }
67 
68  QDomElement& operator* ()
69  {
70  return Elem_;
71  }
72  };
73 
74  struct Range
75  {
76  const Iterator Begin_;
77 
78  auto begin () const { return Begin_; }
79  auto end () const { return Iterator {}; }
80  };
81 
82  auto firstChild = parent.firstChildElement (tag);
83  return Range { { firstChild, tag } };
84  }
85 
98  UTIL_SLL_API QVector<QDomElement> DomDescendants (const QDomElement& parent, const QString& tag);
99 }
#define UTIL_SLL_API
Definition: sllconfig.h:16
auto DomChildren(const QDomNode &parent, const QString &tag)
Creates a range iterating over direct children named tag.
auto operator*(const AF &af, const AV &av) -> decltype(GSL(af, av))
Definition: applicative.h:43
bool operator==(const ModelIterator &left, const ModelIterator &right)
QVector< QDomElement > DomDescendants(const QDomElement &parent, const QString &tag)
Creates a vector with all descendants of parent named tag.