Boost logo

Geometry :

Subject: Re: [geometry] Using Boost.Geometry with a legacy class hierarchy
From: Barend Gehrels (barend_at_[hidden])
Date: 2012-02-21 14:31:53


Hi Mats,

On 21-2-2012 12:43, Mats Taraldsvik wrote:
> Hi Barend,
>
> On 02/20/2012 07:21 PM, Barend Gehrels wrote:
>> Hi Mats,
>>
>>
>> On 20-2-2012 9:03, Mats Taraldsvik wrote:
>>> The object hierarcy is a bit more complex than my current example
>>> (also contains 2d, 3d points, curves etc.), and objects are stored
>>> in pointer to base/super-containers. Therefore, I can't remove the
>>> pointer requirement, I'm afraid. I guess creating separate pointer
>>> and non-pointer specializations (e.g. point_type and point_type_ptr)
>>> since they are so different, means either a lot of duplicated code,
>>> or a very difficult problem...
>>>
>>> I was also hoping to overcome the pointer-to-base container issue
>>> also, but thought it was best to take one step at a time. :)
>>
>>
>> OK, so the first solution I mailed is still based on pointers. Does
>> that work for you?
>>
>
> After re-reading your email, I realise that I misinterpreted it -- the
> version you suggested, using references instead of pointers, should
> work, since it does not modify my hierarchy.
>
> --
>
> However, since I the structure is a bit more complex, and I need to
> worry about casting from base pointers etc. later, I want to use the
> pointer version, as long as it works and behaves correctly.
>
> I managed to fix the issue in QRing, without modifying Boost.Geometry. :)
>
>
> Basically, I needed to change the ConstRingIterator :
> from:
> typedef RingIteratorImpl<std::vector<QLineString*>::const_iterator,
> const QPoint*> ConstRingIterator;
> to:
> typedef RingIteratorImpl<std::vector<QLineString*>::const_iterator,
> QPoint* const> ConstRingIterator;
>
> and then it woked perfectly.
>
> However, I'm not sure if the semantics are right -- shouldn't the
> QPoint be const as well as the pointer (i.e. const QPoint* const)?
> When ConstRingIterator is changed to (const QPoint* const), it does
> not compile (perhaps it is because of lacking specializations (I have
> defined QPoint* and const QPoint*).
>
> I updated my gist with the latest version [1] (a diff userscript is
> available for convenience, if you're not using git [2])

OK, great that it compiles.

I agree, the const-pointer does not mean that the pointee cannot be
modified so indeed it should be expected as const Qpoint* const (or, in
notation I prefer, QPoint const* const).

The following does compile now:

void test(QRing const& ring)
{
     boost::range_iterator<QRing const>::type cri = range_begin(ring);
     (*cri)->x = 5;
     std::cout << boost::geometry::wkt(*cri) << std::endl;
}

Which should not compile - it gives the wrong expectations.

The problem with the pointer-version is that QPoint* and QPoint const*
has to be specialized separately, and are therefore considered
differently in our library. That is not easy to solve. We will discuss
that internally.

Regards, Barend



Geometry list run by mateusz at loskot.net