summaryrefslogtreecommitdiff
path: root/library/backend/palmtopuidgen.h
Unidiff
Diffstat (limited to 'library/backend/palmtopuidgen.h') (more/less context) (ignore whitespace changes)
-rw-r--r--library/backend/palmtopuidgen.h83
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
30template class QPC_EXPORT QMap< int, bool >;
31// MOC_SKIP_END
32#endif
33
34namespace Qtopia {
35
36
37class QPC_EXPORT UidGen
38{
39public:
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
74private:
75 Type type;
76 int sign;
77 QMap<int, bool> ids;
78
79};
80
81}
82
83#endif