[geos-commits] r3453 - in trunk: include/geos/noding src/noding src/operation/buffer

svn_geos at osgeo.org svn_geos at osgeo.org
Wed Jul 27 04:12:56 EDT 2011


Author: strk
Date: 2011-07-27 01:12:56 -0700 (Wed, 27 Jul 2011)
New Revision: 3453

Modified:
   trunk/include/geos/noding/Noder.h
   trunk/include/geos/noding/SegmentNodeList.h
   trunk/src/noding/SegmentNodeList.cpp
   trunk/src/operation/buffer/BufferBuilder.cpp
Log:
Change Noder interface to transfer ownership of noded segment strings to caller. Delete them as soon as converted to Edges in BufferOp.

Modified: trunk/include/geos/noding/Noder.h
===================================================================
--- trunk/include/geos/noding/Noder.h	2011-07-26 16:36:42 UTC (rev 3452)
+++ trunk/include/geos/noding/Noder.h	2011-07-27 08:12:56 UTC (rev 3453)
@@ -1,5 +1,4 @@
 /**********************************************************************
- * $Id$
  *
  * GEOS - Geometry Engine Open Source
  * http://geos.refractions.net
@@ -64,7 +63,7 @@
 	 * The SegmentStrings have the same context as their parent.
 	 *
 	 * @return a newly allocated std::vector of const SegmentStrings.
-	 *         Caller is responsible to delete it
+	 *         Caller is responsible to delete container and elements.
 	 */
 	virtual std::vector<SegmentString*>* getNodedSubstrings() const=0;
 
@@ -83,13 +82,3 @@
 
 #endif // GEOS_NODING_NODER_H
 
-/**********************************************************************
- * $Log$
- * Revision 1.2  2006/03/24 09:52:41  strk
- * USE_INLINE => GEOS_INLINE
- *
- * Revision 1.1  2006/03/09 16:46:49  strk
- * geos::geom namespace definition, first pass at headers split
- *
- **********************************************************************/
-

Modified: trunk/include/geos/noding/SegmentNodeList.h
===================================================================
--- trunk/include/geos/noding/SegmentNodeList.h	2011-07-26 16:36:42 UTC (rev 3452)
+++ trunk/include/geos/noding/SegmentNodeList.h	2011-07-27 08:12:56 UTC (rev 3453)
@@ -61,9 +61,6 @@
 	// the parent edge
 	const NodedSegmentString& edge; 
 
-	// This vector is here to keep track of created splitEdges
-	std::vector<SegmentString*> splitEdges;
-
 	/**
 	 * Checks the correctness of the set of split edges corresponding
 	 * to this edge
@@ -77,6 +74,8 @@
 	 * (and including) the two intersections.
 	 * The label for the new edge is the same as the label for the
 	 * parent edge.
+	 * 
+	 * ownership of return value is transferred
 	 */
 	SegmentString* createSplitEdge(SegmentNode *ei0, SegmentNode *ei1);
 

Modified: trunk/src/noding/SegmentNodeList.cpp
===================================================================
--- trunk/src/noding/SegmentNodeList.cpp	2011-07-26 16:36:42 UTC (rev 3452)
+++ trunk/src/noding/SegmentNodeList.cpp	2011-07-27 08:12:56 UTC (rev 3453)
@@ -56,11 +56,6 @@
 	{
 		delete *it;
 	}
-
-	for(size_t i=0, n=splitEdges.size(); i<n; ++i)
-	{
-		delete splitEdges[i];
-	}
 }
 
 SegmentNode*
@@ -217,6 +212,7 @@
 #endif
 }
 
+/*private*/
 void
 SegmentNodeList::checkSplitEdgesCorrectness(std::vector<SegmentString*>& splitEdges)
 {
@@ -286,7 +282,6 @@
 #if GEOS_DEBUG
 	std::cerr<<" SegmentString created"<<std::endl;
 #endif
-	splitEdges.push_back(ret);
 
 	return ret;
 }

Modified: trunk/src/operation/buffer/BufferBuilder.cpp
===================================================================
--- trunk/src/operation/buffer/BufferBuilder.cpp	2011-07-26 16:36:42 UTC (rev 3452)
+++ trunk/src/operation/buffer/BufferBuilder.cpp	2011-07-27 08:12:56 UTC (rev 3453)
@@ -194,11 +194,13 @@
    // Node these SegmentStrings.
    Noder* noder = getNoder( precisionModel );
    noder->computeNodes( &curveList );
+
    SegmentString::NonConstVect* nodedEdges = noder->getNodedSubstrings();
 
    // Create a geometry out of the noded substrings.
    std::vector< Geometry* >* singleSidedNodedEdges =
       new std::vector< Geometry * >();
+   singleSidedNodedEdges->reserve(nodedEdges->size());
    for ( unsigned int i = 0, n = nodedEdges->size(); i < n; ++i )
    {
       SegmentString* ss = ( *nodedEdges )[i];
@@ -206,10 +208,12 @@
       Geometry* tmp = geomFact->createLineString(
                         ss->getCoordinates()->clone()
                       );
+      delete ss;
+
       singleSidedNodedEdges->push_back( tmp );
    }
 
-   if ( nodedEdges != &curveList ) delete nodedEdges;
+   delete nodedEdges;
 
    for (size_t i=0, n=curveList.size(); i<n; ++i) delete curveList[i];
    curveList.clear();
@@ -526,25 +530,22 @@
 		const Label* oldLabel = static_cast<const Label*>(segStr->getData());
 
 		CoordinateSequence* cs = CoordinateSequence::removeRepeatedPoints(segStr->getCoordinates());
+		delete segStr;
 		if ( cs->size() < 2 ) 
 		{
-			delete cs; // we need to take care of the memory here as cs is a new sequence
-			return; // don't insert collapsed edges
+			// don't insert collapsed edges
+			delete cs; 
+			return;
 		}
-		// we need to clone SegmentString coordinates
-		// as Edge will take ownership of them
-		// TODO: find a way to transfer ownership instead
-		// Who will own the edge ? FIXME: find out and handle that!
+
+		// Edge takes ownership of the CoordinateSequence
 		Edge* edge = new Edge(cs, *oldLabel);
 
 		// will take care of the Edge ownership
 		insertUniqueEdge(edge);
 	}
 
-	if ( nodedSegStrings != &bufferSegStrList )
-	{
-		delete nodedSegStrings;
-	}
+	delete nodedSegStrings;
 
 	if ( noder != workingNoder ) delete noder;
 }



More information about the geos-commits mailing list