Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

quuid.cpp

Go to the documentation of this file.
00001 /**********************************************************************
00002 ** Copyright (C) 2000-2002 Trolltech AS.  All rights reserved.
00003 **
00004 ** This file is part of the Qtopia Environment.
00005 **
00006 ** This file may be distributed and/or modified under the terms of the
00007 ** GNU General Public License version 2 as published by the Free Software
00008 ** Foundation and appearing in the file LICENSE.GPL included in the
00009 ** packaging of this file.
00010 **
00011 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00012 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00013 **
00014 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
00015 **
00016 ** Contact info@trolltech.com if any conditions of this licensing are
00017 ** not clear to you.
00018 **
00019 **********************************************************************/
00020 
00021 #include "quuid.h"
00022 
00055 #ifndef QT_NO_QUUID_STRING
00056 
00062 QUuid::QUuid( const QString &text )
00063 {
00064     bool ok;
00065     QString temp = text.upper();
00066 
00067     data1 = temp.mid( 1, 8 ).toULong( &ok, 16 );
00068     if ( !ok )
00069     {
00070         *this = QUuid();
00071         return;
00072     }
00073 
00074     data2 = temp.mid( 10, 4 ).toUInt( &ok, 16 );
00075     if ( !ok )
00076     {
00077         *this = QUuid();
00078         return;
00079     }
00080     data3 = temp.mid( 15, 4 ).toUInt( &ok, 16 );
00081     if ( !ok )
00082     {
00083         *this = QUuid();
00084         return;
00085     }
00086     data4[0] = temp.mid( 20, 2 ).toUInt( &ok, 16 );
00087     if ( !ok )
00088     {
00089         *this = QUuid();
00090         return;
00091     }
00092     data4[1] = temp.mid( 22, 2 ).toUInt( &ok, 16 );
00093     if ( !ok )
00094     {
00095         *this = QUuid();
00096         return;
00097     }
00098     for ( int i = 2; i<8; i++ )
00099     {
00100         data4[i] = temp.mid( 25 + (i-2)*2, 2 ).toUShort( &ok, 16 );
00101         if ( !ok )
00102         {
00103             *this = QUuid();
00104             return;
00105         }
00106     }
00107 }
00108 
00132 QString QUuid::toString() const
00133 {
00134     QString result;
00135 
00136     result = "{" + QString::number( data1, 16 ).rightJustify( 8, '0' ) + "-";
00137     result += QString::number( (int)data2, 16 ).rightJustify( 4, '0' ) + "-";
00138     result += QString::number( (int)data3, 16 ).rightJustify( 4, '0' ) + "-";
00139     result += QString::number( (int)data4[0], 16 ).rightJustify( 2, '0' );
00140     result += QString::number( (int)data4[1], 16 ).rightJustify( 2, '0' ) + "-";
00141     for ( int i = 2; i < 8; i++ )
00142         result += QString::number( (int)data4[i], 16 ).rightJustify( 2, '0' );
00143 
00144     return result + "}";
00145 }
00146 #endif
00147 
00151 bool QUuid::isNull() const
00152 {
00153     return data4[0] == 0 && data4[1] == 0 && data4[2] == 0 && data4[3] == 0 &&
00154            data4[4] == 0 && data4[5] == 0 && data4[6] == 0 && data4[7] == 0 &&
00155            data1 == 0 && data2 == 0 && data3 == 0;
00156 }
00157 
00158 
00167 QUuid::Variant QUuid::variant() const
00168 {
00169     if ( isNull() )
00170         return VarUnknown;
00171     // Check the 3 MSB of data4[0]
00172     if ( (data4[0] & 0x80) == 0x00 ) return NCS;
00173     else if ( (data4[0] & 0xC0) == 0x80 ) return DCE;
00174     else if ( (data4[0] & 0xE0) == 0xC0 ) return Microsoft;
00175     else if ( (data4[0] & 0xE0) == 0xE0 ) return Reserved;
00176     return VarUnknown;
00177 }
00178 
00188 #define ISLESS(f1, f2) if (f1!=f2) return (f1<f2);
00189 bool QUuid::operator<(const QUuid &other ) const
00190 {
00191     if ( variant() != other.variant() )
00192         return FALSE;
00193 
00194     ISLESS( data1, other.data1 );
00195     ISLESS( data2, other.data2 );
00196     ISLESS( data3, other.data3 );
00197     for ( int n = 0; n < 8; n++ )
00198     {
00199         ISLESS( data4[n], other.data4[n] );
00200     }
00201     return FALSE;
00202 }
00203 
00213 #define ISMORE(f1, f2) if (f1!=f2) return (f1>f2);
00214 bool QUuid::operator>(const QUuid &other ) const
00215 {
00216     if ( variant() != other.variant() )
00217         return FALSE;
00218 
00219     ISMORE( data1, other.data1 );
00220     ISMORE( data2, other.data2 );
00221     ISMORE( data3, other.data3 );
00222     for ( int n = 0; n < 8; n++ )
00223     {
00224         ISMORE( data4[n], other.data4[n] );
00225     }
00226     return FALSE;
00227 }

Generated on Sat Nov 5 16:16:41 2005 for OPIE by  doxygen 1.4.2