Skip to content
Commit 9d1586c4 authored by Volker Krause's avatar Volker Krause
Browse files

Add support for polymorphic payloads to Akonadi::Item.

Polymorphic payload support means that the payload mechanism in
Akonadi::Item is no longer limited to retrieve the exact same payload
type that was put in, but can now also cast if possible, which is
especially useful with payloads like KCal or KMime objects.

However, implementing that is much harder than it sounds and requires
some external hints, namely compile-time introspection of the
inheritance hierarchy. This is provided by KPIMUtils::SuperTrait and its
specializations in KCal and KMime.

While I was at it I also added convenience typedefs for shared pointers
for KCal and KMime objects, as we have them all over Akonadi code
currently.

The changes to Akonadi::Item itself have a few side-effects though,
besides adding support for polymorphic payloads in boost::shared_ptr and
QSharedPointer:
- There are strict compile-time checks for invalid payload types now, so
  trying to use a pointer as payload will fail to compile instead of
  crash at runtime.
- When using a shared pointer payload, the class the shared pointer
  contains now needs to be fully declared when the payload related
  templates are instantiated, so far one could get away with just a
  forward declaration in some cases. I only found one occurence of that 
  in our code, so this doesn't seem to be a problem in practice.
- So far behaviour was pretty much undefined when retrieving a
  mismatching payload type (most probably it would crash somehow), in
  this cases an exception is thrown now. This will reliably crash if the
  application doesn't care (normal code should use hasPayload() and never
  get there), but also allows handling this kind of error (which eg. the
  Item code uses internally). However, this means we need to compile
  every user of the payload mechanism with exception support now (the
  exception throwing happens in template code). 

svn path=/trunk/KDE/kdepimlibs/; revision=961996
parent 9e37aa3d
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment