Skip to content
Permalink
Browse files
Use std::unique_ptr for LayerFeature
  • Loading branch information
m-kuhn committed Sep 30, 2018
1 parent 8c85b73 commit a2111b0041aa08401c9c51b12b8959909ffe6aad
@@ -97,13 +97,38 @@ QgsGeometryCheckerUtils::LayerFeatures::iterator::iterator( const QStringList::c
nextLayerFeature( true );
}

QgsGeometryCheckerUtils::LayerFeatures::iterator::iterator( const QgsGeometryCheckerUtils::LayerFeatures::iterator &rh )
{
mLayerIt = rh.mLayerIt;
mFeatureIt = rh.mFeatureIt;
mParent = rh.mParent;
mCurrentFeature = qgis::make_unique<LayerFeature>( *rh.mCurrentFeature.get() );
}

bool QgsGeometryCheckerUtils::LayerFeature::useMapCrs() const
{
return mMapCrs;
}
QgsGeometryCheckerUtils::LayerFeatures::iterator::~iterator()
{
delete mCurrentFeature;
}

QgsGeometryCheckerUtils::LayerFeatures::iterator QgsGeometryCheckerUtils::LayerFeatures::iterator::operator++( int )
{
iterator tmp( *this );
++*this;
return tmp;
}

const QgsGeometryCheckerUtils::LayerFeature &QgsGeometryCheckerUtils::LayerFeatures::iterator::operator*() const
{
Q_ASSERT( mCurrentFeature );
return *mCurrentFeature;
}

bool QgsGeometryCheckerUtils::LayerFeatures::iterator::operator!=( const QgsGeometryCheckerUtils::LayerFeatures::iterator &other )
{
return mLayerIt != other.mLayerIt || mFeatureIt != other.mFeatureIt;
}

const QgsGeometryCheckerUtils::LayerFeatures::iterator &QgsGeometryCheckerUtils::LayerFeatures::iterator::operator++()
@@ -127,8 +152,7 @@ bool QgsGeometryCheckerUtils::LayerFeatures::iterator::nextLayerFeature( bool be
}
// End
mFeatureIt = QgsFeatureIds::const_iterator();
delete mCurrentFeature;
mCurrentFeature = nullptr;
mCurrentFeature.reset();
return false;
}

@@ -173,8 +197,7 @@ bool QgsGeometryCheckerUtils::LayerFeatures::iterator::nextFeature( bool begin )
QgsFeature feature;
if ( featurePool->getFeature( *mFeatureIt, feature ) && feature.geometry() && feature.geometry().constGet() )
{
delete mCurrentFeature;
mCurrentFeature = new LayerFeature( mParent->mFeaturePools[*mLayerIt], feature, mParent->mContext, mParent->mUseMapCrs );
mCurrentFeature.reset( new LayerFeature( mParent->mFeaturePools[*mLayerIt], feature, mParent->mContext, mParent->mUseMapCrs ) );
return true;
}
++mFeatureIt;
@@ -225,6 +248,16 @@ QgsGeometryCheckerUtils::LayerFeatures::LayerFeatures( const QMap<QString, QgsFe
}
}

QgsGeometryCheckerUtils::LayerFeatures::iterator QgsGeometryCheckerUtils::LayerFeatures::begin() const
{
return iterator( mLayerIds.constBegin(), this );
}

QgsGeometryCheckerUtils::LayerFeatures::iterator QgsGeometryCheckerUtils::LayerFeatures::end() const
{
return iterator( mLayerIds.end(), this );
}

/////////////////////////////////////////////////////////////////////////////

std::unique_ptr<QgsGeometryEngine> QgsGeometryCheckerUtils::createGeomEngine( const QgsAbstractGeometry *geometry, double tolerance )
@@ -101,24 +101,25 @@ class ANALYSIS_EXPORT QgsGeometryCheckerUtils
{
public:
iterator( const QList<QString>::const_iterator &layerIt, const LayerFeatures *parent );
iterator( const iterator &rh );
~iterator();
const iterator &operator++();
iterator operator++( int ) { iterator tmp( *this ); ++*this; return tmp; }
const LayerFeature &operator*() const { Q_ASSERT( mCurrentFeature ); return *mCurrentFeature; }
bool operator!=( const iterator &other ) { return mLayerIt != other.mLayerIt || mFeatureIt != other.mFeatureIt; }
iterator operator++( int );
const LayerFeature &operator*() const;
bool operator!=( const iterator &other );

private:
bool nextLayerFeature( bool begin );
bool nextLayer( bool begin );
bool nextFeature( bool begin );
QList<QString>::const_iterator mLayerIt;
QgsFeatureIds::const_iterator mFeatureIt;
const LayerFeatures *mParent;
const LayerFeature *mCurrentFeature = nullptr;
const LayerFeatures *mParent = nullptr;
std::unique_ptr<LayerFeature> mCurrentFeature;
};

iterator begin() const { return iterator( mLayerIds.constBegin(), this ); }
iterator end() const { return iterator( mLayerIds.end(), this ); }
iterator begin() const;
iterator end() const;

#endif

0 comments on commit a2111b0

Please sign in to comment.