Skip to content
Permalink
Browse files

Merge pull request #4751 from nyalldawson/unique_ptr

Return std::unique_ptrs where possible
  • Loading branch information
nyalldawson committed Aug 17, 2017
2 parents fad5973 + e0d1ddc commit 26a911cd61c46ee3c381803e1cc7bb89ca2c0013
@@ -782,7 +782,7 @@ bool QgsAuthManager::registerCoreAuthMethods()
mAuthMethods.clear();
Q_FOREACH ( const QString &authMethodKey, QgsAuthMethodRegistry::instance()->authMethodList() )
{
mAuthMethods.insert( authMethodKey, QgsAuthMethodRegistry::instance()->authMethod( authMethodKey ) );
mAuthMethods.insert( authMethodKey, QgsAuthMethodRegistry::instance()->authMethod( authMethodKey ).release() );
}

return !mAuthMethods.isEmpty();
@@ -260,7 +260,7 @@ void QgsAuthMethodRegistry::setLibraryDirectory( const QDir &path )
// typedef for the QgsDataProvider class factory
typedef QgsAuthMethod *classFactoryFunction_t();

QgsAuthMethod *QgsAuthMethodRegistry::authMethod( const QString &authMethodKey )
std::unique_ptr<QgsAuthMethod> QgsAuthMethodRegistry::authMethod( const QString &authMethodKey )
{
// load the plugin
QString lib = library( authMethodKey );
@@ -299,7 +299,7 @@ QgsAuthMethod *QgsAuthMethodRegistry::authMethod( const QString &authMethodKey )
return nullptr;
}

QgsAuthMethod *authMethod = classFactory();
std::unique_ptr< QgsAuthMethod > authMethod( classFactory() );
if ( !authMethod )
{
QgsMessageLog::logMessage( QObject::tr( "Unable to instantiate the auth method plugin %1" ).arg( lib ) );
@@ -342,19 +342,16 @@ QFunctionPointer QgsAuthMethodRegistry::function( QString const &authMethodKey,
}
}

QLibrary *QgsAuthMethodRegistry::authMethodLibrary( const QString &authMethodKey ) const
std::unique_ptr<QLibrary> QgsAuthMethodRegistry::authMethodLibrary( const QString &authMethodKey ) const
{
QLibrary *myLib = new QLibrary( library( authMethodKey ) );
std::unique_ptr< QLibrary > myLib( new QLibrary( library( authMethodKey ) ) );

QgsDebugMsg( "Library name is " + myLib->fileName() );

if ( myLib->load() )
return myLib;

QgsDebugMsg( "Cannot load library: " + myLib->errorString() );

delete myLib;

return nullptr;
}

@@ -23,6 +23,7 @@
#include <QLibrary>
#include <QMap>
#include <QString>
#include <memory>

#include "qgis_core.h"

@@ -67,7 +68,7 @@ class CORE_EXPORT QgsAuthMethodRegistry
\param authMethodKey identificator of the auth method
\returns instance of auth method or nullptr on error
*/
QgsAuthMethod *authMethod( const QString &authMethodKey );
std::unique_ptr< QgsAuthMethod > authMethod( const QString &authMethodKey );

