LeechCraft  0.6.70-18450-gabe19ee3b0
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 #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 }
#define UTIL_SLL_API
Definition: sllconfig.h:16
auto operator*(const F &function, const T &functor) -> decltype(Fmap(functor, function))
An operator-style alias for Fmap().
Definition: functor.h:154
auto DomChildren(const QDomNode &parent, const QString &tag)
Creates a range iterating over direct children named tag.
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.