Use of Boost library classes in kdecore?

David Jarvie lists at astrojar.org.uk
Sun Jul 8 20:15:27 BST 2007


On Sunday 08 July 2007 15:45:39 Thiago Macieira wrote:
> David Jarvie wrote:
> >I tested it after adding a virtual function to TimeZone, and it does
> > work. The drawback of using this approach is that the private classes
> > need to be publicly available in order to derive from them outside
> > kdelibs. I suspect that introducing another level of private class
> > (i.e. a d-pointer within the "private" classes) might fix this.
>
> No. Keep the private classes private, but in a _p.h file.
>
> *IF* the need arises for this to be available for an application in an
> URGENCY, then it can copy the _p.h file while waiting for the inclusion
> in kdelibs.
>
> It's like my other email: I find it very unlikely that any application
> will need another timezone backend format that:
>
> 1) is unsuitable for kdelibs inclusion
> or 2) cannot be added to kdelibs in time

On Sunday 08 July 2007 15:58:45 Thomas Zander wrote:
> Then don't derive them outside of kdelibs :)

There is already a derived class in kdepimlibs. Given that it's specific to 
iCalendar, I think that it belongs there, not in kdelibs.

> Honestly; why would you want to? And are you sure its worth the extra
> complexity?  I doubt it personally.

I've now got it working, using an implementation class which keeps track of 
the ref counts and implements virtual functions. There is no exposure of 
private class data or implementation details. I don't see why there should be 
a problem in making the KTimeZoneImpl class public. To summarise the 
approach:

class KTimeZone
{
...
private:
KTimeZoneImpl *d;
};

class KTimeZoneImpl
{
public:
    KTimeZoneImpl();
    explicit KTimeZoneImpl(const QString &name);
    KTimeZoneImpl(const KTimeZoneImpl &other);
    KTimeZoneImpl &operator=(const KTimeZoneImpl &other);
    virtual ~KTimeZoneImpl();
    virtual KTimeZoneImpl *clone() const;
    // Implementation of KTimeZone virtual methods
    virtual .....
private:
    KTimeZonePrivate *d;
};

Derived classes are like this:

class KSystemTimeZone : public KTimeZone
{
...
    // No d-pointer
};

class KSystemTimeZoneImpl : public KTimeZoneImpl
{
    // constructors
    virtual KTimeZoneImpl *clone() const;
    // Implementation of KSystemTimeZone virtual methods
    virtual ...
private:
    KSystemTimeZonePrivate *d;
};

The KTimeZonePrivate etc. classes are truly private, and contain all data.

I attach the full kdelibs code.

-- 
David Jarvie.
KAlarm author and maintainer.
http://www.astrojar.org.uk/kalarm
-------------- next part --------------
A non-text attachment was scrubbed...
Name: timezone.tar.bz2
Type: application/x-tbz
Size: 24261 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20070708/a7381aca/attachment.bin>


More information about the kde-core-devel mailing list