7#include "datastream_p_p.h"
19 ImapInterval::Id begin = 0;
20 ImapInterval::Id end = 0;
27 void add(
const T &values)
30 std::sort(vals.begin(), vals.end());
31 for (
int i = 0; i < vals.count(); ++i) {
32 const int begin = vals[i];
34 if (i == vals.count() - 1) {
35 intervals << ImapInterval(begin, begin);
40 Q_ASSERT(vals[i] >= 0);
41 if (vals[i] != (vals[i - 1] + 1)) {
45 }
while (i < vals.count() - 1);
46 intervals << ImapInterval(begin, vals[i]);
50 ImapInterval::List intervals;
53ImapInterval::ImapInterval()
54 : d(new ImapIntervalPrivate)
58ImapInterval::ImapInterval(
const ImapInterval &other)
63ImapInterval::ImapInterval(Id begin, Id end)
64 : d(new ImapIntervalPrivate)
70ImapInterval::~ImapInterval() =
default;
72ImapInterval &ImapInterval::operator=(
const ImapInterval &other)
81bool ImapInterval::operator==(
const ImapInterval &other)
const
83 return (d->begin == other.d->begin && d->end == other.d->end);
86ImapInterval::Id ImapInterval::size()
const
88 if (!d->begin && !d->end) {
92 return (d->end - d->begin + 1);
95bool ImapInterval::hasDefinedBegin()
const
97 return (d->begin != 0);
100ImapInterval::Id ImapInterval::begin()
const
105bool ImapInterval::hasDefinedEnd()
const
107 return (d->end != 0);
110ImapInterval::Id ImapInterval::end()
const
112 if (hasDefinedEnd()) {
116 return std::numeric_limits<Id>::max();
119void ImapInterval::setBegin(Id value)
121 Q_ASSERT(value >= 0);
122 Q_ASSERT(value <= d->end || !hasDefinedEnd());
126void ImapInterval::setEnd(Id value)
128 Q_ASSERT(value >= 0);
129 Q_ASSERT(value >= d->begin || !hasDefinedBegin());
133QByteArray Akonadi::ImapInterval::toImapSequence()
const
145 if (hasDefinedEnd()) {
155 : d(new ImapSetPrivate)
159ImapSet::ImapSet(Id
id)
160 : d(new ImapSetPrivate)
165 : d(new ImapSetPrivate)
170ImapSet::ImapSet(
const ImapInterval &interval)
171 : d(new ImapSetPrivate)
176ImapSet::ImapSet(
const ImapSet &other)
185ImapSet ImapSet::all()
188 set.add(ImapInterval(1, 0));
192ImapSet &ImapSet::operator=(
const ImapSet &other)
194 if (
this != &other) {
201bool ImapSet::operator==(
const ImapSet &other)
const
203 return d->intervals == other.d->intervals;
206void ImapSet::add(
const QList<Id> &values)
211void ImapSet::add(
const QSet<Id> &values)
222void ImapSet::add(
const ImapInterval &interval)
224 d->intervals << interval;
230 for (
auto iter = d->intervals.cbegin(), end = d->intervals.cend(); iter != end; ++iter) {
231 if (iter != d->intervals.cbegin()) {
234 rv += iter->toImapSequence();
240ImapInterval::List ImapSet::intervals()
const
245bool ImapSet::isEmpty()
const
247 return d->intervals.
isEmpty() || (d->intervals.size() == 1 && d->intervals.at(0).size() == 0);
250void ImapSet::optimize()
253 if (d->intervals.size() < 2) {
258 std::sort(d->intervals.begin(), d->intervals.end(), [](
const ImapInterval &lhs,
const ImapInterval &rhs) {
259 return lhs.begin() < rhs.begin();
262 auto it = d->intervals.begin();
263 while (it != d->intervals.end() && it != std::prev(d->intervals.end())) {
264 auto next = std::next(it);
266 if (it->hasDefinedEnd() && it->end() + 1 >=
next->begin()) {
267 next->setBegin(it->begin());
268 if (
next->hasDefinedEnd() && it->end() >
next->end()) {
269 next->setEnd(it->end());
271 it = d->intervals.erase(it);
272 }
else if (!it->hasDefinedEnd()) {
274 it = d->intervals.erase(next, d->intervals.end());
281Protocol::DataStream &
operator<<(Protocol::DataStream &stream,
const Akonadi::ImapInterval &interval)
283 return stream << interval.d->begin << interval.d->end;
286Protocol::DataStream &
operator>>(Protocol::DataStream &stream, Akonadi::ImapInterval &interval)
288 return stream >> interval.d->begin >> interval.d->end;
291Protocol::DataStream &
operator<<(Protocol::DataStream &stream,
const Akonadi::ImapSet &set)
293 return stream << set.d->intervals;
296Protocol::DataStream &
operator>>(Protocol::DataStream &stream, Akonadi::ImapSet &set)
298 return stream >> set.d->intervals;
307 d << interval.toImapSequence();
313 d << set.toImapSequenceSet();
Helper integration between Akonadi and Qt.
KCALENDARCORE_EXPORT QDataStream & operator>>(QDataStream &in, const KCalendarCore::Alarm::Ptr &)
QDebug operator<<(QDebug dbg, const DcrawInfoContainer &c)
const QList< QKeySequence > & begin()
const QList< QKeySequence > & next()
const QList< QKeySequence > & end()
bool isEmpty() const const
QByteArray number(double n, char format, int precision)
void push_back(parameter_type value)
void reserve(qsizetype size)
const_iterator constBegin() const const
const_iterator constEnd() const const
qsizetype size() const const