Skip to content
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

return const OGRSpatialReference* for a few methods(fixes #7377) #7381

Merged
merged 3 commits into from
Mar 22, 2023

Conversation

rouault
Copy link
Member

@rouault rouault commented Mar 8, 2023

  • Make OGRCoordinateTransformation::GetSourceCS() and GetTargetCS() return a const OGRSpatialReference* (fixes Make OGRCoordinateTransformation::GetSourceCS/GetTargetCS() return a const OGRSpatialReference* #7377)

    to reflect that those objects should be considered immutable.

    The downside is that we have internally to
    const_cast<OGRSpatialReference*>, in particular in
    OGRGeometry::transform() when assigning GetTargetCS() to the geometry,
    as assignSpatialReference() needs to increase the reference count.

  • Make OGRGeometry::getSpatialReference() return a const OGRSpatialReference*

  • Make OGRGeomFieldDefn::GetSpatialRef() return a const OGRSpatialReference*

@rouault rouault added this to the 3.7.0 milestone Mar 8, 2023
Copy link
Collaborator

@elpaso elpaso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, for the const_cast, would it be possible to mark Reference mutable and avoid the cast?

@rouault
Copy link
Member Author

rouault commented Mar 22, 2023

would it be possible to mark Reference mutable and avoid the cast?

I considered this. The issue is that we have a GetRefCount() method, so nRefCount is not just an implementation detail and Reference() has thus visible effects which make it a bit hard to tag is a const.

…urn a const OGRSpatialReference* (fixes OSGeo#7377)

to reflect that those objects should be considered immutable.

The downside is that we have internally to
const_cast<OGRSpatialReference*>, in particular in
OGRGeometry::transform() when assigning GetTargetCS() to the geometry,
as assignSpatialReference() needs to increase the reference count.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make OGRCoordinateTransformation::GetSourceCS/GetTargetCS() return a const OGRSpatialReference*
2 participants