author | kergoth <kergoth> | 2002-01-25 22:14:26 (UTC) |
---|---|---|
committer | kergoth <kergoth> | 2002-01-25 22:14:26 (UTC) |
commit | 15318cad33835e4e2dc620d033e43cd930676cdd (patch) (unidiff) | |
tree | c2fa0399a2c47fda8e2cd0092c73a809d17f68eb /library/backend/palmtopuidgen.h | |
download | opie-15318cad33835e4e2dc620d033e43cd930676cdd.zip opie-15318cad33835e4e2dc620d033e43cd930676cdd.tar.gz opie-15318cad33835e4e2dc620d033e43cd930676cdd.tar.bz2 |
Initial revision
Diffstat (limited to 'library/backend/palmtopuidgen.h') (more/less context) (ignore whitespace changes)
-rw-r--r-- | library/backend/palmtopuidgen.h | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/library/backend/palmtopuidgen.h b/library/backend/palmtopuidgen.h new file mode 100644 index 0000000..1a16681 --- a/dev/null +++ b/library/backend/palmtopuidgen.h | |||
@@ -0,0 +1,83 @@ | |||
1 | #ifndef QTPALMTOP_UIDGEN_H | ||
2 | #define QTPALMTOP_UIDGEN_H | ||
3 | /********************************************************************** | ||
4 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | ||
5 | ** | ||
6 | ** This file is part of Qtopia Environment. | ||
7 | ** | ||
8 | ** Licensees holding valid Qtopia Developer license may use this | ||
9 | ** file in accordance with the Qtopia Developer License Agreement | ||
10 | ** provided with the Software. | ||
11 | ** | ||
12 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING | ||
13 | ** THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
14 | ** PURPOSE. | ||
15 | ** | ||
16 | ** email sales@trolltech.com for information about Qtopia License | ||
17 | ** Agreements. | ||
18 | ** | ||
19 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
20 | ** not clear to you. | ||
21 | ** | ||
22 | **********************************************************************/ | ||
23 | |||
24 | #include <time.h> | ||
25 | #include <qmap.h> | ||
26 | #include "qpcglobal.h" | ||
27 | |||
28 | #if defined(QPC_TEMPLATEDLL) | ||
29 | // MOC_SKIP_BEGIN | ||
30 | template class QPC_EXPORT QMap< int, bool >; | ||
31 | // MOC_SKIP_END | ||
32 | #endif | ||
33 | |||
34 | namespace Qtopia { | ||
35 | |||
36 | |||
37 | class QPC_EXPORT UidGen | ||
38 | { | ||
39 | public: | ||
40 | enum Type { Qtopia, PalmtopCenter }; | ||
41 | |||
42 | UidGen() : type( Qtopia ), sign( -1 ), ids() | ||
43 | { | ||
44 | #ifdef PALMTOPCENTER | ||
45 | type = PalmtopCenter; | ||
46 | sign = 1; | ||
47 | #endif | ||
48 | } | ||
49 | UidGen( Type t ) : type(t), sign(1), ids() | ||
50 | { | ||
51 | if ( t == Qtopia ) | ||
52 | sign = -1; | ||
53 | } | ||
54 | |||
55 | virtual ~UidGen() { } | ||
56 | |||
57 | int generate() const | ||
58 | { | ||
59 | int id = sign * (int) ::time(NULL); | ||
60 | while ( ids.contains( id ) ) { | ||
61 | id += sign; | ||
62 | |||
63 | // check for overflow cases; if so, wrap back to beginning of | ||
64 | // set ( -1 or 1 ) | ||
65 | if ( sign == -1 && id > 0 || sign == 1 && id < 0 ) | ||
66 | id = sign; | ||
67 | } | ||
68 | return id; | ||
69 | } | ||
70 | |||
71 | void store(int id) { ids.insert(id, TRUE); } | ||
72 | bool isUnique(int id) const { return (!ids.contains(id)); } | ||
73 | |||
74 | private: | ||
75 | Type type; | ||
76 | int sign; | ||
77 | QMap<int, bool> ids; | ||
78 | |||
79 | }; | ||
80 | |||
81 | } | ||
82 | |||
83 | #endif | ||