- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files
- Directories
- Examples

- File List
- File Members

# quuid.h

Go to the documentation of this file.

    00001 /****************************************************************************
    00002 **
    00003 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
    00004 ** All rights reserved.
    00005 ** Contact: Nokia Corporation (qt-info@nokia.com)
    00006 **
    00007 ** This file is part of the QtCore module of the Qt Toolkit.
    00008 **
    00009 ** $QT_BEGIN_LICENSE:LGPL$
    00010 ** Commercial Usage
    00011 ** Licensees holding valid Qt Commercial licenses may use this file in
    00012 ** accordance with the Qt Commercial License Agreement provided with the
    00013 ** Software or, alternatively, in accordance with the terms contained in
    00014 ** a written agreement between you and Nokia.
    00015 **
    00016 ** GNU Lesser General Public License Usage
    00017 ** Alternatively, this file may be used under the terms of the GNU Lesser
    00018 ** General Public License version 2.1 as published by the Free Software
    00019 ** Foundation and appearing in the file LICENSE.LGPL included in the
    00020 ** packaging of this file.  Please review the following information to
    00021 ** ensure the GNU Lesser General Public License version 2.1 requirements
    00022 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    00023 **
    00024 ** In addition, as a special exception, Nokia gives you certain additional
    00025 ** rights.  These rights are described in the Nokia Qt LGPL Exception
    00026 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this module.
    00027 **
    00028 ** GNU General Public License Usage
    00029 ** Alternatively, this file may be used under the terms of the GNU
    00030 ** General Public License version 3.0 as published by the Free Software
    00031 ** Foundation and appearing in the file LICENSE.GPL included in the
    00032 ** packaging of this file.  Please review the following information to
    00033 ** ensure the GNU General Public License version 3.0 requirements will be
    00034 ** met: http://www.gnu.org/copyleft/gpl.html.
    00035 **
    00036 ** If you have questions regarding the use of this file, please contact
    00037 ** Nokia at qt-info@nokia.com.
    00038 ** $QT_END_LICENSE$
    00039 **
    00040 ****************************************************************************/
    00041
    00042 #ifndef QUUID_H
    00043 #define QUUID_H
    00044
    00045 #include <QtCore/qstring.h>
    00046
    00047 QT_BEGIN_HEADER
    00048
    00049 #if defined(Q_OS_WIN)
    00050 #ifndef GUID_DEFINED
    00051 #define GUID_DEFINED
    00052 typedef struct _GUID
    00053 {
    00054     ulong   Data1;
    00055     ushort  Data2;
    00056     ushort  Data3;
    00057     uchar   Data4[8];
    00058 } GUID, *REFGUID, *LPGUID;
    00059 #endif
    00060 #endif
    00061
    00062
    00063 QT_BEGIN_NAMESPACE
    00064
    00065 QT_MODULE(Core)
    00066
    00067 struct Q_CORE_EXPORT QUuid
    00068 {
    00069     enum Variant {
    00070         VarUnknown        =-1,
    00071         NCS                = 0, // 0 - -
    00072         DCE                = 2, // 1 0 -
    00073         Microsoft        = 6, // 1 1 0
    00074         Reserved        = 7  // 1 1 1
    00075     };
    00076
    00077     enum Version {
    00078         VerUnknown        =-1,
    00079         Time                = 1, // 0 0 0 1
    00080         EmbeddedPOSIX        = 2, // 0 0 1 0
    00081         Name                = 3, // 0 0 1 1
    00082         Random                = 4  // 0 1 0 0
    00083     };
    00084
    00085     QUuid()
    00086     {
    00087         data1 = 0;
    00088         data2 = 0;
    00089         data3 = 0;
    00090         for(int i = 0; i < 8; i++)
    00091             data4[i] = 0;
    00092     }
    00093     QUuid(uint l, ushort w1, ushort w2, uchar b1, uchar b2, uchar b3, uchar b4, uchar b5, uchar b6, uchar b7, uchar b8)
    00094     {
    00095         data1 = l;
    00096         data2 = w1;
    00097         data3 = w2;
    00098         data4[0] = b1;
    00099         data4[1] = b2;
    00100         data4[2] = b3;
    00101         data4[3] = b4;
    00102         data4[4] = b5;
    00103         data4[5] = b6;
    00104         data4[6] = b7;
    00105         data4[7] = b8;
    00106     }
    00107 #ifndef QT_NO_QUUID_STRING
    00108     QUuid(const QString &);
    00109     QUuid(const char *);
    00110     QString toString() const;
    00111     operator QString() const { return toString(); }
    00112 #endif
    00113     bool isNull() const;
    00114
    00115     bool operator==(const QUuid &orig) const
    00116     {
    00117         uint i;
    00118         if (data1 != orig.data1 || data2 != orig.data2 ||
    00119              data3 != orig.data3)
    00120             return false;
    00121
    00122         for(i = 0; i < 8; i++)
    00123             if (data4[i] != orig.data4[i])
    00124                 return false;
    00125
    00126         return true;
    00127     }
    00128
    00129     bool operator!=(const QUuid &orig) const
    00130     {
    00131         return !(*this == orig);
    00132     }
    00133
    00134     bool operator<(const QUuid &other) const;
    00135     bool operator>(const QUuid &other) const;
    00136
    00137 #if defined(Q_OS_WIN)
    00138     // On Windows we have a type GUID that is used by the platform API, so we
    00139     // provide convenience operators to cast from and to this type.
    00140     QUuid(const GUID &guid)
    00141     {
    00142         data1 = guid.Data1;
    00143         data2 = guid.Data2;
    00144         data3 = guid.Data3;
    00145         for(int i = 0; i < 8; i++)
    00146             data4[i] = guid.Data4[i];
    00147     }
    00148
    00149     QUuid &operator=(const GUID &guid)
    00150     {
    00151         *this = QUuid(guid);
    00152         return *this;
    00153     }
    00154
    00155     operator GUID() const
    00156     {
    00157         GUID guid = { data1, data2, data3, { data4[0], data4[1], data4[2], data4[3], data4[4], data4[5], data4[6], data4[7] } };
    00158         return guid;
    00159     }
    00160
    00161     bool operator==(const GUID &guid) const
    00162     {
    00163         return *this == QUuid(guid);
    00164     }
    00165
    00166     bool operator!=(const GUID &guid) const
    00167     {
    00168         return !(*this == guid);
    00169     }
    00170 #endif
    00171     static QUuid createUuid();
    00172     QUuid::Variant variant() const;
    00173     QUuid::Version version() const;
    00174
    00175     uint    data1;
    00176     ushort  data2;
    00177     ushort  data3;
    00178     uchar   data4[8];
    00179 };
    00180
    00181 #ifndef QT_NO_DATASTREAM
    00182 Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QUuid &);
    00183 Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QUuid &);
    00184 #endif
    00185
    00186 QT_END_NAMESPACE
    00187
    00188 QT_END_HEADER
    00189
    00190 #endif // QUUID_H