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