--- a/qtmobility/src/contacts/qtcontactsglobal.h Fri Apr 16 15:51:22 2010 +0300
+++ b/qtmobility/src/contacts/qtcontactsglobal.h Mon May 03 13:18:40 2010 +0300
@@ -44,19 +44,18 @@
#include <qmobilityglobal.h>
#include <QString>
+#include <QVariant>
-#define QTCONTACTS_VERSION_NAME "com.nokia.qt.mobility.contacts.api.version"
-#define QTCONTACTS_IMPLEMENTATION_VERSION_NAME "com.nokia.qt.mobility.contacts.implementation.version"
-#define QTCONTACTS_VERSION 1
+#define QTCONTACTS_VERSION_NAME "com.nokia.qt.mobility.contacts.api.version"
+#define QTCONTACTS_IMPLEMENTATION_VERSION_NAME "com.nokia.qt.mobility.contacts.implementation.version"
+#define QTCONTACTS_VERSION 1
QTM_BEGIN_NAMESPACE
-typedef quint32 QContactLocalId; // XXX Put this else where
-
/*
- * Latin1Literal
+ * QLatin1Constant
*
- * The idea of the Latin1Literal is to provide a POD-esque container
+ * The idea of the QLatin1Constant is to provide a POD-esque container
* for constant strings which are defined in various places
* (e.g., detail leaf class definition names, field keys, constant field values, etc).
* We would ideally like these to be stored in the .rodata section to allow
@@ -66,64 +65,109 @@
* member to a char array from a const char array, in order to squash
* the compiler warning regarding uninitialised const value without
* initialiser list in default ctor (POD requires default ctor).
- * Does it work as hoped?
*/
-template <int N> struct Latin1Literal
+template <int N> struct QLatin1Constant
{
- //const char str[N]; // causes compiler warning due to uninitialized const value
- char str[N];
+ char chars[N];
+
+ bool operator ==(const QLatin1Constant& other) const {return (chars == other.chars) || (qstrcmp(chars, other.chars) == 0);}
+ bool operator !=(const QLatin1Constant& other) const {return !operator==(other);}
- operator QLatin1String() const {return QLatin1String(str);}
- operator QString() const {return QString::fromLatin1(str, N-1);}
+ inline const char * latin1() const {return chars;}
+
+ operator QLatin1String() const {return QLatin1String(chars);}
+ operator QString() const {return QString::fromLatin1(chars, N-1);}
+ operator QVariant() const {return QVariant(operator QString());}
};
-template<int N> bool operator==(const Latin1Literal<N>& a, const QLatin1String& b)
+/* Hash - this comes from qhash.cpp >.> */
+template<int N> uint qHash(const QLatin1Constant<N>& a)
{
- return QLatin1String(a.str) == b;
+ uint h = 0;
+ uint g;
+ int n = N - 1;
+ const register uchar*p = (const uchar*)a.chars;
+
+ while (n--) {
+ h = (h << 4) + *p++;
+ if ((g = (h & 0xf0000000)) != 0)
+ h ^= g >> 23;
+ h &= ~g;
+ }
+ return h;
}
-template<int N> bool operator==(const Latin1Literal<N>& a, const QString& b)
+/* Operators for QLatin1Constant */
+template<int N, int M> bool operator==(const QLatin1Constant<N>&, const QLatin1Constant<M>&)
{
- return b == QLatin1String(a.str);
+ // For N != M, this is always false
+ // For N == M, the member function gets called
+ return false;
}
-
-template<int N> bool operator==(const QLatin1String& b, const Latin1Literal<N>& a)
+template<int N, int M> bool operator!=(const QLatin1Constant<N>&, const QLatin1Constant<M>&)
{
- return QLatin1String(a.str) == b;
+ // If N != M, this is always true
+ // For N == M, the member function again gets called
+ return true;
}
-template<int N> bool operator==(const QString& b, const Latin1Literal<N>& a)
+template<int N, int M> bool operator <(const QLatin1Constant<N>& a, const QLatin1Constant<M>& b)
{
- return b == QLatin1String(a.str);
+ return qstrcmp(a.chars, b.chars) < 0;
}
-template<int N> bool operator!=(const Latin1Literal<N>& a, const QLatin1String& b)
+/* Operators for QLatin1String */
+template<int N> bool operator==(const QLatin1Constant<N>& a, const QLatin1String& b)
{
- return QLatin1String(a.str) != b;
+ return (a.chars == b.latin1()) || (qstrcmp(a.chars, b.latin1()) == 0);
+}
+
+template<int N> bool operator==(const QLatin1String& b, const QLatin1Constant<N>& a)
+{
+ return (a.chars == b.latin1()) || (qstrcmp(a.chars, b.latin1()) == 0);
+}
+
+template<int N> bool operator!=(const QLatin1Constant<N>& a, const QLatin1String& b)
+{
+ return (a.chars != b.latin1()) && (qstrcmp(a.chars, b.latin1()) != 0);
}
-template<int N> bool operator!=(const Latin1Literal<N>& a, const QString& b)
+template<int N> bool operator!=(const QLatin1String& b, const QLatin1Constant<N>& a)
{
- return b != QLatin1String(a.str);
+ return (a.chars != b.latin1()) && (qstrcmp(a.chars, b.latin1()) != 0);
+}
+
+/* Operators for QString */
+template<int N> bool operator==(const QLatin1Constant<N>& a, const QString& b)
+{
+ return b == QLatin1String(a.chars);
}
-template<int N> bool operator!=(const QLatin1String& b, const Latin1Literal<N>& a)
+template<int N> bool operator==(const QString& b, const QLatin1Constant<N>& a)
{
- return QLatin1String(a.str) != b;
+ return b == QLatin1String(a.chars);
}
-template<int N> bool operator!=(const QString& b, const Latin1Literal<N>& a)
+template<int N> bool operator!=(const QLatin1Constant<N>& a, const QString& b)
{
- return b != QLatin1String(a.str);
+ return b != QLatin1String(a.chars);
}
-#define Q_DECLARE_LATIN1_LITERAL(varname, str) static const Latin1Literal<sizeof(str)> varname
-#define Q_DEFINE_LATIN1_LITERAL(varname, str) const Latin1Literal<sizeof(str)> varname = {str}
+template<int N> bool operator!=(const QString& b, const QLatin1Constant<N>& a)
+{
+ return b != QLatin1String(a.chars);
+}
+
+#define Q_DECLARE_LATIN1_CONSTANT(varname, str) static const QLatin1Constant<sizeof(str)> varname
+#define Q_DEFINE_LATIN1_CONSTANT(varname, str) const QLatin1Constant<sizeof(str)> varname = {str}
QTM_END_NAMESPACE
// Not needed since this is a typedef, and qglobal already does this for the base type
// Q_DECLARE_TYPEINFO(QTM_PREPEND_NAMESPACE(QContactLocalId), Q_PRIMITIVE_TYPE);
+// Workaround for unannounced SC break
+#include "qcontactid.h"
+
#endif