[geos-commits] r2338 - trunk/source/operation/buffer

svn_geos at osgeo.org svn_geos at osgeo.org
Thu Apr 9 04:54:00 EDT 2009


Author: strk
Date: 2009-04-09 04:54:00 -0400 (Thu, 09 Apr 2009)
New Revision: 2338

Modified:
   trunk/source/operation/buffer/OffsetCurveBuilder.cpp
   trunk/source/operation/buffer/OffsetCurveVertexList.h
Log:
Sync port of OffsetCurveVertexList to JTS-1.9, improve memory management documentation (would need some refactoring/love)


Modified: trunk/source/operation/buffer/OffsetCurveBuilder.cpp
===================================================================
--- trunk/source/operation/buffer/OffsetCurveBuilder.cpp	2009-04-08 16:52:28 UTC (rev 2337)
+++ trunk/source/operation/buffer/OffsetCurveBuilder.cpp	2009-04-09 08:54:00 UTC (rev 2338)
@@ -106,6 +106,7 @@
 	} else {
 		computeLineBufferCurve(*inputPts);
 	}
+	// NOTE: we take ownership of lineCoord here
 	CoordinateSequence *lineCoord=vertexList->getCoordinates();
 	lineList.push_back(lineCoord);
 }
@@ -130,7 +131,10 @@
 		return;
 	}
 	computeRingBufferCurve(*inputPts, side);
-	lineList.push_back(vertexList->getCoordinates()); // this will be vertexList
+
+	// this will be vertexList
+	// NOTE: getCoordinates() take ownership of the CoordinateSequence
+	lineList.push_back(vertexList->getCoordinates());
 }
 
 /*private*/

Modified: trunk/source/operation/buffer/OffsetCurveVertexList.h
===================================================================
--- trunk/source/operation/buffer/OffsetCurveVertexList.h	2009-04-08 16:52:28 UTC (rev 2337)
+++ trunk/source/operation/buffer/OffsetCurveVertexList.h	2009-04-09 08:54:00 UTC (rev 2338)
@@ -13,7 +13,7 @@
  *
  **********************************************************************
  *
- * Last port: operation/buffer/OffsetCurveVertexList.java rev. 1.1
+ * Last port: operation/buffer/OffsetCurveVertexList.java rev. 1.2 (JTS-1.9)
  *
  **********************************************************************/
 
@@ -54,7 +54,6 @@
 private:
 
 	geom::CoordinateSequence* ptList;
-	bool ptListConsumed;
 
 	const geom::PrecisionModel* precisionModel;
   
@@ -87,10 +86,11 @@
 
 public:
 	
+	friend std::ostream& operator<< (std::ostream& os, const OffsetCurveVertexList& node);
+
 	OffsetCurveVertexList()
 		:
 		ptList(new geom::CoordinateArraySequence()),
-		ptListConsumed(false),
 		precisionModel(NULL),
 		minimumVertexDistance (0.0)
 	{
@@ -98,7 +98,6 @@
 
 	~OffsetCurveVertexList()
 	{
-		if (!ptListConsumed)
 			delete ptList;
 	}
 	
@@ -127,10 +126,11 @@
 		// (JTS uses a vector for ptList, not a CoordinateSequence,
 		// we should do the same)
 		ptList->add(bufPt, true);
-		//ptList.push_back(bufPt);
 	}
 	
-	// check that points are a ring - add the startpoint again if they are not
+	/// Check that points are a ring
+	//
+	/// add the startpoint again if they are not
 	void closeRing()
 	{
 		if (ptList->size() < 1) return;
@@ -141,23 +141,37 @@
 		ptList->add(startPt, true);
 	}
 
+	/// Get coordinates by taking ownership of them
+	//
+	/// After this call, the coordinates reference in
+	/// this object are dropped. Calling twice will
+	/// segfault...
+	///
+	/// FIXME: refactor memory management of this
+	///
 	geom::CoordinateSequence* getCoordinates()
 	{
 		closeRing();
-		ptListConsumed = true;
-		return ptList;
+		geom::CoordinateSequence* ret = ptList;
+		ptList = 0;
+		return ret;
 	}
 
-	// Added getCoordinatesRO(), which returns the coordinates without
-	// passing ownership to the caller.
-	const geom::CoordinateSequence* getCoordinatesRO()
+};
+
+std::ostream& operator<< (std::ostream& os, const OffsetCurveVertexList& lst)
+{
+	if ( lst.ptList )
 	{
-		closeRing();
-		return ptList;
+		os << *(lst.ptList);
 	}
+	else
+	{
+		os << "empty (consumed?)";
+	}
+	return os;
+}
 
-};
-
 } // namespace geos.operation.buffer
 } // namespace geos.operation
 } // namespace geos



More information about the geos-commits mailing list