[gdal-dev] Pushing OGRLineString * var to a vector problematic ??
Mateusz Loskot
mateusz at loskot.net
Sat Feb 13 01:13:00 PST 2021
On Sat, 13 Feb 2021 at 08:11, Ahmet Temiz <ahmettemiz88 at gmail.com> wrote:
>
> I want to get your view
> Is putting OGRLineString * var to a vector and then a setter a good idea?
>
> ... // same as tutorial
> if( poGeometry != NULL && wkbFlatten(poGeometry->getGeometryType()) == wkbLineString )
> {
> OGRLineString *poLine = (OGRLineString *) poGeometry;
> v_faultLine.push_back(poLine); /// std::vector < OGRLineString * > v_faultLine;
IN the same https://gdal.org/tutorials/vector_api_tut.html you can read
"Note that OGRFeature::GetGeometryRef() [...] return a pointer
to the internal geometry owned by the OGRFeature"
That should explain the v_faultLine is collection of observers and not owners.
If you use it as such, i.e. without trying to take over the
ownership/deallocate,
you should be safe.
> . ...
> }
>
> this->setFaultLine (v_faultLine);
It is not possible to say that it is "a good idea" without
knowing what the setFaultLine expects and does.
If it expects it will take over ownership of elements in v_faultLine,
then watch the holes in your knees.
Best regards,
--
Mateusz Loskot, http://mateusz.loskot.net
More information about the gdal-dev
mailing list