This file is indexed.

/usr/include/akonadi/itempayloadinternals_p.h is in kdepimlibs5-dev 4:4.13.0-0ubuntu1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
/*
    Copyright (c) 2007 Till Adam <adam@kde.org>

    This library is free software; you can redistribute it and/or modify it
    under the terms of the GNU Library General Public License as published by
    the Free Software Foundation; either version 2 of the License, or (at your
    option) any later version.

    This library is distributed in the hope that it will be useful, but WITHOUT
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
    License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to the
    Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
*/

#ifndef ITEMPAYLOADINTERNALS_P_H
#define ITEMPAYLOADINTERNALS_P_H

#include <kpimutils/supertrait.h>

#include <QtCore/QtGlobal>
#include <QtCore/QSharedPointer>
#include <QtCore/QMetaType>

#include <boost/shared_ptr.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/mpl/eval_if.hpp>
#include <boost/mpl/identity.hpp>
#include <boost/utility/enable_if.hpp>

#include <typeinfo>

#include "exception.h"

//@cond PRIVATE Doxygen 1.7.1 hangs processing this file. so skip it.
//for more info, see https://bugzilla.gnome.org/show_bug.cgi?id=531637

/* WARNING
 * The below is an implementation detail of the Item class. It is not to be
 * considered public API, and subject to change without notice
 */

