[gdal-dev] OGRGeometry copy constructor

Simon Hege simonhege at hotmail.com
Sun Jun 7 15:11:44 PDT 2015


Even,

I submitted the patch as http://trac.osgeo.org/gdal/ticket/5990

Feel free to ask for improvements if needed.

Simon

> From: even.rouault at spatialys.com
> To: gdal-dev at lists.osgeo.org
> Subject: Re: [gdal-dev] OGRGeometry copy constructor
> Date: Fri, 5 Jun 2015 17:46:20 +0200
> CC: simonhege at hotmail.com
> 
> Simon,
> 
> > Looking at the code of GDAL 2.0 (but also 1.x), I noticed that the
> > OGRGeometry class (and the derived classes) do not respects the Rule of 3
> > : there is a destructor and no copy constructor or assignment operator.
> 
> Indeed, the Rule of 3 is not currently really implemented in the C++ API.
> 
> > It
> > seems to me that this may lead to memory leaks on OGRSpatialReference (for
> > example when using std::vector<OGRPoint> and not std::vector<OGRPoint*>).
> > This is not an issue when using the C API because the clone() method is
> > used. Am I well understanding the API ?
> > 
> > Various solutions exists:
> > 1) defines private copy constructors and assignment operators (eg. libkml
> > does this with a macro on each class: LIBKML_DISALLOW_EVIL_CONSTRUCTORS)
> > 2) implements these methods, and manage poSRS the same way that clone() 
> > does. 3) do nothing (and document it somewhere)
> > 
> > If needed I may open an issue and/or send a patch.
> 
> Option 2 looks good to me if you want to prepare a patch for it. Test cases in 
> autotest/cpp/test_ogr.cpp would be appreciated.
> 
> Even
> 
> -- 
> Spatialys - Geospatial professional services
> http://www.spatialys.com
 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20150607/e5cc5d28/attachment.html>


More information about the gdal-dev mailing list