[geos-devel] Recap of requirements for Geometry constructors

Martin Davis mbdavis at VividSolutions.com
Thu Nov 14 20:51:20 EST 2002


I'm not sure if it's been made clear or not, but I thought I'd summarize the requirements for Geometry constructors:

The goal is to make constructors as efficient as possible. This means that whereever possible the constructor should avoid copying point lists.  The decision of whether or not to copy can usually be left to the client.  In general, if a CoordinateList is passed to a constructor, it is not copied and is "owned" by the Geometry object (e.g. will be deleted when the Geometry is).  The same goes for LinearRings passed to Polygons, etc.

The general pattern for the constructors of Geometry classes is:

LineString::LineString()
	this(new ArrayCoordinateList(0))

LineString::LineString(const LineString &ls):  
{
	this(new ArrayCoordinateList(ls.points));		// ls.points will be copied by ArrayCoordinateList constructor
}

// pts is owned by this object and will be deleted by the destructor.   User should provide copy if necessary.
LineString::LineString(CoordinateList pts, PrecisionModel precisionModel, int SRID):
						Geometry(precisionModel, SRID) 
{
	points = pts;
}

LineString::~LineString()
{
	delete points;
}


Not sure, but maybe points can be a reference rather than a pointer?

Martin Davis, Senior Technical Specialist
Vivid Solutions Inc.
Suite #1A-2328 Government Street   Victoria, B.C.   V8T 5G5
Phone: (250) 385 6040    Fax: (250) 385 6046
EMail: mbdavis at vividsolutions.com  Web: www.vividsolutions.com





More information about the geos-devel mailing list