namespace Akonadi {
namespace Internal {

template <typename T>
struct has_clone_method {
private:
    template <typename S, S * (S::*)() const> struct sfinae {};
    struct No {};
    struct Yes { No no[2]; };
    template <typename S> static No  test( ... );
    template <typename S> static Yes test( sfinae<S,&S::clone> * );
public:
    static const bool value = sizeof( test<T>(0) ) == sizeof( Yes ) ;
};

template <typename T, bool b>
struct clone_traits_helper {
    // runtime error (commented in) or compiletime error (commented out)?
    // ### runtime error, until we check has_clone_method in the
    // ### Item::payload<T> impl directly...
    template <typename U>
    static T * clone( U ) { return 0; }
};

template <typename T>
struct clone_traits_helper<T,true> {
    static T * clone( T * t ) { return t ? t->clone() : 0 ; }
};

template <typename T>
struct clone_traits : clone_traits_helper<T, has_clone_method<T>::value> {};

template <typename T>
struct shared_pointer_traits {
    static const bool defined = false;
};

template <typename T>
struct shared_pointer_traits< boost::shared_ptr<T> > {
    static const bool defined = true;
    typedef T element_type;
    template <typename S>
    struct make { typedef boost::shared_ptr<S> type; };
    typedef QSharedPointer<T> next_shared_ptr;
};

template <typename T>
struct shared_pointer_traits< QSharedPointer<T> > {
    static const bool defined = true;
    typedef T element_type;
    template <typename S>
    struct make { typedef QSharedPointer<S> type; };
    typedef boost::shared_ptr<T> next_shared_ptr;
};

template <typename T>
struct is_shared_pointer {
    static const bool value = shared_pointer_traits<T>::defined;
};

template <typename T>
struct get_hierarchy_root;

template <typename T, typename S>
struct get_hierarchy_root_recurse
    : get_hierarchy_root<S> {};

template <typename T>
struct get_hierarchy_root_recurse<T,T>
    : boost::mpl::identity<T> {};

template <typename T>
struct get_hierarchy_root
    : get_hierarchy_root_recurse< T, typename ::KPIMUtils::SuperClass<T>::Type > {};

template <typename T>
struct get_hierarchy_root< boost::shared_ptr<T> > {
    typedef boost::shared_ptr< typename get_hierarchy_root<T>::type > type;
};

template <typename T>
struct get_hierarchy_root< QSharedPointer<T> > {
    typedef QSharedPointer< typename get_hierarchy_root<T>::type > type;
};

/**
  @internal
  Payload type traits. Implements specialized handling for polymorphic types and smart pointers.
  The default one is never used (as isPolymorphic is always false) and only contains safe dummy
  implementations to make the compiler happy (in practice it will always optimized away anyway).
*/
template <typename T> struct PayloadTrait
{
  /// type of the payload object contained inside a shared pointer
  typedef T ElementType;
  // the metatype id for the element type, or for pointer-to-element
  // type, if in a shared pointer
  static int elementMetaTypeId() { return qMetaTypeId<T>(); }
  /// type of the base class of the payload object inside a shared pointer,
  /// same as ElementType if there is no super class
  typedef typename KPIMUtils::SuperClass<T>::Type SuperElementType;
  /// type of this payload object
  typedef T Type;
  /// type of the payload to store a base class of this payload
  /// (eg. a shared pointer containing a pointer to SuperElementType)
  /// same as Type if there is not super class
  typedef typename KPIMUtils::SuperClass<T>::Type SuperType;
  /// indicates if this payload is polymorphic, that is is a shared pointer
  /// and has a known super class
  static const bool isPolymorphic = false;
  /// checks an object of this payload type for being @c null
  static inline bool isNull( const Type & ) { return true; }
  /// casts to Type from @c U
  /// throws a PayloadException if casting failed
  template <typename U> static inline Type castFrom( const U& )
  {
    throw PayloadException( "you should never get here" );
  }
  /// tests if casting from @c U to Type is possible
  template <typename U> static inline bool canCastFrom( const U& )
  {
    return false;
  }
  /// cast to @c U from Type
  template <typename U> static inline U castTo( const Type& )
  {
    throw PayloadException( "you should never get here" );
  }
  template <typename U> static T clone( const U & )
  {
    throw PayloadException( "clone: you should never get here" );
  }
  /// defines the type of shared pointer used (0: none, > 0: boost::shared_ptr, QSharedPointer, ...)
  static const unsigned int sharedPointerId = 0;
};

/**
  @internal
  Payload type trait specialization for boost::shared_ptr
  for documentation of the various members, see above
*/
template <typename T> struct PayloadTrait<boost::shared_ptr<T> >
{
  typedef T ElementType;
  static int elementMetaTypeId() { return qMetaTypeId<T*>(); }
  typedef typename KPIMUtils::SuperClass<T>::Type SuperElementType;
  typedef boost::shared_ptr<ElementType> Type;
  typedef boost::shared_ptr<SuperElementType> SuperType;
  static const bool isPolymorphic = !boost::is_same<ElementType, SuperElementType>::value;
  static inline bool isNull( const Type &p ) { return p.get() == 0; }
  template <typename U> static inline Type castFrom( const boost::shared_ptr<U> &p )
  {
    const Type sp = boost::dynamic_pointer_cast<T,U>( p );
    if ( sp.get() != 0 || p.get() == 0 )
      return sp;
    throw PayloadException( "boost::dynamic_pointer_cast failed" );
  }
  template <typename U> static inline bool canCastFrom( const boost::shared_ptr<U> &p )
  {
    const Type sp = boost::dynamic_pointer_cast<T,U>( p );
    return sp.get() != 0 || p.get() == 0;
  }
  template <typename U> static inline boost::shared_ptr<U> castTo( const Type &p )
  {
    const boost::shared_ptr<U> sp = boost::dynamic_pointer_cast<U>( p );
    return sp;
  }
  static boost::shared_ptr<T> clone( const QSharedPointer<T> & t ) {
      if ( T * nt = clone_traits<T>::clone( t.data() ) )
          return boost::shared_ptr<T>( nt );
      else
          return boost::shared_ptr<T>();
  }
  static const unsigned int sharedPointerId = 1;
};

/**
  @internal
  Payload type trait specialization for QSharedPointer
  for documentation of the various members, see above
*/
template <typename T> struct PayloadTrait<QSharedPointer<T> >
{
  typedef T ElementType;
  static int elementMetaTypeId() { return qMetaTypeId<T*>(); }
  typedef typename KPIMUtils::SuperClass<T>::Type SuperElementType;
  typedef QSharedPointer<T> Type;
  typedef QSharedPointer<SuperElementType> SuperType;
  static const bool isPolymorphic = !boost::is_same<ElementType, SuperElementType>::value;
  static inline bool isNull( const Type &p ) { return p.isNull(); }
  template <typename U> static inline Type castFrom( const QSharedPointer<U> &p )
  {
    const Type sp = qSharedPointerDynamicCast<T,U>( p );
    if ( !sp.isNull() || p.isNull() )
      return sp;
    throw PayloadException( "qSharedPointerDynamicCast failed" );
  }
  template <typename U> static inline bool canCastFrom( const QSharedPointer<U> &p )
  {
    const Type sp = qSharedPointerDynamicCast<T,U>( p );
    return !sp.isNull() || p.isNull();
  }
  template <typename U> static inline QSharedPointer<U> castTo( const Type &p )
  {
    const QSharedPointer<U> sp = qSharedPointerDynamicCast<U,T>( p );
    return sp;
  }
  static QSharedPointer<T> clone( const boost::shared_ptr<T> & t ) {
      if ( T * nt = clone_traits<T>::clone( t.get() ) )
          return QSharedPointer<T>( nt );
      else
          return QSharedPointer<T>();
  }
  static const unsigned int sharedPointerId = 2;
};

}

/**
 * @internal
 * Non-template base class for the payload container.
 * @note Move to Internal namespace for KDE5
 */
struct PayloadBase
{
    virtual ~PayloadBase() { }
    virtual PayloadBase * clone() const = 0;
    virtual const char* typeName() const = 0;
};

/**
 * @internal
 * Container for the actual payload object.
 * @note Move to Internal namespace for KDE5
 */
template <typename T>
struct Payload : public PayloadBase
{
    Payload() {};
    Payload( const T& p ) : payload( p ) {}

    PayloadBase * clone() const
    {
        return new Payload<T>( const_cast<Payload<T>* >(this)->payload);
    }

    const char* typeName() const
    {
      return typeid(const_cast<Payload<T>*> (this)).name();
    }

    T payload;
};

/**
 * @internal
 * abstract, will therefore always fail to compile for pointer payloads
 */
template <typename T>
struct Payload<T*> : public PayloadBase
{
};

namespace Internal {

/**
  @internal
  Basically a dynamic_cast that also works across DSO boundaries.
*/
template <typename T> inline Payload<T>* payload_cast( PayloadBase* payloadBase )
{
  Payload<T> *p = dynamic_cast<Payload<T>*>( payloadBase );
  // try harder to cast, workaround for some gcc issue with template instances in multiple DSO's
  if ( !p && payloadBase && strcmp( payloadBase->typeName(), typeid(p).name() ) == 0 ) {
    p = static_cast<Payload<T>*>( payloadBase );
  }
  return p;
}

}

}
//@endcond

#endif