Skip to content

Commit

Permalink
fix GEOS initialization
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@9329 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Sep 14, 2008
1 parent 83c2b4e commit 11a6db5
Showing 1 changed file with 24 additions and 21 deletions.
45 changes: 24 additions & 21 deletions src/core/qgsgeometry.cpp
Expand Up @@ -38,13 +38,14 @@ email : morb at ozemail dot com dot au
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
{
Expand Down Expand Up @@ -72,13 +73,13 @@ class GEOSException
}

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 );
Expand All @@ -92,7 +93,7 @@ void throwGEOSException( const char *fmt, ... )
throw GEOSException( msg );
}

void printGEOSNotice( const char *fmt, ... )
static void printGEOSNotice( const char *fmt, ... )
{
#if defined(QGISDEBUG)
va_list ap;
Expand All @@ -106,6 +107,23 @@ void printGEOSNotice( const char *fmt, ... )
#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 )
Expand Down Expand Up @@ -154,33 +172,21 @@ static GEOSGeometry *cloneGeosGeom( const GEOSGeometry *geom )
#define GEOSGeom_clone(g) cloneGeosGeom(g)
#endif

int QgsGeometry::refcount = 0;

QgsGeometry::QgsGeometry()
: mGeometry( 0 ),
mGeometrySize( 0 ),
mGeos( 0 ),
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];
Expand Down Expand Up @@ -210,9 +216,6 @@ QgsGeometry::~QgsGeometry()
{
GEOSGeom_destroy( mGeos );
}

if ( --refcount == 0 )
finishGEOS();
}

static unsigned int getNumGeosPoints( const GEOSGeometry *geom )
Expand Down

0 comments on commit 11a6db5

Please sign in to comment.