[Proj] C++ coding practices w.r.t object ownership

Mateusz Loskot mateusz at loskot.net
Tue May 29 11:12:16 EST 2018


On 29 May 2018 at 15:01, Martin Desruisseaux
<martin.desruisseaux at geomatys.com> wrote:
> Le 29/05/2018 à 14:28, Even Rouault a écrit :
>>
>> Another main reason is that the UML modelling from which this is derived
>> from has probably be done with Java in mind as an implementation target. So
>> shared pointers are the closest tool we have to emulate Java garbage
>> collection.
>
> Actually the design is a little bit more abstract. Normally (unless we did a
> mistake in the model), there is no requirement to use a garbage collector or
> not; the choice is up to implementer. ISO 19111 allows implementations
> without garbage collector by allowing some pointers to be null, for breaking
> cycles. For example, on a conceptual point of view
> Conversion.source/targetCRS should never be null. But in practice ISO 19111
> nevertheless declares those associations as optional for implementers who
> want to avoid cycles between Conversion and ProjectedCRS.

In such case, final version of the Even's POC should/could state
the implementation requirement more explicitly, eg.

CRSPtr sourceCRS() const
{
    if (auto p = crsWeak_.lock())
        return p;
    else
        throw std::logic_error("dereferencing expired pointer");
}

Best regards,
-- 
Mateusz Loskot, http://mateusz.loskot.net


More information about the Proj mailing list