// @(#)root/base:$Id$
// Author: Fons Rademakers   30/9/2001

/*************************************************************************
 * Copyright (C) 1995-2001, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#ifndef ROOT_TUUID
#define ROOT_TUUID

//////////////////////////////////////////////////////////////////////////
//                                                                      //
// TUUID                                                                //
//                                                                      //
// This class defines a UUID (Universally Unique IDentifier), also      //
// known as GUIDs (Globally Unique IDentifier). A UUID is 128 bits      //
// long, and if generated according to this algorithm, is either        //
// guaranteed to be different from all other UUIDs/GUIDs generated      //
// until 3400 A.D. or extremely likely to be different. UUIDs were      //
// originally used in the Network Computing System (NCS) and            //
// later in the Open Software Foundation's (OSF) Distributed Computing  //
// Environment (DCE).                                                   //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

#ifdef WIN32
#undef GetCurrentTime
#endif
#ifndef ROOT_Rtypes
#include "Rtypes.h"
#endif

// forward declaration
class TBuffer;
class TFile;
class TDirectory;
class TInetAddress;
class TDatime;

class TUUID {

protected:
   UInt_t    fUUIDIndex;             //!index in the list of UUIDs in TProcessUUID
   UInt_t    fTimeLow;               // 60 bit time, lower 32 bits
   UShort_t  fTimeMid;               // middle 16 time bits
   UShort_t  fTimeHiAndVersion;      // high 12 time bits + 4 UUID version bits
   UChar_t   fClockSeqHiAndReserved; // high 6 clock bits + 2 bits reserved
   UChar_t   fClockSeqLow;           // low 8 clock bits
   UChar_t   fNode[6];               // 6 node id bytes

   struct uuid_time_t {
      UInt_t high;
      UInt_t low;
   };

   Int_t CmpTime(uuid_time_t *t1, uuid_time_t *t2);
   void  Format(UShort_t clockseq, uuid_time_t ts);
   void  GetNodeIdentifier();
   void  GetCurrentTime(uuid_time_t *timestamp);
   void  GetSystemTime(uuid_time_t *timestamp);
   void  GetRandomInfo(UChar_t seed[16]);
   void  SetFromString(const char *uuid_str);

public:
   TUUID();
   TUUID(const char *uuid_str);
   virtual ~TUUID();

   const char  *AsString() const;
   Int_t        Compare(const TUUID &u) const;
   UShort_t     Hash() const;
   void         Print() const;
   TInetAddress GetHostAddress() const;
   TDatime      GetTime() const;
   void         GetUUID(UChar_t uuid[16]) const;
   void         SetUUID(const char *uuid_str);
   UInt_t       GetUUIDNumber() const { return fUUIDIndex; }
   void         SetUUIDNumber(UInt_t index) { fUUIDIndex = index; }

   void         StreamerV1(TBuffer &b);
   void         FillBuffer(char *&buffer);
   void         ReadBuffer(char *&buffer);
   Int_t        Sizeof() const { return 18; }

   ClassDef(TUUID,1)  // Universally Unique IDentifier
};


inline TBuffer &operator>>(TBuffer &buf, TUUID &uuid)
{ uuid.Streamer(buf); return buf; }

// Not inlined in order to avoid const casted away warning in user code.
TBuffer &operator<<(TBuffer &buf, const TUUID &uuid);

inline Bool_t operator==(const TUUID &u1, const TUUID &u2)
{ return (!u1.Compare(u2)) ? kTRUE : kFALSE; }

inline Bool_t operator!=(const TUUID &u1, const TUUID &u2)
{ return !(u1 == u2); }


#endif
 TUUID.h:1
 TUUID.h:2
 TUUID.h:3
 TUUID.h:4
 TUUID.h:5
 TUUID.h:6
 TUUID.h:7
 TUUID.h:8
 TUUID.h:9
 TUUID.h:10
 TUUID.h:11
 TUUID.h:12
 TUUID.h:13
 TUUID.h:14
 TUUID.h:15
 TUUID.h:16
 TUUID.h:17
 TUUID.h:18
 TUUID.h:19
 TUUID.h:20
 TUUID.h:21
 TUUID.h:22
 TUUID.h:23
 TUUID.h:24
 TUUID.h:25
 TUUID.h:26
 TUUID.h:27
 TUUID.h:28
 TUUID.h:29
 TUUID.h:30
 TUUID.h:31
 TUUID.h:32
 TUUID.h:33
 TUUID.h:34
 TUUID.h:35
 TUUID.h:36
 TUUID.h:37
 TUUID.h:38
 TUUID.h:39
 TUUID.h:40
 TUUID.h:41
 TUUID.h:42
 TUUID.h:43
 TUUID.h:44
 TUUID.h:45
 TUUID.h:46
 TUUID.h:47
 TUUID.h:48
 TUUID.h:49
 TUUID.h:50
 TUUID.h:51
 TUUID.h:52
 TUUID.h:53
 TUUID.h:54
 TUUID.h:55
 TUUID.h:56
 TUUID.h:57
 TUUID.h:58
 TUUID.h:59
 TUUID.h:60
 TUUID.h:61
 TUUID.h:62
 TUUID.h:63
 TUUID.h:64
 TUUID.h:65
 TUUID.h:66
 TUUID.h:67
 TUUID.h:68
 TUUID.h:69
 TUUID.h:70
 TUUID.h:71
 TUUID.h:72
 TUUID.h:73
 TUUID.h:74
 TUUID.h:75
 TUUID.h:76
 TUUID.h:77
 TUUID.h:78
 TUUID.h:79
 TUUID.h:80
 TUUID.h:81
 TUUID.h:82
 TUUID.h:83
 TUUID.h:84
 TUUID.h:85
 TUUID.h:86
 TUUID.h:87
 TUUID.h:88
 TUUID.h:89
 TUUID.h:90
 TUUID.h:91
 TUUID.h:92
 TUUID.h:93
 TUUID.h:94
 TUUID.h:95
 TUUID.h:96
 TUUID.h:97
 TUUID.h:98
 TUUID.h:99
 TUUID.h:100
 TUUID.h:101
 TUUID.h:102
 TUUID.h:103
 TUUID.h:104
 TUUID.h:105
 TUUID.h:106