MagicSmoke  $VERSION$
domiterator.h
Go to the documentation of this file.
1 //
2 // C++ Implementation: DOM node iterator for range based for loops
3 //
4 //
5 // Author: Konrad Rosenbaum <konrad@silmor.de>, (C) 2013-2014
6 //
7 // Copyright: See README/COPYING.GPL files that come with this distribution
8 //
9 // originally introduced at http://silmor.de/qtstuff.domfor.php
10 
11 #ifndef SMOKE_DOM_ITERATOR_H
12 #define SMOKE_DOM_ITERATOR_H
13 
14 #include "commonexport.h"
15 
17 {
18  int pos;
19  const QDomNodeList&container;
20 public:
21  //constructors and assignments
22  QDomNodeIterator(const QDomNodeList&l,int p):pos(p),container(l){}
23  QDomNodeIterator(const QDomNodeIterator&)=default;
25  QDomNodeIterator& operator=(const QDomNodeIterator&)=default;
26  QDomNodeIterator& operator=(QDomNodeIterator&&)=default;
27 
28  //increment
29  QDomNodeIterator& operator++(){pos++;return *this;}
30 
31  //comparison
32  bool operator==(const QDomNodeIterator&o){return pos==o.pos && container==o.container;}
33  bool operator!=(const QDomNodeIterator&o){return pos!=o.pos || container!=o.container;}
34 
35  //indirection
36  QDomNode operator*(){return container.at(pos);}
37 };
38 
39 //begin and end
40 inline QDomNodeIterator begin(const QDomNodeList&l){return QDomNodeIterator(l,0);}
41 inline QDomNodeIterator end(const QDomNodeList&l){return QDomNodeIterator(l,l.size());}
42 
43 
44 #endif
#define MAGICSMOKE_COMMON_EXPORT
Definition: commonexport.h:7
QDomNodeIterator end(const QDomNodeList &l)
Definition: domiterator.h:41
bool operator!=(const QDomNodeIterator &o)
Definition: domiterator.h:33
QDomNode operator*()
Definition: domiterator.h:36
Definition: domiterator.h:16
QDomNodeIterator & operator++()
Definition: domiterator.h:29
bool operator==(const QDomNodeIterator &o)
Definition: domiterator.h:32
QDomNodeIterator(const QDomNodeList &l, int p)
Definition: domiterator.h:22
QDomNodeIterator begin(const QDomNodeList &l)
Definition: domiterator.h:40