Skip to content

Commit 6158236

Browse files
committedMar 16, 2018
Modernize connection pool code
1 parent f3b5838 commit 6158236

File tree

2 files changed

+23
-14
lines changed

2 files changed

+23
-14
lines changed
 

‎src/core/qgsconnectionpool.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#define SIP_NO_FILE
2020

21+
#include "qgis.h"
2122
#include <QCoreApplication>
2223
#include <QMap>
2324
#include <QMutex>
@@ -34,7 +35,7 @@
3435

3536
/**
3637
* \ingroup core
37-
* Template that stores data related to one server.
38+
* Template that stores data related to a connection to a single server or datasource.
3839
*
3940
* It is assumed that following functions exist:
4041
* - void qgsConnectionPool_ConnectionCreate(QString name, T& c) ... create a new connection
@@ -74,7 +75,7 @@ class QgsConnectionPoolGroup
7475

7576
~QgsConnectionPoolGroup()
7677
{
77-
Q_FOREACH ( Item item, conns )
78+
for ( const Item &item : qgis::as_const( conns ) )
7879
{
7980
qgsConnectionPool_ConnectionDestroy( item.c );
8081
}
@@ -180,12 +181,12 @@ class QgsConnectionPoolGroup
180181
void invalidateConnections()
181182
{
182183
connMutex.lock();
183-
Q_FOREACH ( Item i, conns )
184+
for ( const Item &i : qgis::as_const( conns ) )
184185
{
185186
qgsConnectionPool_ConnectionDestroy( i.c );
186187
}
187188
conns.clear();
188-
Q_FOREACH ( T c, acquiredConns )
189+
for ( T c : qgis::as_const( acquiredConns ) )
189190
qgsConnectionPool_InvalidateConnection( c );
190191
connMutex.unlock();
191192
}
@@ -269,7 +270,7 @@ class QgsConnectionPool
269270
virtual ~QgsConnectionPool()
270271
{
271272
mMutex.lock();
272-
Q_FOREACH ( T_Group *group, mGroups )
273+
for ( T_Group *group : qgis::as_const( mGroups ) )
273274
{
274275
delete group;
275276
}

‎src/providers/ogr/qgsogrconnpool.h

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,16 @@ class QgsOgrConnPoolGroup : public QObject, public QgsConnectionPoolGroup<QgsOgr
6565
public:
6666
explicit QgsOgrConnPoolGroup( const QString &name )
6767
: QgsConnectionPoolGroup<QgsOgrConn*>( name )
68-
, mRefCount( 0 )
69-
{ initTimer( this ); }
68+
{
69+
initTimer( this );
70+
}
71+
72+
//! QgsOgrConnPoolGroup cannot be copied
73+
QgsOgrConnPoolGroup( const QgsOgrConnPoolGroup &other ) = delete;
74+
75+
//! QgsOgrConnPoolGroup cannot be copied
76+
QgsOgrConnPoolGroup &operator=( const QgsOgrConnPoolGroup &other ) = delete;
77+
7078
void ref() { ++mRefCount; }
7179
bool unref()
7280
{
@@ -79,11 +87,8 @@ class QgsOgrConnPoolGroup : public QObject, public QgsConnectionPoolGroup<QgsOgr
7987
void startExpirationTimer() { expirationTimer->start(); }
8088
void stopExpirationTimer() { expirationTimer->stop(); }
8189

82-
protected:
83-
Q_DISABLE_COPY( QgsOgrConnPoolGroup )
84-
8590
private:
86-
int mRefCount;
91+
int mRefCount = 0;
8792

8893
};
8994

@@ -110,6 +115,12 @@ class QgsOgrConnPool : public QgsConnectionPool<QgsOgrConn *, QgsOgrConnPoolGrou
110115
//
111116
static void cleanupInstance();
112117

118+
//! QgsOgrConnPool cannot be copied
119+
QgsOgrConnPool( const QgsOgrConnPool &other ) = delete;
120+
121+
//! QgsOgrConnPool cannot be copied
122+
QgsOgrConnPool &operator=( const QgsOgrConnPool &other ) = delete;
123+
113124
/**
114125
* \brief Increases the reference count on the connection pool for the specified connection.
115126
* \param connInfo The connection string.
@@ -151,9 +162,6 @@ class QgsOgrConnPool : public QgsConnectionPool<QgsOgrConn *, QgsOgrConnPoolGrou
151162
mMutex.unlock();
152163
}
153164

154-
protected:
155-
Q_DISABLE_COPY( QgsOgrConnPool )
156-
157165
private:
158166
QgsOgrConnPool();
159167
~QgsOgrConnPool() override;

0 commit comments

Comments
 (0)
Please sign in to comment.