Hi, Strk, [EMAIL PROTECTED] wrote:
>> - Our "typedef struct GEOSGeom_t *GEOSGeom;" used in function arguments >> as "const GEOSGeom" actually defines an unmodifiable Pointer to a >> modifiable Geometry. This is the reason for those "type qualifiers >> ignored on return type" warnings. >> Possible solutions: >> - Include the "const" into the typedef, as the C-API does not expose >> any in-place modificators. >> - Remove the "*" from the typedef, and declare the Pointers explicitly >> in the function definitions >> We will have to dig into whether this might break any clients. > > I'd like to hear opinion of others on this. > Making the pointer part visible is probably the cleanest thing to do, > but clients will suffer from this. Maybe should *add* new typedefs > so that old clients will still work w/out modification but new code > can use the new typedefs ? The attached Patch is a first try of follwing this path. But it causes clients (geostest, to be exactly) to throw scary warnings, and I assume that fixing those warnings in the clients will break source compatibility with GEOS 2.X. HTH, Markus -- Markus Schaber | Logical Tracking&Tracing International AG Dipl. Inf. | Software Development GIS Fight against software patents in Europe! www.ffii.org www.nosoftwarepatents.org
Index: capi/geos_c.cpp =================================================================== --- capi/geos_c.cpp (revision 1887) +++ capi/geos_c.cpp (working copy) @@ -51,8 +51,8 @@ #include <memory> // Some extra magic to make type declarations in geos_c.h work - for cross-checking of types in header. -#define GEOSGeom geos::geom::Geometry* -#define GEOSCoordSeq geos::geom::CoordinateSequence* +#define GEOSGeometry geos::geom::Geometry +#define GEOSCoordSequence geos::geom::CoordinateSequence #include "geos_c.h" /// Define this if you want operations triggering Exceptions to Index: capi/geos_c.h.in =================================================================== --- capi/geos_c.h.in (revision 1887) +++ capi/geos_c.h.in (working copy) @@ -72,11 +72,17 @@ * C-API users, we need to define them as "opaque" struct pointers, as * those clients don't have access to the original C++ headers, by design. */ -#ifndef GEOSGeom -typedef struct GEOSGeom_t *GEOSGeom; -typedef struct GEOSCoordSeq_t *GEOSCoordSeq; +#ifndef GEOSGeometry +typedef struct GEOSGeom_t GEOSGeometry; +typedef struct GEOSCoordSeq_t GEOSCoordSequence; #endif +/* Those are compatibility definitions for source compatibility + * with GEOS 2.X clients relying on that type. + */ +typedef GEOSGeometry* GEOSGeom; +typedef GEOSCoordSequence* GEOSCoordSeq; + /* Supported geometry types * This was renamed from GEOSGeomTypeId in GEOS 2.2.X, which might * break compatibility, this issue is still under investigation. @@ -124,8 +130,8 @@ * ***********************************************************************/ -extern GEOSGeom GEOS_DLL GEOSGeomFromWKT(const char *wkt); -extern char GEOS_DLL *GEOSGeomToWKT(const GEOSGeom g); +extern GEOSGeometry* GEOS_DLL GEOSGeomFromWKT(const char *wkt); +extern char GEOS_DLL *GEOSGeomToWKT(const GEOSGeometry* g); /* * Specify whether output WKB should be 2d or 3d. @@ -141,11 +147,11 @@ extern int GEOS_DLL GEOS_getWKBByteOrder(); extern int GEOS_DLL GEOS_setWKBByteOrder(int byteOrder); -extern GEOSGeom GEOS_DLL GEOSGeomFromWKB_buf(const unsigned char *wkb, size_t size); -extern unsigned char GEOS_DLL *GEOSGeomToWKB_buf(const GEOSGeom g, size_t *size); +extern GEOSGeometry* GEOS_DLL GEOSGeomFromWKB_buf(const unsigned char *wkb, size_t size); +extern unsigned char GEOS_DLL *GEOSGeomToWKB_buf(const GEOSGeometry* g, size_t *size); -extern GEOSGeom GEOS_DLL GEOSGeomFromHEX_buf(const unsigned char *hex, size_t size); -extern unsigned char GEOS_DLL *GEOSGeomToHEX_buf(const GEOSGeom g, size_t *size); +extern GEOSGeometry* GEOS_DLL GEOSGeomFromHEX_buf(const unsigned char *hex, size_t size); +extern unsigned char GEOS_DLL *GEOSGeomToHEX_buf(const GEOSGeometry* g, size_t *size); /************************************************************************ * @@ -158,78 +164,78 @@ * of ``dims'' dimensions. * Return NULL on exception. */ -extern GEOSCoordSeq GEOS_DLL GEOSCoordSeq_create(unsigned int size, unsigned int dims); +extern GEOSCoordSequence* GEOS_DLL GEOSCoordSeq_create(unsigned int size, unsigned int dims); /* * Clone a Coordinate Sequence. * Return NULL on exception. */ -extern GEOSCoordSeq GEOS_DLL GEOSCoordSeq_clone(const GEOSCoordSeq s); +extern GEOSCoordSequence* GEOS_DLL GEOSCoordSeq_clone(const GEOSCoordSequence* s); /* * Destroy a Coordinate Sequence. */ -extern void GEOS_DLL GEOSCoordSeq_destroy(GEOSCoordSeq s); +extern void GEOS_DLL GEOSCoordSeq_destroy(GEOSCoordSequence* s); /* * Set ordinate values in a Coordinate Sequence. * Return 0 on exception. */ -extern int GEOS_DLL GEOSCoordSeq_setX(GEOSCoordSeq s, +extern int GEOS_DLL GEOSCoordSeq_setX(GEOSCoordSequence* s, unsigned int idx, double val); -extern int GEOS_DLL GEOSCoordSeq_setY(GEOSCoordSeq s, +extern int GEOS_DLL GEOSCoordSeq_setY(GEOSCoordSequence* s, unsigned int idx, double val); -extern int GEOS_DLL GEOSCoordSeq_setZ(GEOSCoordSeq s, +extern int GEOS_DLL GEOSCoordSeq_setZ(GEOSCoordSequence* s, unsigned int idx, double val); -extern int GEOS_DLL GEOSCoordSeq_setOrdinate(GEOSCoordSeq s, +extern int GEOS_DLL GEOSCoordSeq_setOrdinate(GEOSCoordSequence* s, unsigned int idx, unsigned int dim, double val); /* * Get ordinate values from a Coordinate Sequence. * Return 0 on exception. */ -extern int GEOS_DLL GEOSCoordSeq_getX(const GEOSCoordSeq s, +extern int GEOS_DLL GEOSCoordSeq_getX(const GEOSCoordSequence* s, unsigned int idx, double *val); -extern int GEOS_DLL GEOSCoordSeq_getY(const GEOSCoordSeq s, +extern int GEOS_DLL GEOSCoordSeq_getY(const GEOSCoordSequence* s, unsigned int idx, double *val); -extern int GEOS_DLL GEOSCoordSeq_getZ(const GEOSCoordSeq s, +extern int GEOS_DLL GEOSCoordSeq_getZ(const GEOSCoordSequence* s, unsigned int idx, double *val); -extern int GEOS_DLL GEOSCoordSeq_getOrdinate(const GEOSCoordSeq s, +extern int GEOS_DLL GEOSCoordSeq_getOrdinate(const GEOSCoordSequence* s, unsigned int idx, unsigned int dim, double *val); /* * Get size and dimensions info from a Coordinate Sequence. * Return 0 on exception. */ -extern int GEOS_DLL GEOSCoordSeq_getSize(const GEOSCoordSeq s, +extern int GEOS_DLL GEOSCoordSeq_getSize(const GEOSCoordSequence* s, unsigned int *size); -extern int GEOS_DLL GEOSCoordSeq_getDimensions(const GEOSCoordSeq s, +extern int GEOS_DLL GEOSCoordSeq_getDimensions(const GEOSCoordSequence* s, unsigned int *dims); /************************************************************************ * * Geometry Constructors. - * GEOSCoordSeq arguments will become ownership of the returned object. + * GEOSCoordSequence* arguments will become ownership of the returned object. * All functions return NULL on exception. * ***********************************************************************/ -extern GEOSGeom GEOS_DLL GEOSGeom_createPoint(GEOSCoordSeq s); -extern GEOSGeom GEOS_DLL GEOSGeom_createLinearRing(GEOSCoordSeq s); -extern GEOSGeom GEOS_DLL GEOSGeom_createLineString(GEOSCoordSeq s); +extern GEOSGeometry* GEOS_DLL GEOSGeom_createPoint(GEOSCoordSequence* s); +extern GEOSGeometry* GEOS_DLL GEOSGeom_createLinearRing(GEOSCoordSequence* s); +extern GEOSGeometry* GEOS_DLL GEOSGeom_createLineString(GEOSCoordSequence* s); /* - * Second argument is an array of GEOSGeom objects. + * Second argument is an array of GEOSGeometry* objects. * The caller remains owner of the array, but pointed-to - * objects become ownership of the returned GEOSGeom. + * objects become ownership of the returned GEOSGeometry. */ -extern GEOSGeom GEOS_DLL GEOSGeom_createPolygon(GEOSGeom shell, - GEOSGeom *holes, unsigned int nholes); -extern GEOSGeom GEOS_DLL GEOSGeom_createCollection(int type, - GEOSGeom *geoms, unsigned int ngeoms); +extern GEOSGeometry* GEOS_DLL GEOSGeom_createPolygon(GEOSGeometry* shell, + GEOSGeometry* *holes, unsigned int nholes); +extern GEOSGeometry* GEOS_DLL GEOSGeom_createCollection(int type, + GEOSGeometry* *geoms, unsigned int ngeoms); -extern GEOSGeom GEOS_DLL GEOSGeom_clone(const GEOSGeom g); +extern GEOSGeometry* GEOS_DLL GEOSGeom_clone(const GEOSGeometry* g); /************************************************************************ * @@ -237,7 +243,7 @@ * ***********************************************************************/ -extern void GEOS_DLL GEOSGeom_destroy(GEOSGeom g); +extern void GEOS_DLL GEOSGeom_destroy(GEOSGeometry* g); /************************************************************************ @@ -246,24 +252,24 @@ * ***********************************************************************/ -extern GEOSGeom GEOS_DLL GEOSEnvelope(const GEOSGeom g1); -extern GEOSGeom GEOS_DLL GEOSIntersection(const GEOSGeom g1, const GEOSGeom g2); -extern GEOSGeom GEOS_DLL GEOSBuffer(const GEOSGeom g1, +extern GEOSGeometry* GEOS_DLL GEOSEnvelope(const GEOSGeometry* g1); +extern GEOSGeometry* GEOS_DLL GEOSIntersection(const GEOSGeometry* g1, const GEOSGeometry* g2); +extern GEOSGeometry* GEOS_DLL GEOSBuffer(const GEOSGeometry* g1, double width, int quadsegs); -extern GEOSGeom GEOS_DLL GEOSConvexHull(const GEOSGeom g1); -extern GEOSGeom GEOS_DLL GEOSDifference(const GEOSGeom g1, const GEOSGeom g2); -extern GEOSGeom GEOS_DLL GEOSSymDifference(const GEOSGeom g1, - const GEOSGeom g2); -extern GEOSGeom GEOS_DLL GEOSBoundary(const GEOSGeom g1); -extern GEOSGeom GEOS_DLL GEOSUnion(const GEOSGeom g1, const GEOSGeom g2); -extern GEOSGeom GEOS_DLL GEOSPointOnSurface(const GEOSGeom g1); -extern GEOSGeom GEOS_DLL GEOSGetCentroid(const GEOSGeom g); -extern char GEOS_DLL *GEOSRelate(const GEOSGeom g1, const GEOSGeom g2); -extern GEOSGeom GEOS_DLL GEOSPolygonize(const GEOSGeom geoms[], +extern GEOSGeometry* GEOS_DLL GEOSConvexHull(const GEOSGeometry* g1); +extern GEOSGeometry* GEOS_DLL GEOSDifference(const GEOSGeometry* g1, const GEOSGeometry* g2); +extern GEOSGeometry* GEOS_DLL GEOSSymDifference(const GEOSGeometry* g1, + const GEOSGeometry* g2); +extern GEOSGeometry* GEOS_DLL GEOSBoundary(const GEOSGeometry* g1); +extern GEOSGeometry* GEOS_DLL GEOSUnion(const GEOSGeometry* g1, const GEOSGeometry* g2); +extern GEOSGeometry* GEOS_DLL GEOSPointOnSurface(const GEOSGeometry* g1); +extern GEOSGeometry* GEOS_DLL GEOSGetCentroid(const GEOSGeometry* g); +extern char GEOS_DLL *GEOSRelate(const GEOSGeometry* g1, const GEOSGeometry* g2); +extern GEOSGeometry* GEOS_DLL GEOSPolygonize(const GEOSGeometry* geoms[], unsigned int ngeoms); -extern GEOSGeom GEOS_DLL GEOSLineMerge(const GEOSGeom g); -extern GEOSGeom GEOS_DLL GEOSSimplify(const GEOSGeom g1, double tolerance); -extern GEOSGeom GEOS_DLL GEOSTopologyPreserveSimplify(const GEOSGeom g1, +extern GEOSGeometry* GEOS_DLL GEOSLineMerge(const GEOSGeometry* g); +extern GEOSGeometry* GEOS_DLL GEOSSimplify(const GEOSGeometry* g1, double tolerance); +extern GEOSGeometry* GEOS_DLL GEOSTopologyPreserveSimplify(const GEOSGeometry* g1, double tolerance); /************************************************************************ @@ -272,17 +278,17 @@ * ***********************************************************************/ -extern char GEOS_DLL GEOSRelatePattern(const GEOSGeom g1, const GEOSGeom g2, +extern char GEOS_DLL GEOSRelatePattern(const GEOSGeometry* g1, const GEOSGeometry* g2, const char *pat); -extern char GEOS_DLL GEOSDisjoint(const GEOSGeom g1, const GEOSGeom g2); -extern char GEOS_DLL GEOSTouches(const GEOSGeom g1, const GEOSGeom g2); -extern char GEOS_DLL GEOSIntersects(const GEOSGeom g1, const GEOSGeom g2); -extern char GEOS_DLL GEOSCrosses(const GEOSGeom g1, const GEOSGeom g2); -extern char GEOS_DLL GEOSWithin(const GEOSGeom g1, const GEOSGeom g2); -extern char GEOS_DLL GEOSContains(const GEOSGeom g1, const GEOSGeom g2); -extern char GEOS_DLL GEOSOverlaps(const GEOSGeom g1, const GEOSGeom g2); -extern char GEOS_DLL GEOSEquals(const GEOSGeom g1, const GEOSGeom g2); -extern char GEOS_DLL GEOSEqualsExact(const GEOSGeom g1, const GEOSGeom g2, double tolerance); +extern char GEOS_DLL GEOSDisjoint(const GEOSGeometry* g1, const GEOSGeometry* g2); +extern char GEOS_DLL GEOSTouches(const GEOSGeometry* g1, const GEOSGeometry* g2); +extern char GEOS_DLL GEOSIntersects(const GEOSGeometry* g1, const GEOSGeometry* g2); +extern char GEOS_DLL GEOSCrosses(const GEOSGeometry* g1, const GEOSGeometry* g2); +extern char GEOS_DLL GEOSWithin(const GEOSGeometry* g1, const GEOSGeometry* g2); +extern char GEOS_DLL GEOSContains(const GEOSGeometry* g1, const GEOSGeometry* g2); +extern char GEOS_DLL GEOSOverlaps(const GEOSGeometry* g1, const GEOSGeometry* g2); +extern char GEOS_DLL GEOSEquals(const GEOSGeometry* g1, const GEOSGeometry* g2); +extern char GEOS_DLL GEOSEqualsExact(const GEOSGeometry* g1, const GEOSGeometry* g2, double tolerance); /************************************************************************ @@ -291,11 +297,11 @@ * ***********************************************************************/ -extern char GEOS_DLL GEOSisEmpty(const GEOSGeom g1); -extern char GEOS_DLL GEOSisValid(const GEOSGeom g1); -extern char GEOS_DLL GEOSisSimple(const GEOSGeom g1); -extern char GEOS_DLL GEOSisRing(const GEOSGeom g1); -extern char GEOS_DLL GEOSHasZ(const GEOSGeom g1); +extern char GEOS_DLL GEOSisEmpty(const GEOSGeometry* g1); +extern char GEOS_DLL GEOSisValid(const GEOSGeometry* g1); +extern char GEOS_DLL GEOSisSimple(const GEOSGeometry* g1); +extern char GEOS_DLL GEOSisRing(const GEOSGeometry* g1); +extern char GEOS_DLL GEOSHasZ(const GEOSGeometry* g1); /************************************************************************ @@ -305,15 +311,15 @@ ***********************************************************************/ /* Return NULL on exception, result must be freed by caller. */ -extern char GEOS_DLL *GEOSGeomType(const GEOSGeom g1); +extern char GEOS_DLL *GEOSGeomType(const GEOSGeometry* g1); /* Return -1 on exception */ -extern int GEOS_DLL GEOSGeomTypeId(const GEOSGeom g1); +extern int GEOS_DLL GEOSGeomTypeId(const GEOSGeometry* g1); /* Return 0 on exception */ -extern int GEOS_DLL GEOSGetSRID(const GEOSGeom g1); +extern int GEOS_DLL GEOSGetSRID(const GEOSGeometry* g1); -extern void GEOS_DLL GEOSSetSRID(GEOSGeom g, int SRID); +extern void GEOS_DLL GEOSSetSRID(GEOSGeometry* g, int SRID); /* May be called on all geometries in GEOS 3.x, returns -1 on error and 1 * for non-multi geometries. Older GEOS versions only accept @@ -321,48 +327,48 @@ * when feeded simple geometries, so beware if you need compatibility with * old GEOS versions. */ -extern int GEOS_DLL GEOSGetNumGeometries(const GEOSGeom g1); +extern int GEOS_DLL GEOSGetNumGeometries(const GEOSGeometry* g1); /* * Return NULL on exception, Geometry must be a Collection. * Returned object is a pointer to internal storage: * it must NOT be destroyed directly. */ -extern const GEOSGeom GEOS_DLL GEOSGetGeometryN(const GEOSGeom g, int n); +extern const GEOSGeometry* GEOS_DLL GEOSGetGeometryN(const GEOSGeometry* g, int n); /* Return -1 on exception */ -extern int GEOS_DLL GEOSNormalize(GEOSGeom g1); +extern int GEOS_DLL GEOSNormalize(GEOSGeometry* g1); /* Return -1 on exception */ -extern int GEOS_DLL GEOSGetNumInteriorRings(const GEOSGeom g1); +extern int GEOS_DLL GEOSGetNumInteriorRings(const GEOSGeometry* g1); /* * Return NULL on exception, Geometry must be a Polygon. * Returned object is a pointer to internal storage: * it must NOT be destroyed directly. */ -extern const GEOSGeom GEOS_DLL GEOSGetInteriorRingN(const GEOSGeom g, int n); +extern const GEOSGeometry* GEOS_DLL GEOSGetInteriorRingN(const GEOSGeometry* g, int n); /* * Return NULL on exception, Geometry must be a Polygon. * Returned object is a pointer to internal storage: * it must NOT be destroyed directly. */ -extern const GEOSGeom GEOS_DLL GEOSGetExteriorRing(const GEOSGeom g); +extern const GEOSGeometry* GEOS_DLL GEOSGetExteriorRing(const GEOSGeometry* g); /* Return -1 on exception */ -extern int GEOS_DLL GEOSGetNumCoordinates(const GEOSGeom g1); +extern int GEOS_DLL GEOSGetNumCoordinates(const GEOSGeometry* g1); /* * Return NULL on exception. * Geometry must be a LineString, LinearRing or Point. */ -extern const GEOSCoordSeq GEOS_DLL GEOSGeom_getCoordSeq(const GEOSGeom g); +extern const GEOSCoordSequence* GEOS_DLL GEOSGeom_getCoordSeq(const GEOSGeometry* g); /* * Return 0 on exception (or empty geometry) */ -extern int GEOS_DLL GEOSGeom_getDimensions(const GEOSGeom g); +extern int GEOS_DLL GEOSGeom_getDimensions(const GEOSGeometry* g); /************************************************************************ * @@ -371,9 +377,9 @@ ***********************************************************************/ /* Return 0 on exception, 1 otherwise */ -extern int GEOS_DLL GEOSArea(const GEOSGeom g1, double *area); -extern int GEOS_DLL GEOSLength(const GEOSGeom g1, double *length); -extern int GEOS_DLL GEOSDistance(const GEOSGeom g1, const GEOSGeom g2, +extern int GEOS_DLL GEOSArea(const GEOSGeometry* g1, double *area); +extern int GEOS_DLL GEOSLength(const GEOSGeometry* g1, double *length); +extern int GEOS_DLL GEOSDistance(const GEOSGeometry* g1, const GEOSGeometry* g2, double *dist); #ifdef __cplusplus
_______________________________________________ geos-devel mailing list geos-devel@geos.refractions.net http://geos.refractions.net/mailman/listinfo/geos-devel