00001 // @(#)root/base:$Id: TUUID.h 27658 2009-02-28 05:34:57Z pcanal $ 00002 // Author: Fons Rademakers 30/9/2001 00003 00004 /************************************************************************* 00005 * Copyright (C) 1995-2001, Rene Brun and Fons Rademakers. * 00006 * All rights reserved. * 00007 * * 00008 * For the licensing terms see $ROOTSYS/LICENSE. * 00009 * For the list of contributors see $ROOTSYS/README/CREDITS. * 00010 *************************************************************************/ 00011 00012 #ifndef ROOT_TUUID 00013 #define ROOT_TUUID 00014 00015 ////////////////////////////////////////////////////////////////////////// 00016 // // 00017 // TUUID // 00018 // // 00019 // This class defines a UUID (Universally Unique IDentifier), also // 00020 // known as GUIDs (Globally Unique IDentifier). A UUID is 128 bits // 00021 // long, and if generated according to this algorithm, is either // 00022 // guaranteed to be different from all other UUIDs/GUIDs generated // 00023 // until 3400 A.D. or extremely likely to be different. UUIDs were // 00024 // originally used in the Network Computing System (NCS) and // 00025 // later in the Open Software Foundation's (OSF) Distributed Computing // 00026 // Environment (DCE). // 00027 // // 00028 ////////////////////////////////////////////////////////////////////////// 00029 00030 #ifdef WIN32 00031 #undef GetCurrentTime 00032 #endif 00033 #ifndef ROOT_Rtypes 00034 #include "Rtypes.h" 00035 #endif 00036 00037 // forward declaration 00038 class TBuffer; 00039 class TFile; 00040 class TDirectory; 00041 class TInetAddress; 00042 class TDatime; 00043 00044 class TUUID { 00045 00046 protected: 00047 UInt_t fUUIDIndex; //!index in the list of UUIDs in TProcessUUID 00048 UInt_t fTimeLow; // 60 bit time, lower 32 bits 00049 UShort_t fTimeMid; // middle 16 time bits 00050 UShort_t fTimeHiAndVersion; // high 12 time bits + 4 UUID version bits 00051 UChar_t fClockSeqHiAndReserved; // high 6 clock bits + 2 bits reserved 00052 UChar_t fClockSeqLow; // low 8 clock bits 00053 UChar_t fNode[6]; // 6 node id bytes 00054 00055 struct uuid_time_t { 00056 UInt_t high; 00057 UInt_t low; 00058 }; 00059 00060 Int_t CmpTime(uuid_time_t *t1, uuid_time_t *t2); 00061 void Format(UShort_t clockseq, uuid_time_t ts); 00062 void GetNodeIdentifier(); 00063 void GetCurrentTime(uuid_time_t *timestamp); 00064 void GetSystemTime(uuid_time_t *timestamp); 00065 void GetRandomInfo(UChar_t seed[16]); 00066 void SetFromString(const char *uuid_str); 00067 00068 public: 00069 TUUID(); 00070 TUUID(const char *uuid_str); 00071 virtual ~TUUID(); 00072 00073 const char *AsString() const; 00074 Int_t Compare(const TUUID &u) const; 00075 UShort_t Hash() const; 00076 void Print() const; 00077 TInetAddress GetHostAddress() const; 00078 TDatime GetTime() const; 00079 void GetUUID(UChar_t uuid[16]) const; 00080 void SetUUID(const char *uuid_str); 00081 UInt_t GetUUIDNumber() const { return fUUIDIndex; } 00082 void SetUUIDNumber(UInt_t index) { fUUIDIndex = index; } 00083 00084 void StreamerV1(TBuffer &b); 00085 void FillBuffer(char *&buffer); 00086 void ReadBuffer(char *&buffer); 00087 Int_t Sizeof() const { return 18; } 00088 00089 ClassDef(TUUID,1) // Universally Unique IDentifier 00090 }; 00091 00092 00093 inline TBuffer &operator>>(TBuffer &buf, TUUID &uuid) 00094 { uuid.Streamer(buf); return buf; } 00095 00096 // Not inlined in order to avoid const casted away warning in user code. 00097 TBuffer &operator<<(TBuffer &buf, const TUUID &uuid); 00098 00099 inline Bool_t operator==(const TUUID &u1, const TUUID &u2) 00100 { return (!u1.Compare(u2)) ? kTRUE : kFALSE; } 00101 00102 inline Bool_t operator!=(const TUUID &u1, const TUUID &u2) 00103 { return !(u1 == u2); } 00104 00105 00106 #endif