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 ) :
82 if (
this != &other ) {
90 return ( d->begin == other.d->begin && d->end == other.d->end );
95 if ( !d->begin && !d->end ) {
98 if ( d->begin && !d->end ) {
99 return Q_INT64_C( 0x7FFFFFFFFFFFFFFF ) - d->begin + 1;
101 return d->end - d->begin + 1;
106 return d->begin != 0;
129 Q_ASSERT( value >= 0 );
136 Q_ASSERT( value >= 0 );
147 return QByteArray::number( d->begin );
150 rv += QByteArray::number( d->begin ) +
':';
152 rv += QByteArray::number( d->end );
161 QList<QByteArray> values = sequence.split(
':' );
162 if ( values.isEmpty() || values.size() > 2 ) {
167 Id begin = values[0].toLongLong( &ok );
175 if ( values.size() == 1 ) {
177 }
else if ( values[1] == QByteArray(
"*" ) ) {
181 end = values[1].toLongLong( &ok );
204 add( QList<Id>() << value );
218 if (
this != &other ) {
226 if ( d->intervals.size()!=other.d->intervals.size() ) {
230 foreach (
const ImapInterval &interval, d->intervals ) {
231 if ( !other.d->intervals.contains( interval ) ) {
241 add( QList<Id>() << value );
246 QList<Id> vals = values;
248 for (
int i = 0; i < vals.count(); ++i ) {
249 const int begin = vals[i];
250 Q_ASSERT( begin >= 0 );
251 if ( i == vals.count() - 1 ) {
257 Q_ASSERT( vals[i] >= 0 );
258 if ( vals[i] != ( vals[i - 1] + 1 ) ) {
262 }
while ( i < vals.count() - 1 );
269 d->intervals << interval;
274 QList<QByteArray> rv;
275 foreach (
const ImapInterval &interval, d->intervals ) {
281 if ( !rv.isEmpty() ) {
283 QList<QByteArray>::ConstIterator it = rv.constBegin();
285 for ( ; it != rv.constEnd(); ++it ) {
286 result +=
',' + ( *it );
297 QList<QByteArray>
intervals = sequence.split(
',' );
299 foreach (
const QByteArray &interval, intervals ) {
300 if ( !interval.isEmpty() ) {
315 return d->intervals.isEmpty();
318 QDebug& operator<<( QDebug &d,
const ImapInterval &interval )
324 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.