[QGIS Commit] r9329 - trunk/qgis/src/core
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Sun Sep 14 18:55:36 EDT 2008
Author: jef
Date: 2008-09-14 18:55:36 -0400 (Sun, 14 Sep 2008)
New Revision: 9329
Modified:
trunk/qgis/src/core/qgsgeometry.cpp
Log:
fix GEOS initialization
Modified: trunk/qgis/src/core/qgsgeometry.cpp
===================================================================
--- trunk/qgis/src/core/qgsgeometry.cpp 2008-09-14 11:22:09 UTC (rev 9328)
+++ trunk/qgis/src/core/qgsgeometry.cpp 2008-09-14 22:55:36 UTC (rev 9329)
@@ -38,13 +38,14 @@
class GEOSException
{
public:
- GEOSException( char *theMsg )
+ GEOSException( const char *theMsg )
{
if ( strcmp( theMsg, "Unknown exception thrown" ) == 0 && lastMsg )
{
delete [] theMsg;
- msg = new char[strlen( lastMsg )+1];
- strcpy( msg, lastMsg );
+ char *aMsg = new char[strlen( lastMsg )+1];
+ strcpy( aMsg, lastMsg );
+ msg = aMsg;
}
else
{
@@ -72,13 +73,13 @@
}
private:
- char *msg;
+ const char *msg;
static const char *lastMsg;
};
const char *GEOSException::lastMsg = NULL;
-void throwGEOSException( const char *fmt, ... )
+static void throwGEOSException( const char *fmt, ... )
{
va_list ap;
va_start( ap, fmt );
@@ -92,7 +93,7 @@
throw GEOSException( msg );
}
-void printGEOSNotice( const char *fmt, ... )
+static void printGEOSNotice( const char *fmt, ... )
{
#if defined(QGISDEBUG)
va_list ap;
@@ -106,6 +107,23 @@
#endif
}
+class GEOSInit
+{
+ public:
+ GEOSInit()
+ {
+ initGEOS( printGEOSNotice, throwGEOSException );
+ }
+
+ ~GEOSInit()
+ {
+ finishGEOS();
+ }
+};
+
+static GEOSInit geosinit;
+
+
#if defined(GEOS_VERSION_MAJOR) && (GEOS_VERSION_MAJOR<3)
#define GEOSGeom_getCoordSeq(g) GEOSGeom_getCoordSeq( (GEOSGeometry *) g )
#define GEOSGetExteriorRing(g) GEOSGetExteriorRing( (GEOSGeometry *)g )
@@ -154,8 +172,6 @@
#define GEOSGeom_clone(g) cloneGeosGeom(g)
#endif
-int QgsGeometry::refcount = 0;
-
QgsGeometry::QgsGeometry()
: mGeometry( 0 ),
mGeometrySize( 0 ),
@@ -163,24 +179,14 @@
mDirtyWkb( FALSE ),
mDirtyGeos( FALSE )
{
- if ( refcount++ == 0 )
- {
- initGEOS( printGEOSNotice, throwGEOSException );
- }
}
-
QgsGeometry::QgsGeometry( QgsGeometry const & rhs )
: mGeometry( 0 ),
mGeometrySize( rhs.mGeometrySize ),
mDirtyWkb( rhs.mDirtyWkb ),
mDirtyGeos( rhs.mDirtyGeos )
{
- if ( refcount++ == 0 )
- {
- initGEOS( printGEOSNotice, throwGEOSException );
- }
-
if ( mGeometrySize && rhs.mGeometry )
{
mGeometry = new unsigned char[mGeometrySize];
@@ -210,9 +216,6 @@
{
GEOSGeom_destroy( mGeos );
}
-
- if ( --refcount == 0 )
- finishGEOS();
}
static unsigned int getNumGeosPoints( const GEOSGeometry *geom )
More information about the QGIS-commit
mailing list