Use of Boost library classes in kdecore?

David Jarvie lists at astrojar.org.uk
Fri Jul 6 22:12:22 BST 2007


There is an important issue in the KTimeZone class and the classes derived 
from it which needs to be addressed by using reference counted pointers. The 
most suitable class which I can find is from the Boost library: shared_ptr. 
This has a necessary facility which KSharedPtr lacks, i.e. the ability to 
implicitly convert shared_ptr<T> to shared_ptr<U> whenever T* can be 
implicitly converted to U* (e.g. when U is a base class of T).

The reason reference counted pointers are necessary is to prevent users of 
KTimeZone instances from referencing invalid pointers if the KTimeZone 
instance happens to get deleted somewhere else. This problem has already 
arisen when iCalendar files are reloaded in kdepimlibs/kcal - KDateTime 
objects which reference a time zone require that the KTimeZone instance 
doesn't disappear. It is unrealistic to expect developers in general to be 
sufficiently aware of the issue to manage to avoid it. The problem might only 
manifest itself occasionally, and it is not necessarily easy to track down. 
Use everywhere of a KTimeZonePtr class in place of KTimeZone pointers would 
fix this:

typedef shared_ptr<KTimeZone> KTimeZonePtr;

There are two options if the Boost class is to be used: either make kdelibs 
require the Boost library, which is already required for kdepimlibs; or put a 
copy of the relevant headers (at least 7 of them at a cursory glance) from 
the Boost library into kdecore. As far as I can see, the Boost licence 
(http://www.boost.org/LICENSE_1_0.txt) would not present a problem for the 
latter option.

Comments?

-- 
David Jarvie.
KAlarm author and maintainer.
http://www.astrojar.org.uk/kalarm




More information about the kde-core-devel mailing list