|
QGIS API Documentation
master-6227475
|
00001 /*************************************************************************** 00002 qgsfeatureiterator.h 00003 --------------------- 00004 begin : Juli 2012 00005 copyright : (C) 2012 by Martin Dobias 00006 email : wonder dot sk at gmail dot com 00007 *************************************************************************** 00008 * * 00009 * This program is free software; you can redistribute it and/or modify * 00010 * it under the terms of the GNU General Public License as published by * 00011 * the Free Software Foundation; either version 2 of the License, or * 00012 * (at your option) any later version. * 00013 * * 00014 ***************************************************************************/ 00015 #ifndef QGSFEATUREITERATOR_H 00016 #define QGSFEATUREITERATOR_H 00017 00018 #include "qgsfeaturerequest.h" 00019 00020 00024 class CORE_EXPORT QgsAbstractFeatureIterator 00025 { 00026 public: 00028 QgsAbstractFeatureIterator( const QgsFeatureRequest& request ); 00029 00031 virtual ~QgsAbstractFeatureIterator(); 00032 00034 virtual bool nextFeature( QgsFeature& f ) = 0; 00036 virtual bool rewind() = 0; 00038 virtual bool close() = 0; 00039 00040 protected: 00041 QgsFeatureRequest mRequest; 00042 00043 bool mClosed; 00044 00045 // reference counting (to allow seamless copying of QgsFeatureIterator instances) 00046 int refs; 00047 void ref(); // add reference 00048 void deref(); // remove reference, delete if refs == 0 00049 friend class QgsFeatureIterator; 00050 }; 00051 00052 00057 class CORE_EXPORT QgsFeatureIterator 00058 { 00059 public: 00061 QgsFeatureIterator(); 00063 QgsFeatureIterator( QgsAbstractFeatureIterator* iter ); 00065 QgsFeatureIterator( const QgsFeatureIterator& fi ); 00067 ~QgsFeatureIterator(); 00068 00069 QgsFeatureIterator& operator=( const QgsFeatureIterator& other ); 00070 00071 bool nextFeature( QgsFeature& f ); 00072 bool rewind(); 00073 bool close(); 00074 00076 bool isClosed(); 00077 00078 friend bool operator== ( const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2 ); 00079 friend bool operator!= ( const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2 ); 00080 00081 protected: 00082 QgsAbstractFeatureIterator* mIter; 00083 }; 00084 00086 00087 inline QgsFeatureIterator::QgsFeatureIterator() 00088 : mIter( NULL ) 00089 { 00090 } 00091 00092 inline QgsFeatureIterator::QgsFeatureIterator( QgsAbstractFeatureIterator* iter ) 00093 : mIter( iter ) 00094 { 00095 if ( iter ) 00096 iter->ref(); 00097 } 00098 00099 inline QgsFeatureIterator::QgsFeatureIterator( const QgsFeatureIterator& fi ) 00100 : mIter( fi.mIter ) 00101 { 00102 if ( mIter ) 00103 mIter->ref(); 00104 } 00105 00106 inline QgsFeatureIterator::~QgsFeatureIterator() 00107 { 00108 if ( mIter ) 00109 mIter->deref(); 00110 } 00111 00112 inline bool QgsFeatureIterator::nextFeature( QgsFeature& f ) 00113 { 00114 return mIter ? mIter->nextFeature( f ) : false; 00115 } 00116 00117 inline bool QgsFeatureIterator::rewind() 00118 { 00119 return mIter ? mIter->rewind() : false; 00120 } 00121 00122 inline bool QgsFeatureIterator::close() 00123 { 00124 return mIter ? mIter->close() : false; 00125 } 00126 00127 inline bool QgsFeatureIterator::isClosed() 00128 { 00129 return mIter ? mIter->mClosed : true; 00130 } 00131 00132 00133 inline bool operator== ( const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2 ) 00134 { 00135 return ( fi1.mIter == fi2.mIter ); 00136 } 00137 inline bool operator!= ( const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2 ) 00138 { 00139 return !( fi1 == fi2 ); 00140 } 00141 00142 00143 #endif // QGSFEATUREITERATOR_H