Skip to content

Commit

Permalink
Use std::unique_ptr for LayerFeature
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Sep 30, 2018
1 parent 8c85b73 commit a2111b0
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 12 deletions.
43 changes: 38 additions & 5 deletions src/analysis/vector/geometry_checker/qgsgeometrycheckerutils.cpp
Expand Up @@ -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++()
Expand All @@ -127,8 +152,7 @@ bool QgsGeometryCheckerUtils::LayerFeatures::iterator::nextLayerFeature( bool be
}
// End
mFeatureIt = QgsFeatureIds::const_iterator();
delete mCurrentFeature;
mCurrentFeature = nullptr;
mCurrentFeature.reset();
return false;
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 )
Expand Down
15 changes: 8 additions & 7 deletions src/analysis/vector/geometry_checker/qgsgeometrycheckerutils.h
Expand Up @@ -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

Expand Down

0 comments on commit a2111b0

Please sign in to comment.