QGIS API Documentation  2.0.1-Dufour
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgsfeatureiterator.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsfeatureiterator.h
3  ---------------------
4  begin : Juli 2012
5  copyright : (C) 2012 by Martin Dobias
6  email : wonder dot sk at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 #ifndef QGSFEATUREITERATOR_H
16 #define QGSFEATUREITERATOR_H
17 
18 #include "qgsfeaturerequest.h"
19 
20 
24 class CORE_EXPORT QgsAbstractFeatureIterator
25 {
26  public:
29 
31  virtual ~QgsAbstractFeatureIterator();
32 
34  virtual bool nextFeature( QgsFeature& f ) = 0;
36  virtual bool rewind() = 0;
38  virtual bool close() = 0;
39 
40  protected:
42 
43  bool mClosed;
44 
45  // reference counting (to allow seamless copying of QgsFeatureIterator instances)
46  int refs;
47  void ref(); // add reference
48  void deref(); // remove reference, delete if refs == 0
49  friend class QgsFeatureIterator;
50 };
51 
52 
57 class CORE_EXPORT QgsFeatureIterator
58 {
59  public:
68 
69  QgsFeatureIterator& operator=( const QgsFeatureIterator& other );
70 
71  bool nextFeature( QgsFeature& f );
72  bool rewind();
73  bool close();
74 
76  bool isClosed() const;
77 
78  friend bool operator== ( const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2 );
79  friend bool operator!= ( const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2 );
80 
81  protected:
83 };
84 
86 
88  : mIter( NULL )
89 {
90 }
91 
93  : mIter( iter )
94 {
95  if ( iter )
96  iter->ref();
97 }
98 
100  : mIter( fi.mIter )
101 {
102  if ( mIter )
103  mIter->ref();
104 }
105 
107 {
108  if ( mIter )
109  mIter->deref();
110 }
111 
113 {
114  return mIter ? mIter->nextFeature( f ) : false;
115 }
116 
118 {
119  return mIter ? mIter->rewind() : false;
120 }
121 
123 {
124  return mIter ? mIter->close() : false;
125 }
126 
127 inline bool QgsFeatureIterator::isClosed() const
128 {
129  return mIter ? mIter->mClosed : true;
130 }
131 
132 inline bool operator== ( const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2 )
133 {
134  return ( fi1.mIter == fi2.mIter );
135 }
136 
137 inline bool operator!= ( const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2 )
138 {
139  return !( fi1 == fi2 );
140 }
141 
142 #endif // QGSFEATUREITERATOR_H