libkpimexchange Library API Documentation

dateset.h

00001 /*
00002     This file is part of libkpimexchange.
00003     Copyright (c) 2002 Jan-Pascal van Best <janpascal@vanbest.org>
00004 
00005     This library is free software; you can redistribute it and/or modify it
00006     under the terms of the GNU Library General Public License as published by
00007     the Free Software Foundation; either version 2 of the License, or (at your
00008     option) any later version.
00009 
00010     This library is distributed in the hope that it will be useful, but WITHOUT
00011     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00013     License for more details.
00014 
00015     You should have received a copy of the GNU Library General Public License
00016     along with this library; see the file COPYING.LIB.  If not, write to the
00017     Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
00018     02111-1307, USA.
00019 */
00020 
00021 // $Id: dateset.h,v 1.1 2002/12/11 11:25:13 janpascal Exp $
00022 
00023 #ifndef _DATESET_H
00024 #define _DATESET_H
00025 
00026 #include <qdatetime.h>
00027 #include <qpair.h>
00028 #include <qptrlist.h>
00029 
00030 /*
00031 class DateRange {
00032   public:
00033     DateRange() { }
00034     DateRange( QDate const& from, QDate const& to )
00035         : mFrom( from ), mTo( to ) { }
00036     bool operator< ( const DateRange& r ) { return mFrom < r.from(); }
00037     bool contains( QDate const& d ) { return ( mFrom <= d && d <= mTo ); }
00038     bool contains( QDate const& from, QDate const& to ) { return ( mFrom <= from && to <= mTo ); }
00039 
00040     QDate from() { return mFrom; }
00041     QDate to() { return mTo; }
00042 
00043   private:
00044     QDate mFrom;
00045     QDate mTo;
00046 }
00047 */
00048 
00049 class RangeList : public QPtrList< QPair<QDate, QDate> > {
00050   protected:
00051     virtual int compareItems(QPtrCollection::Item item1, QPtrCollection::Item item2) {
00052        QPair<QDate,QDate> *i1 = static_cast<QPair<QDate,QDate> *> (item1);
00053        QPair<QDate,QDate> *i2 = static_cast<QPair<QDate,QDate> *> (item2);
00054        if ( *i1 < *i2 ) return -1;
00055        if ( *i2 < *i1 ) return 1;
00056        return 0;
00057     }
00058 };
00059 
00060 class DateSet {
00061   public:
00062     DateSet();
00063     ~DateSet();
00064 
00065     void add( QDate const& date );
00066     void add( QDate const& from, QDate const& to );
00067 
00068     void remove( QDate const& date );
00069     void remove( QDate const& from, QDate const& to );
00070     
00071     bool contains( QDate const& date );
00072     // returns true if and only if the whole range is in the set
00073     bool contains( QDate const& from, QDate const& to );
00074 
00075     int find( QDate const &date );
00076     void print();
00077 
00078   protected:
00079   private:
00080     bool tryMerge( int i );
00081     RangeList *mDates; 
00082 
00083     QDate mOldestDate;
00084     QDate mNewestDate;
00085 };  
00086 
00087 #endif
KDE Logo
This file is part of the documentation for libkpimexchange Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat May 1 11:38:09 2004 by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2003