/** Return the auth method capabilities
\param authMethodKey identificator of the auth method
@@ -89,7 +90,7 @@ class CORE_EXPORT QgsAuthMethodRegistry
const QString &functionName );

//! Return the library object associated with an auth method key
QLibrary *authMethodLibrary( const QString &authMethodKey ) const;
std::unique_ptr< QLibrary > authMethodLibrary( const QString &authMethodKey ) const;

//! Return list of available auth methods by their keys
QStringList authMethodList() const;
@@ -134,70 +134,70 @@ bool QgsGeometry::isNull() const

QgsGeometry QgsGeometry::fromWkt( const QString &wkt )
{
QgsAbstractGeometry *geom = QgsGeometryFactory::geomFromWkt( wkt );
std::unique_ptr< QgsAbstractGeometry > geom = QgsGeometryFactory::geomFromWkt( wkt );
if ( !geom )
{
return QgsGeometry();
}
return QgsGeometry( geom );
return QgsGeometry( geom.release() );
}

QgsGeometry QgsGeometry::fromPoint( const QgsPointXY &point )
{
QgsAbstractGeometry *geom = QgsGeometryFactory::fromPoint( point );
std::unique_ptr< QgsAbstractGeometry > geom( QgsGeometryFactory::fromPoint( point ) );
if ( geom )
{
return QgsGeometry( geom );
return QgsGeometry( geom.release() );
}
return QgsGeometry();
}

QgsGeometry QgsGeometry::fromPolyline( const QgsPolyline &polyline )
{
QgsAbstractGeometry *geom = QgsGeometryFactory::fromPolyline( polyline );
std::unique_ptr< QgsAbstractGeometry > geom = QgsGeometryFactory::fromPolyline( polyline );
if ( geom )
{
return QgsGeometry( geom );
return QgsGeometry( geom.release() );
}
return QgsGeometry();
}

QgsGeometry QgsGeometry::fromPolygon( const QgsPolygon &polygon )
{
QgsAbstractGeometry *geom = QgsGeometryFactory::fromPolygon( polygon );
std::unique_ptr< QgsPolygonV2 > geom = QgsGeometryFactory::fromPolygon( polygon );
if ( geom )
{
return QgsGeometry( geom );
return QgsGeometry( geom.release() );
}
return QgsGeometry();
}

QgsGeometry QgsGeometry::fromMultiPoint( const QgsMultiPoint &multipoint )
{
QgsAbstractGeometry *geom = QgsGeometryFactory::fromMultiPoint( multipoint );
std::unique_ptr< QgsMultiPointV2 > geom = QgsGeometryFactory::fromMultiPoint( multipoint );
if ( geom )
{
return QgsGeometry( geom );
return QgsGeometry( geom.release() );
}
return QgsGeometry();
}

QgsGeometry QgsGeometry::fromMultiPolyline( const QgsMultiPolyline &multiline )
{
QgsAbstractGeometry *geom = QgsGeometryFactory::fromMultiPolyline( multiline );
std::unique_ptr< QgsMultiLineString > geom = QgsGeometryFactory::fromMultiPolyline( multiline );
if ( geom )
{
return QgsGeometry( geom );
return QgsGeometry( geom.release() );
}
return QgsGeometry();
}

QgsGeometry QgsGeometry::fromMultiPolygon( const QgsMultiPolygon &multipoly )
{
QgsAbstractGeometry *geom = QgsGeometryFactory::fromMultiPolygon( multipoly );
std::unique_ptr< QgsMultiPolygonV2 > geom = QgsGeometryFactory::fromMultiPolygon( multipoly );
if ( geom )
{
return QgsGeometry( geom );
return QgsGeometry( geom.release() );
}
return QgsGeometry();
}
@@ -246,7 +246,7 @@ void QgsGeometry::fromWkb( unsigned char *wkb, int length )
delete d->geometry;
}
QgsConstWkbPtr ptr( wkb, length );
d->geometry = QgsGeometryFactory::geomFromWkb( ptr );
d->geometry = QgsGeometryFactory::geomFromWkb( ptr ).release();
delete [] wkb;
}

@@ -259,7 +259,7 @@ void QgsGeometry::fromWkb( const QByteArray &wkb )
delete d->geometry;
}
QgsConstWkbPtr ptr( wkb );
d->geometry = QgsGeometryFactory::geomFromWkb( ptr );
d->geometry = QgsGeometryFactory::geomFromWkb( ptr ).release();
}

GEOSGeometry *QgsGeometry::exportToGeos( double precision ) const
@@ -1155,16 +1155,16 @@ bool QgsGeometry::convertToMultiType()
return true;
}

QgsGeometryCollection *multiGeom = qgsgeometry_cast<QgsGeometryCollection *>
( QgsGeometryFactory::geomFromWkbType( QgsWkbTypes::multiType( d->geometry->wkbType() ) ) );
std::unique_ptr< QgsAbstractGeometry >geom = QgsGeometryFactory::geomFromWkbType( QgsWkbTypes::multiType( d->geometry->wkbType() ) );
QgsGeometryCollection *multiGeom = qgsgeometry_cast<QgsGeometryCollection *>( geom.get() );
if ( !multiGeom )
{
return false;
}

detach( true );
multiGeom->addGeometry( d->geometry );
d->geometry = multiGeom;
d->geometry = geom.release();
return true;
}

@@ -2026,11 +2026,11 @@ int QgsGeometry::avoidIntersections( const QList<QgsVectorLayer *> &avoidInterse
return 1;
}

QgsAbstractGeometry *diffGeom = QgsGeometryEditUtils::avoidIntersections( *( d->geometry ), avoidIntersectionsLayers, ignoreFeatures );
std::unique_ptr< QgsAbstractGeometry > diffGeom = QgsGeometryEditUtils::avoidIntersections( *( d->geometry ), avoidIntersectionsLayers, ignoreFeatures );
if ( diffGeom )
{
detach( false );
d->geometry = diffGeom;
d->geometry = diffGeom.release();
}
return 0;
}
@@ -219,10 +219,10 @@ bool QgsGeometryCollection::fromWkb( QgsConstWkbPtr &wkbPtr )
mGeometries.clear();
for ( int i = 0; i < nGeometries; ++i )
{
QgsAbstractGeometry *geom = QgsGeometryFactory::geomFromWkb( wkbPtr ); // also updates wkbPtr
std::unique_ptr< QgsAbstractGeometry > geom( QgsGeometryFactory::geomFromWkb( wkbPtr ) ); // also updates wkbPtr
if ( geom )
{
if ( !addGeometry( geom ) )
if ( !addGeometry( geom.release() ) )
{
qDeleteAll( mGeometries );
mGeometries = geometryListBackup;
@@ -597,11 +597,10 @@ bool QgsGeometryCollection::hasCurvedSegments() const

QgsAbstractGeometry *QgsGeometryCollection::segmentize( double tolerance, SegmentationToleranceType toleranceType ) const
{
QgsAbstractGeometry *geom = QgsGeometryFactory::geomFromWkbType( mWkbType );
QgsGeometryCollection *geomCollection = qgsgeometry_cast<QgsGeometryCollection *>( geom );
std::unique_ptr< QgsAbstractGeometry > geom( QgsGeometryFactory::geomFromWkbType( mWkbType ) );
QgsGeometryCollection *geomCollection = qgsgeometry_cast<QgsGeometryCollection *>( geom.get() );
if ( !geomCollection )
{
delete geom;
return clone();
}

@@ -610,7 +609,7 @@ QgsAbstractGeometry *QgsGeometryCollection::segmentize( double tolerance, Segmen
{
geomCollection->addGeometry( ( *geomIt )->segmentize( tolerance, toleranceType ) );
}
return geomCollection;
return geom.release();
}

double QgsGeometryCollection::vertexAngle( QgsVertexId vertex ) const
@@ -221,7 +221,7 @@ bool QgsGeometryEditUtils::deletePart( QgsAbstractGeometry *geom, int partNum )
return c->removeGeometry( partNum );
}

QgsAbstractGeometry *QgsGeometryEditUtils::avoidIntersections( const QgsAbstractGeometry &geom,
std::unique_ptr<QgsAbstractGeometry> QgsGeometryEditUtils::avoidIntersections( const QgsAbstractGeometry &geom,
const QList<QgsVectorLayer *> &avoidIntersectionsLayers,
QHash<QgsVectorLayer *, QSet<QgsFeatureId> > ignoreFeatures )
{
@@ -281,7 +281,7 @@ QgsAbstractGeometry *QgsGeometryEditUtils::avoidIntersections( const QgsAbstract
return nullptr;
}

QgsAbstractGeometry *diffGeom = geomEngine->difference( combinedGeometries );
std::unique_ptr< QgsAbstractGeometry > diffGeom( geomEngine->difference( combinedGeometries ) );

delete combinedGeometries;
return diffGeom;
@@ -26,6 +26,7 @@ class QgsVectorLayer;
#include "qgsfeature.h"
#include "qgsgeometry.h"
#include <QMap>
#include <memory>

/** \ingroup core
* \class QgsGeometryEditUtils
@@ -69,7 +70,7 @@ class QgsGeometryEditUtils
* \param avoidIntersectionsLayers list of layers to check for intersections
* \param ignoreFeatures map of layer to feature id of features to ignore
*/
static QgsAbstractGeometry *avoidIntersections( const QgsAbstractGeometry &geom,
static std::unique_ptr< QgsAbstractGeometry > avoidIntersections( const QgsAbstractGeometry &geom,
const QList<QgsVectorLayer *> &avoidIntersectionsLayers,
QHash<QgsVectorLayer *, QSet<QgsFeatureId> > ignoreFeatures = ( QHash<QgsVectorLayer *, QSet<QgsFeatureId> >() ) );
};

0 comments on commit 26a911c

Please sign in to comment.
You can’t perform that action at this time.