20 #ifndef AKONADI_ITEM_P_H
21 #define AKONADI_ITEM_P_H
23 #include <QtCore/QDateTime>
24 #include <QtCore/QMap>
25 #include <QtCore/QVarLengthArray>
28 #include "itempayloadinternals_p.h"
31 #include <boost/bind.hpp>
50 explicit clone_ptr(T *t)
53 clone_ptr(
const clone_ptr &other)
54 : t(other.t ? other.t->clone() : 0)
60 clone_ptr &operator=(
const clone_ptr &other)
63 clone_ptr copy(other);
68 void swap(clone_ptr &other)
92 void reset(T *other = 0)
105 typedef void (_save_bool::*save_bool)();
107 operator save_bool()
const
109 return get() ? &_save_bool::f : 0;
113 template <
typename T>
114 inline void swap(clone_ptr<T> &lhs, clone_ptr<T> &rhs)
119 template <
typename T,
size_t N>
120 class VarLengthArray {
123 typedef T value_type;
125 typedef const T *const_iterator;
127 typedef const T *const_pointer;
128 typedef T &reference;
129 typedef const T &const_reference;
131 explicit VarLengthArray(
int size = 0)
138 void push_back(
const T &t)
144 return impl.capacity();
156 return impl.isEmpty();
160 return impl.removeLast();
162 void reserve(
size_t n)
166 void resize(
size_t n)
177 return impl.data() + impl.size();
179 const_iterator begin()
const
183 const_iterator end()
const
185 return impl.data() + impl.size();
187 const_iterator cbegin()
const
191 const_iterator cend()
const
202 return *(impl.data() + impl.size());
204 const_reference front()
const
208 const_reference back()
const
210 return *(impl.data() + impl.size());
213 reference operator[](
size_t n)
217 const_reference operator[](
size_t n)
const
225 clone_ptr<PayloadBase> payload;
230 struct BySharedPointerAndMetaTypeID : std::unary_function<TypedPayload, bool>
234 BySharedPointerAndMetaTypeID(
int spid,
int mtid)
239 bool operator()(
const TypedPayload &tp)
const
241 return (mtid == -1 || mtid == tp.metaTypeId)
242 && (spid == -1 || spid == tp.sharedPointerId) ;
252 inline void swap<Akonadi::_detail::TypedPayload>(Akonadi::_detail::TypedPayload &lhs, Akonadi::_detail::TypedPayload &rhs)
254 lhs.payload.swap(rhs.payload);
255 swap(lhs.sharedPointerId, rhs.sharedPointerId);
256 swap(lhs.metaTypeId, rhs.metaTypeId);
262 typedef std::vector<_detail::TypedPayload> PayloadContainer;
267 class QForeachContainer<Akonadi::PayloadContainer> {};
281 , mConversionInProgress(
false)
285 , mModificationTime()
286 , mFlagsOverwritten(
false)
287 , mTagsOverwritten(
false)
288 , mSizeChanged(
false)
289 , mClearPayload(
false)
297 mFlags = other.mFlags;
298 mRevision = other.mRevision;
300 mModificationTime = other.mModificationTime;
301 mMimeType = other.mMimeType;
302 mLegacyPayload = other.mLegacyPayload;
303 mPayloads = other.mPayloads;
304 mConversionInProgress =
false;
305 mAddedFlags = other.mAddedFlags;
306 mDeletedFlags = other.mDeletedFlags;
307 mFlagsOverwritten = other.mFlagsOverwritten;
308 mSizeChanged = other.mSizeChanged;
309 mCollectionId = other.mCollectionId;
310 mClearPayload = other.mClearPayload;
318 void resetChangeLog()
320 mFlagsOverwritten =
false;
322 mDeletedFlags.clear();
323 mSizeChanged =
false;
324 mTagsOverwritten =
false;
326 mDeletedTags.
clear();
334 bool hasMetaTypeId(
int mtid)
const
336 return std::find_if(mPayloads.begin(), mPayloads.end(),
337 _detail::BySharedPointerAndMetaTypeID(-1, mtid))
341 PayloadBase *payloadBaseImpl(
int spid,
int mtid)
const
343 const PayloadContainer::const_iterator it
344 = std::find_if(mPayloads.begin(), mPayloads.end(),
345 _detail::BySharedPointerAndMetaTypeID(spid, mtid));
346 return it == mPayloads.end() ? 0 : it->payload.get() ;
349 bool movePayloadFrom(
ItemPrivate *other,
int mtid)
const
352 const size_t oldSize = mPayloads.size();
353 PayloadContainer &oPayloads = other->mPayloads;
354 const _detail::BySharedPointerAndMetaTypeID matcher(-1, mtid);
355 const size_t numMatching = std::count_if(oPayloads.begin(), oPayloads.end(), matcher);
356 mPayloads.resize(oldSize + numMatching);
358 for (PayloadContainer::iterator
359 dst = mPayloads.begin() + oldSize,
360 src = oPayloads.begin(), end = oPayloads.end() ; src != end ; ++src) {
366 return numMatching > 0 ;
370 std::auto_ptr<PayloadBase> takePayloadBaseImpl(
int spid,
int mtid)
372 PayloadContainer::iterator it
373 = std::find_if(mPayloads.begin(), mPayloads.end(),
374 _detail::BySharedPointerAndMetaTypeID(spid, mtid));
375 if (it == mPayloads.end()) {
376 return std::auto_ptr<PayloadBase>();
378 std::rotate(it, it + 1, mPayloads.end());
379 std::auto_ptr<PayloadBase> result(it->payload.release());
380 mPayloads.pop_back();
385 void setPayloadBaseImpl(
int spid,
int mtid, std::auto_ptr<PayloadBase> p,
bool add)
const
389 mLegacyPayload.reset();
401 mPayloads.resize(add ? mPayloads.size() + 1 : 1);
402 _detail::TypedPayload &tp = mPayloads.back();
403 tp.payload.reset(p.release());
404 tp.sharedPointerId = spid;
405 tp.metaTypeId = mtid;
408 void setLegacyPayloadBaseImpl(std::auto_ptr<PayloadBase> p);
409 void tryEnsureLegacyPayload()
const;
411 mutable _detail::clone_ptr<PayloadBase> mLegacyPayload;
412 mutable PayloadContainer mPayloads;
413 mutable bool mConversionInProgress;
423 Item::Flags mAddedFlags;
424 Item::Flags mDeletedFlags;
428 bool mFlagsOverwritten : 1;
429 bool mTagsOverwritten : 1;
430 bool mSizeChanged : 1;
431 bool mClearPayload : 1;
qint64 Id
Describes the unique id type.