palmtopuidgen.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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
00030 QPC_TEMPLATEEXTERN template class QPC_EXPORT QMap< int, bool >;
00031
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
00064
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
This file is part of the documentation for OPIE Version 1.5.5.