@@ -38,13 +38,14 @@ email : morb at ozemail dot com dot au
38
38
class GEOSException
39
39
{
40
40
public:
41
- GEOSException ( char *theMsg )
41
+ GEOSException ( const char *theMsg )
42
42
{
43
43
if ( strcmp ( theMsg, " Unknown exception thrown" ) == 0 && lastMsg )
44
44
{
45
45
delete [] theMsg;
46
- msg = new char [strlen ( lastMsg )+1 ];
47
- strcpy ( msg, lastMsg );
46
+ char *aMsg = new char [strlen ( lastMsg )+1 ];
47
+ strcpy ( aMsg, lastMsg );
48
+ msg = aMsg;
48
49
}
49
50
else
50
51
{
@@ -72,13 +73,13 @@ class GEOSException
72
73
}
73
74
74
75
private:
75
- char *msg;
76
+ const char *msg;
76
77
static const char *lastMsg;
77
78
};
78
79
79
80
const char *GEOSException::lastMsg = NULL ;
80
81
81
- void throwGEOSException ( const char *fmt, ... )
82
+ static void throwGEOSException ( const char *fmt, ... )
82
83
{
83
84
va_list ap;
84
85
va_start ( ap, fmt );
@@ -92,7 +93,7 @@ void throwGEOSException( const char *fmt, ... )
92
93
throw GEOSException ( msg );
93
94
}
94
95
95
- void printGEOSNotice ( const char *fmt, ... )
96
+ static void printGEOSNotice ( const char *fmt, ... )
96
97
{
97
98
#if defined(QGISDEBUG)
98
99
va_list ap;
@@ -106,6 +107,23 @@ void printGEOSNotice( const char *fmt, ... )
106
107
#endif
107
108
}
108
109
110
+ class GEOSInit
111
+ {
112
+ public:
113
+ GEOSInit ()
114
+ {
115
+ initGEOS ( printGEOSNotice, throwGEOSException );
116
+ }
117
+
118
+ ~GEOSInit ()
119
+ {
120
+ finishGEOS ();
121
+ }
122
+ };
123
+
124
+ static GEOSInit geosinit;
125
+
126
+
109
127
#if defined(GEOS_VERSION_MAJOR) && (GEOS_VERSION_MAJOR<3)
110
128
#define GEOSGeom_getCoordSeq (g ) GEOSGeom_getCoordSeq( (GEOSGeometry *) g )
111
129
#define GEOSGetExteriorRing (g ) GEOSGetExteriorRing( (GEOSGeometry *)g )
@@ -154,33 +172,21 @@ static GEOSGeometry *cloneGeosGeom( const GEOSGeometry *geom )
154
172
#define GEOSGeom_clone (g ) cloneGeosGeom(g)
155
173
#endif
156
174
157
- int QgsGeometry::refcount = 0 ;
158
-
159
175
QgsGeometry::QgsGeometry ()
160
176
: mGeometry( 0 ),
161
177
mGeometrySize( 0 ),
162
178
mGeos( 0 ),
163
179
mDirtyWkb( FALSE ),
164
180
mDirtyGeos( FALSE )
165
181
{
166
- if ( refcount++ == 0 )
167
- {
168
- initGEOS ( printGEOSNotice, throwGEOSException );
169
- }
170
182
}
171
183
172
-
173
184
QgsGeometry::QgsGeometry ( QgsGeometry const & rhs )
174
185
: mGeometry( 0 ),
175
186
mGeometrySize( rhs.mGeometrySize ),
176
187
mDirtyWkb( rhs.mDirtyWkb ),
177
188
mDirtyGeos( rhs.mDirtyGeos )
178
189
{
179
- if ( refcount++ == 0 )
180
- {
181
- initGEOS ( printGEOSNotice, throwGEOSException );
182
- }
183
-
184
190
if ( mGeometrySize && rhs.mGeometry )
185
191
{
186
192
mGeometry = new unsigned char [mGeometrySize ];
@@ -210,9 +216,6 @@ QgsGeometry::~QgsGeometry()
210
216
{
211
217
GEOSGeom_destroy ( mGeos );
212
218
}
213
-
214
- if ( --refcount == 0 )
215
- finishGEOS ();
216
219
}
217
220
218
221
static unsigned int getNumGeosPoints ( const GEOSGeometry *geom )
0 commit comments