|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the Qt Mobility Components. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #ifndef QTCONTACTSGLOBAL_H |
|
43 #define QTCONTACTSGLOBAL_H |
|
44 |
|
45 #include <qmobilityglobal.h> |
|
46 #include <QString> |
|
47 #include <QVariant> |
|
48 |
|
49 #define QTCONTACTS_VERSION_NAME "com.nokia.qt.mobility.contacts.api.version" |
|
50 #define QTCONTACTS_IMPLEMENTATION_VERSION_NAME "com.nokia.qt.mobility.contacts.implementation.version" |
|
51 #define QTCONTACTS_VERSION 1 |
|
52 |
|
53 QTM_BEGIN_NAMESPACE |
|
54 |
|
55 /* |
|
56 * QLatin1Constant |
|
57 * |
|
58 * The idea of the QLatin1Constant is to provide a POD-esque container |
|
59 * for constant strings which are defined in various places |
|
60 * (e.g., detail leaf class definition names, field keys, constant field values, etc). |
|
61 * We would ideally like these to be stored in the .rodata section to allow |
|
62 * sharing / minimise footprint. |
|
63 * |
|
64 * Given that the declare/define macros are const anyway, we changed the |
|
65 * member to a char array from a const char array, in order to squash |
|
66 * the compiler warning regarding uninitialised const value without |
|
67 * initialiser list in default ctor (POD requires default ctor). |
|
68 */ |
|
69 |
|
70 template <int N> struct QLatin1Constant |
|
71 { |
|
72 char chars[N]; |
|
73 |
|
74 bool operator ==(const QLatin1Constant& other) const {return (chars == other.chars) || (qstrcmp(chars, other.chars) == 0);} |
|
75 bool operator !=(const QLatin1Constant& other) const {return !operator==(other);} |
|
76 |
|
77 inline const char * latin1() const {return chars;} |
|
78 |
|
79 operator QLatin1String() const {return QLatin1String(chars);} |
|
80 operator QString() const {return QString::fromLatin1(chars, N-1);} |
|
81 operator QVariant() const {return QVariant(operator QString());} |
|
82 }; |
|
83 |
|
84 /* Hash - this comes from qhash.cpp >.> */ |
|
85 template<int N> uint qHash(const QLatin1Constant<N>& a) |
|
86 { |
|
87 uint h = 0; |
|
88 uint g; |
|
89 int n = N - 1; |
|
90 const register uchar*p = (const uchar*)a.chars; |
|
91 |
|
92 while (n--) { |
|
93 h = (h << 4) + *p++; |
|
94 if ((g = (h & 0xf0000000)) != 0) |
|
95 h ^= g >> 23; |
|
96 h &= ~g; |
|
97 } |
|
98 return h; |
|
99 } |
|
100 |
|
101 /* Operators for QLatin1Constant */ |
|
102 template<int N, int M> bool operator==(const QLatin1Constant<N>&, const QLatin1Constant<M>&) |
|
103 { |
|
104 // For N != M, this is always false |
|
105 // For N == M, the member function gets called |
|
106 return false; |
|
107 } |
|
108 template<int N, int M> bool operator!=(const QLatin1Constant<N>&, const QLatin1Constant<M>&) |
|
109 { |
|
110 // If N != M, this is always true |
|
111 // For N == M, the member function again gets called |
|
112 return true; |
|
113 } |
|
114 |
|
115 template<int N, int M> bool operator <(const QLatin1Constant<N>& a, const QLatin1Constant<M>& b) |
|
116 { |
|
117 return qstrcmp(a.chars, b.chars) < 0; |
|
118 } |
|
119 |
|
120 /* Operators for QLatin1String */ |
|
121 template<int N> bool operator==(const QLatin1Constant<N>& a, const QLatin1String& b) |
|
122 { |
|
123 return (a.chars == b.latin1()) || (qstrcmp(a.chars, b.latin1()) == 0); |
|
124 } |
|
125 |
|
126 template<int N> bool operator==(const QLatin1String& b, const QLatin1Constant<N>& a) |
|
127 { |
|
128 return (a.chars == b.latin1()) || (qstrcmp(a.chars, b.latin1()) == 0); |
|
129 } |
|
130 |
|
131 template<int N> bool operator!=(const QLatin1Constant<N>& a, const QLatin1String& b) |
|
132 { |
|
133 return (a.chars != b.latin1()) && (qstrcmp(a.chars, b.latin1()) != 0); |
|
134 } |
|
135 |
|
136 template<int N> bool operator!=(const QLatin1String& b, const QLatin1Constant<N>& a) |
|
137 { |
|
138 return (a.chars != b.latin1()) && (qstrcmp(a.chars, b.latin1()) != 0); |
|
139 } |
|
140 |
|
141 /* Operators for QString */ |
|
142 template<int N> bool operator==(const QLatin1Constant<N>& a, const QString& b) |
|
143 { |
|
144 return b == QLatin1String(a.chars); |
|
145 } |
|
146 |
|
147 template<int N> bool operator==(const QString& b, const QLatin1Constant<N>& a) |
|
148 { |
|
149 return b == QLatin1String(a.chars); |
|
150 } |
|
151 |
|
152 template<int N> bool operator!=(const QLatin1Constant<N>& a, const QString& b) |
|
153 { |
|
154 return b != QLatin1String(a.chars); |
|
155 } |
|
156 |
|
157 template<int N> bool operator!=(const QString& b, const QLatin1Constant<N>& a) |
|
158 { |
|
159 return b != QLatin1String(a.chars); |
|
160 } |
|
161 |
|
162 #define Q_DECLARE_LATIN1_CONSTANT(varname, str) static const QLatin1Constant<sizeof(str)> varname |
|
163 #define Q_DEFINE_LATIN1_CONSTANT(varname, str) const QLatin1Constant<sizeof(str)> varname = {str} |
|
164 |
|
165 /* XXX - deprecation stuff */ |
|
166 #define Q_DECLARE_LATIN1_LITERAL(v, s) Q_DECLARE_LATIN1_CONSTANT(v, s) |
|
167 #define Q_DEFINE_LATIN1_LITERAL(v, s) Q_DEFINE_LATIN1_CONSTANT(v, s) |
|
168 template <int N> struct Latin1Literal : public QLatin1Constant<N> |
|
169 { }; |
|
170 |
|
171 QTM_END_NAMESPACE |
|
172 |
|
173 // Not needed since this is a typedef, and qglobal already does this for the base type |
|
174 // Q_DECLARE_TYPEINFO(QTM_PREPEND_NAMESPACE(QContactLocalId), Q_PRIMITIVE_TYPE); |
|
175 |
|
176 #endif |