[Kde-pim] KCalCore Ptr typedefs and constness

Sérgio Martins iamsergio at gmail.com
Fri Aug 20 10:24:27 BST 2010


On Thu, Aug 19, 2010 at 4:42 PM, David Jarvie <djarvie at kde.org> wrote:

> On Thu, August 19, 2010 4:29 pm, Sérgio Martins wrote:
> > 2010/8/19 David Jarvie <djarvie at kde.org>
> >
> >> I wonder if in addition to such typedefs as KCalCore::Event::Ptr, there
> >> should also be
> >>
> >> typedef QSharedPointer<const KCalCore::Event> ConstPtr;
> >>
> >> AFAICS, currently it isn't possible using the Ptr types to have a
> >> pointer
> >> to const data. Specifying
> >>
> >> const Ptr
> >>
> >> will only make the pointer const, not the data pointed to.
> >>
> >> Or is QSharedPointer much cleverer than I imagine?
> >>
> >
> > Hello David,
> >
> >
> > Unfortunately it isn't as simple as adding a typedef.
> >
> > ConstPtr will give you a false sense of security and can be breached when
> > you access getters which return non-const pointers:
> >
> > ConstPtr incidence( someIncidence );
> > Person *person = incidence->organizer();
> > person->setName( "foo" ); //ups
> >
> > We would have to duplicate(overload) every function that returns a
> pointer
> > to avoid this.
>
> But isn't this the same as when you use a const pointer instead of
> ConstPtr? E.g. the following use of a const pointer works exactly the same
> as your example: (...)
>

The difference is the typedef. I see the act of creating the typedef as
advertising people to use something that only protects half object.

Without the typedef they still can write QSharedPointer<const Event> and use
it at their own risk.

I would rather have the overloads first, then provide the typedef.


All in all, I think the ability to declare a pointer as const while using
> Ptr/ConstPtr is necessary. I'm happy to provide code for this if it's
> agreed in principle.
>
>
Ok, I'll ping Marc, Bertjan and Allen.


Regards,
Sérgio Martins
_______________________________________________
KDE PIM mailing list kde-pim at kde.org
https://mail.kde.org/mailman/listinfo/kde-pim
KDE PIM home page at http://pim.kde.org/



More information about the kde-pim mailing list