Qtopia library API Documentation

palmtopuidgen.h

00001 /**********************************************************************
00002 ** Copyright (C) 2000-2002 Trolltech AS.  All rights reserved.
00003 **
00004 ** This file is part of the Qtopia Environment.
00005 **
00006 ** This file may be distributed and/or modified under the terms of the
00007 ** GNU General Public License version 2 as published by the Free Software
00008 ** Foundation and appearing in the file LICENSE.GPL included in the
00009 ** packaging of this file.
00010 **
00011 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00012 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00013 **
00014 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
00015 **
00016 ** Contact info@trolltech.com if any conditions of this licensing are
00017 ** not clear to you.
00018 **
00019 **********************************************************************/
00020 
00021 #ifndef QTPALMTOP_UIDGEN_H
00022 #define QTPALMTOP_UIDGEN_H
00023 
00024 #include <time.h>
00025 #include <qmap.h>
00026 #include "qpcglobal.h"
00027 
00028 #if defined(QPC_TEMPLATEDLL)
00029 // MOC_SKIP_BEGIN
00030 QPC_TEMPLATEEXTERN template class QPC_EXPORT QMap< int, bool >;
00031 // MOC_SKIP_END
00032 #endif
00033 
00034 namespace Qtopia {
00035 
00036 
00037 class QPC_EXPORT UidGen
00038 {
00039 public:
00040     enum Type { Qtopia, PalmtopCenter };
00041 
00042     UidGen() : type( Qtopia ), sign( -1 ), ids()
00043 {
00044 #ifdef PALMTOPCENTER
00045     type = PalmtopCenter;
00046     sign = 1;
00047 #endif
00048 }
00049     UidGen( Type t ) : type(t), sign(1), ids()
00050 {
00051     if ( t == Qtopia )
00052     sign = -1;
00053 }
00054 
00055     virtual ~UidGen() { }
00056 
00057     int generate() const
00058 {
00059     int id = sign * (int) ::time(NULL);
00060     while ( ids.contains( id ) ) {
00061     id += sign;
00062     
00063     // check for overflow cases; if so, wrap back to beginning of
00064     // set ( -1 or 1 )
00065     if ( sign == -1 && id > 0 || sign == 1 && id < 0 )
00066         id = sign;
00067     }
00068     return id;
00069 }
00070 
00071     void store(int id) { ids.insert(id, TRUE); }
00072     bool isUnique(int id) const { return (!ids.contains(id)); }
00073 
00074 private:
00075     Type type;
00076     int sign;
00077     QMap<int, bool> ids;
00078 
00079 };
00080 
00081 }
00082 
00083 #endif
KDE Logo
This file is part of the documentation for OPIE Version 1.5.5.
Documentation copyright © 1997-2003 the KDE developers. 2003 OPIE developers
Generated on Tue Feb 10 20:24:06 2004 by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2001