[geos-commits] r2296 - trunk/capi
svn_geos at osgeo.org
svn_geos at osgeo.org
Mon Mar 23 17:07:56 EDT 2009
Author: mloskot
Date: 2009-03-23 17:07:56 -0400 (Mon, 23 Mar 2009)
New Revision: 2296
Modified:
trunk/capi/geos_ts_c.cpp
Log:
capi/geos_ts_c.cpp: refactoring, replace manual strdup with gstrdup, use single return expression per function, added some comments.
Modified: trunk/capi/geos_ts_c.cpp
===================================================================
--- trunk/capi/geos_ts_c.cpp 2009-03-23 20:31:23 UTC (rev 2295)
+++ trunk/capi/geos_ts_c.cpp 2009-03-23 21:07:56 UTC (rev 2296)
@@ -190,6 +190,10 @@
bool result = g1->disjoint(g2);
return result;
}
+
+ // TODO: mloskot is going to replace these double-catch block
+ // with a macro to remove redundant code in this and
+ // following functions.
catch (const std::exception &e)
{
handle->ERROR_MESSAGE("%s", e.what());
@@ -1117,22 +1121,19 @@
{
std::string s = g1->getGeometryType();
- char *result;
- result = (char*) std::malloc( s.length() + 1);
- std::strcpy(result, s.c_str() );
+ char *result = gstrdup(s);
return result;
}
catch (const std::exception &e)
{
handle->ERROR_MESSAGE("%s", e.what());
- return NULL;
}
-
catch (...)
{
handle->ERROR_MESSAGE("Unknown exception thrown");
- return NULL;
}
+
+ return NULL;
}
// Return postgis geometry type index
@@ -1158,19 +1159,15 @@
catch (const std::exception &e)
{
handle->ERROR_MESSAGE("%s", e.what());
- return -1;
}
-
catch (...)
{
handle->ERROR_MESSAGE("Unknown exception thrown");
- return -1;
}
+
+ return -1;
}
-
-
-
//-------------------------------------------------------------------
// GEOS functions that return geometries
//-------------------------------------------------------------------
@@ -1198,14 +1195,13 @@
catch (const std::exception &e)
{
handle->ERROR_MESSAGE("%s", e.what());
- return NULL;
}
-
catch (...)
{
handle->ERROR_MESSAGE("Unknown exception thrown");
- return NULL;
}
+
+ return NULL;
}
Geometry *
@@ -1225,22 +1221,23 @@
try
{
- GeomAutoPtr g3 = BinaryOp(g1, g2, overlayOp(OverlayOp::opINTERSECTION));
+ GeomAutoPtr g3(BinaryOp(g1, g2, overlayOp(OverlayOp::opINTERSECTION)));
return g3.release();
+
+ // XXX: old version
//Geometry *g3 = g1->intersection(g2);
//return g3;
}
catch (const std::exception &e)
{
handle->ERROR_MESSAGE("%s", e.what());
- return NULL;
}
-
catch (...)
{
handle->ERROR_MESSAGE("Unknown exception thrown");
- return NULL;
}
+
+ return NULL;
}
Geometry *
@@ -1266,14 +1263,13 @@
catch (const std::exception &e)
{
handle->ERROR_MESSAGE("%s", e.what());
- return NULL;
}
-
catch (...)
{
handle->ERROR_MESSAGE("Unknown exception thrown");
- return NULL;
}
+
+ return NULL;
}
Geometry *
@@ -1299,14 +1295,13 @@
catch (const std::exception &e)
{
handle->ERROR_MESSAGE("%s", e.what());
- return NULL;
}
-
catch (...)
{
handle->ERROR_MESSAGE("Unknown exception thrown");
- return NULL;
}
+
+ return NULL;
}
Geometry *
@@ -1326,22 +1321,23 @@
try
{
- GeomAutoPtr g3 = BinaryOp(g1, g2, overlayOp(OverlayOp::opDIFFERENCE));
+ GeomAutoPtr g3(BinaryOp(g1, g2, overlayOp(OverlayOp::opDIFFERENCE)));
return g3.release();
+
+ // XXX: old version
//Geometry *g3 = g1->difference(g2);
//return g3;
}
catch (const std::exception &e)
{
handle->ERROR_MESSAGE("%s", e.what());
- return NULL;
}
-
catch (...)
{
handle->ERROR_MESSAGE("Unknown exception thrown");
- return NULL;
}
+
+ return NULL;
}
Geometry *
@@ -1367,14 +1363,13 @@
catch (const std::exception &e)
{
handle->ERROR_MESSAGE("%s", e.what());
- return NULL;
}
-
catch (...)
{
handle->ERROR_MESSAGE("Unknown exception thrown");
- return NULL;
}
+
+ return NULL;
}
Geometry *
@@ -1431,6 +1426,8 @@
{
GeomAutoPtr g3 = BinaryOp(g1, g2, overlayOp(OverlayOp::opUNION));
return g3.release();
+
+ // XXX: old version
//Geometry *g3 = g1->Union(g2);
//return g3;
}
@@ -1444,14 +1441,13 @@
handle->NOTICE_MESSAGE("%s", s.str().c_str());
#endif // VERBOSE_EXCEPTIONS
handle->ERROR_MESSAGE("%s", e.what());
- return NULL;
}
-
catch (...)
{
handle->ERROR_MESSAGE("Unknown exception thrown");
- return NULL;
}
+
+ return NULL;
}
Geometry *
@@ -1477,19 +1473,20 @@
handle->ERROR_MESSAGE("Invalid argument (must be a MultiPolygon)");
return NULL;
}
+
using geos::operation::geounion::CascadedPolygonUnion;
return CascadedPolygonUnion::Union(p);
}
catch (const std::exception &e)
{
handle->ERROR_MESSAGE("%s", e.what());
- return NULL;
}
catch (...)
{
handle->ERROR_MESSAGE("Unknown exception thrown");
- return NULL;
}
+
+ return NULL;
}
Geometry *
@@ -1511,25 +1508,23 @@
{
Geometry *ret = g1->getInteriorPoint();
if ( ! ret )
- {
- const GeometryFactory *gf;
- gf=handle->geomFactory;
- // return an empty collection
- return gf->createGeometryCollection();
- }
+ {
+ const GeometryFactory* gf = handle->geomFactory;
+ // return an empty collection
+ return gf->createGeometryCollection();
+ }
return ret;
}
catch (const std::exception &e)
{
handle->ERROR_MESSAGE("%s", e.what());
- return NULL;
}
-
catch (...)
{
handle->ERROR_MESSAGE("Unknown exception thrown");
- return NULL;
}
+
+ return NULL;
}
//-------------------------------------------------------------------
@@ -1541,6 +1536,10 @@
{
GEOSContextHandleInternal_t *handle = 0;
+ // FIXME: mloskot: Does this try-catch around delete means that
+ // destructors in GEOS may throw? If it does, this is a serious
+ // violation of "never throw an exception from a destructor" principle
+
try
{
delete a;
More information about the geos-commits
mailing list