22 #include <QtCore/QSharedData>
24 using namespace KIMAP;
26 class ImapInterval::Private :
public QSharedData
35 Private(
const Private &other ) :
46 class ImapSet::Private :
public QSharedData
49 Private() : QSharedData() {}
50 Private(
const Private &other ) :
83 if (
this != &other ) {
91 return ( d->begin == other.d->begin && d->end == other.d->end );
96 if ( !d->begin && !d->end ) {
99 if ( d->begin && !d->end ) {
100 return Q_INT64_C( 0x7FFFFFFFFFFFFFFF ) - d->begin + 1;
102 return d->end - d->begin + 1;
107 return d->begin != 0;
130 Q_ASSERT( value >= 0 );
137 Q_ASSERT( value >= 0 );
148 return QByteArray::number( d->begin );
151 rv += QByteArray::number( d->begin ) +
':';
153 rv += QByteArray::number( d->end );
162 QList<QByteArray> values = sequence.split(
':' );
163 if ( values.isEmpty() || values.size() > 2 ) {
168 Id begin = values[0].toLongLong( &ok );
176 if ( values.size() == 1 ) {
178 }
else if ( values[1] == QByteArray(
"*" ) ) {
182 end = values[1].toLongLong( &ok );
205 add( QList<Id>() << value );
219 if (
this != &other ) {
227 if ( d->intervals.size()!=other.d->intervals.size() ) {
231 foreach (
const ImapInterval &interval, d->intervals ) {
232 if ( !other.d->intervals.contains( interval ) ) {
242 add( QList<Id>() << value );
247 QList<Id> vals = values;
249 for (
int i = 0; i < vals.count(); ++i ) {
250 const int begin = vals[i];
251 Q_ASSERT( begin >= 0 );
252 if ( i == vals.count() - 1 ) {
258 Q_ASSERT( vals[i] >= 0 );
259 if ( vals[i] != ( vals[i - 1] + 1 ) ) {
263 }
while ( i < vals.count() - 1 );
270 d->intervals << interval;
275 QList<QByteArray> rv;
276 foreach (
const ImapInterval &interval, d->intervals ) {
282 if ( !rv.isEmpty() ) {
284 QList<QByteArray>::ConstIterator it = rv.constBegin();
286 for ( ; it != rv.constEnd(); ++it ) {
287 result +=
',' + ( *it );
298 QList<QByteArray>
intervals = sequence.split(
',' );
300 foreach (
const QByteArray &interval, intervals ) {
301 if ( !interval.isEmpty() ) {
316 return d->intervals.isEmpty();
319 QDebug& operator<<( QDebug &d,
const ImapInterval &interval )
325 QDebug& operator<<( QDebug &d,
const ImapSet &set )
bool isEmpty() const
Returns true if this set doesn't contains any values.
bool operator==(const ImapSet &other) const
Comparison operator.
bool hasDefinedBegin() const
Returns true if this interval has a defined begin.
~ImapInterval()
Destructor.
ImapInterval::List intervals() const
Returns the intervals this set consists of.
bool operator==(const ImapInterval &other) const
Comparison operator.
bool hasDefinedEnd() const
Returns true if this intercal has been defined.
Id size() const
Returns the size of this interval.
ImapSet()
Constructs an empty set.
void add(Id value)
Adds a single positive integer numbers to the set.
Represents a single interval in an ImapSet.
ImapInterval()
Constructs an interval that covers all positive numbers.
ImapInterval & operator=(const ImapInterval &other)
Assignment operator.
void setBegin(Id value)
Sets the begin of the interval.
Represents a set of natural numbers (1-> ) in a as compact as possible form.
static ImapInterval fromImapSequence(const QByteArray &sequence)
Return the interval corresponding to the given IMAP-compatible QByteArray representation.
void setEnd(Id value)
Sets the end of this interval.
QList< ImapInterval > List
A list of ImapInterval objects.
qint64 Id
Describes the ids stored in the interval.
static ImapSet fromImapSequenceSet(const QByteArray &sequence)
Return the set corresponding to the given IMAP-compatible QByteArray representation.
Id end() const
Returns the end of this interval.
Id begin() const
Returns the begin of this interval.
QByteArray toImapSequenceSet() const
Returns a IMAP-compatible QByteArray representation of this set.
QByteArray toImapSequence() const
Converts this set into an IMAP compatible sequence.
ImapSet & operator=(const ImapSet &other)
Assignment operator.
qint64 Id
Describes the ids stored in the set.