-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OGRGeometryFactory: Add createFromWkt overload returning unique_ptr #11165
Conversation
As forceToPolygon() consumes the input geometry, In the more general case, if we don't want to break backwards compatibility, |
5571e5b
to
886fe26
Compare
Maybe @elpaso has some thoughts about that topic of how to keep methods that return a raw pointer vs enhanced ones that would return a unique_ptr ? |
Not sure: can you point me to a method that should be converted to std::unique_ptr (besides forceToPolygon that if I get this right doesn't have a problem)?. |
|
I don't see many options here, we could create a set of new methods with a different name/suffix (something like AsUnique) and deprecate the old methods (or not). Regarding methods that might return the original geometry instead of a new one, I would probably change their behavior to throw an exception or return a null (unique) ptr. |
The GDAL C++ API doesn't throw exceptions. Most of the code isn't ready for that given there are manual C style memory allocations, and that would cause memory leaks. C++ exceptions also apparently tend to cause issues when people run under debugger on Windows I believe (at least users seem to be regularly annoyed by PROJ throwing occasionaly C++ exceptions for its internal needs, despite PROJ catching them before they face the caller) |
An alternative to a return type of Instead of
you'd have
I prefer the |
yes, for now, we've restricted use of C++17 features to our GDAL internal use. https://gdal.org/en/latest/development/rfc/rfc98_build_requirements_gdal_3_9.html : "While we want to allow C++17 features to build GDAL, for now, we will stick to exposing at most C++11 features in the exported headers of the library to minimize disruption for GDAL C++ users. That might be revisited later" . |
What does this PR do?
Adds an overload of
OGRGeometry::createFromWkt
to more easily get aunique_ptr<OGRGeometry>
from a WKT string. I don't know how others feel about thestd::pair
return in place of an "out" parameter. The diff in autotest/cpp/test_ogr.cppautotest/cpp/test_ogr.cpp demonstrates the simplification nicely.Unfortunately this technique isn't generally applicable to methods currently returning a raw pointer. I'm not sure what the best pattern for addressing those is. Maybe just adding a new method with a
U
at the end? For example,std::unique_ptr<OGRPolygon> OGRGeometryFactory::forceToPolygonU(const OGRGeometry*)
. Ugly, but I haven't thought of a better idea yet.