00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
#ifndef VTK_UUID_H_
00017
# define VTK_UUID_H_
00018
# include "vtkExtensionsCommonConfigure.h"
00019
# include "vtkExtensionsTypes.h"
00020
# include <assert.h>
00021
00022
# include "vtkObject.h"
00023
00026 # define VTK_UUID_VARIANT_UNKNOWN -1
00027 # define VTK_UUID_VARIANT_NCS 0
00028 # define VTK_UUID_VARIANT_DCE 2
00029 # define VTK_UUID_VARIANT_MICROSOFT 6
00030 # define VTK_UUID_VARIANT_RESERVED 7
00032
00033
00035 # define VTK_UUID_VERSION_UNKNOWN -1
00036 # define VTK_UUID_VERSION_TIME 1
00037 # define VTK_UUID_VERSION_EMBEDDED_POSIX 2
00038 # define VTK_UUID_VERSION_NAME 3
00039 # define VTK_UUID_VERSION_RANDOM 4
00041
00042
00043
struct timeval;
00044
00045
VTK_EXTENSIONS_NAMESPACE_BEGIN
00046
00047
class vtkUUIDGenerator;
00048
00300 class VTK_EXTENSIONS_COMMON_EXPORT vtkUUID :
public vtkObject
00301 {
00302
public:
00303
static vtkUUID*
New (
void);
00304 vtkTypeRevisionMacro (vtkUUID,
vtkObject);
00305
void PrintSelf (ostream&,
vtkIndent);
00306
00307
00308 struct Structure
00309 {
00311 vtkUint32Type mTimeLow;
00313 vtkUint16Type mTimeMid;
00315 vtkUint16Type mTimeHigh;
00317 vtkUint8Type mClockSeqHigh;
00319 vtkUint8Type mClockSeqLow;
00321 vtkUint8Type mNode[6];
00322
00323
void Clear (
void);
00324
void Copy (
Structure const& a);
00325
void Copy (
const char*
const& a);
00326
void Copy (
const unsigned char a[16]);
00327
int GetString (
char buffer[37])
const;
00328
int GetBinary (
unsigned char buffer[16])
const;
00329
int IsNull (
void) const;
00330 time_t GetTime (struct timeval* & a) const;
00331
int GetVariant (
void) const;
00332
int GetVersion (
void) const;
00333
int Compare (
Structure const& a) const;
00334
void Swap (
Structure & a);
00335
00336 Structure (
void) { this->Clear(); }
00337 Structure (
Structure const& a) { this->Copy(a); }
00338 Structure (
const char*
const& a) { this->Copy(a); }
00339 Structure (
const unsigned char a[16]) { this->Copy(a); }
00340 };
00341
00342
00343
00346 static const vtkUint32Type TimeOffsetLow = VTK_EXTENSIONS_UINT32(0x13814000);
00347 static const vtkUint32Type TimeOffsetHigh= VTK_EXTENSIONS_UINT32(0x01B21DD2);
00349
00350
00352
void Clear (
void);
00353
00358
void Copy (
const vtkUUID* a);
00359
00364
void Copy (
const char* a);
00365
00370
void Copy (
const unsigned char a[16]);
00371
00372
00377
int GetString (
char buffer[37])
const;
00378
00379
00385
const char* GetString (
void) const;
00386
00387
00392
int GetBinary (
unsigned char buffer[16]) const;
00393
00394
00400 const
unsigned char* GetBinary (
void) const;
00401
00403
int IsNull (
void) const;
00404
00405
00408 Structure & GetData (
void) {
return this->Data; }
00409 const Structure & GetData (
void)
const {
return this->Data; }
00413 time_t GetTime (
struct timeval* a)
const;
00414
00415
00417
long GetTime (
void) const;
00418
00420
int GetVariant (
void) const;
00421
00423
int GetVersion (
void) const;
00424
00426 static const
char* GetVariantString (
int variant);
00427
00429 static const
char* GetVersionString (
int version);
00430
00439
int Compare (const vtkUUID* a) const;
00440
int Compare (const
char* a) const;
00441
int Compare (const
unsigned char a[16]) const;
00445
void Swap (vtkUUID* object);
00446
00447 protected:
00448 vtkUUID (
void);
00449 ~vtkUUID();
00450
00451
00453 vtkUUID (const vtkUUID* a) { this->Copy(a); }
00454
00456 vtkUUID (
const char* a) { this->Copy(a); }
00457
00459 vtkUUID (
const unsigned char a[16]) { this->Copy(a); }
00460
00461
friend class vtkUUIDGenerator;
00462
00463
00464
private:
00465
00466
static vtkUUIDGenerator* Generator;
00467
00468 Structure Data;
00469
00470
00471
protected:
00472
00475
static void ClassInitialize (
void);
00476
static void ClassFinalize (
void);
00478
00479
00480
public:
00481
00487
class Init;
00488
friend class Init;
00489 class Init
00490 {
00491
friend class vtkUUID;
00492
public:
00493
Init (
void);
00494 ~
Init();
00495
private:
00496
static long TranslationUnits;
00497 };
00499
00500
00501
private:
00507 vtkUUID (
const vtkUUID&);
00508
void operator= (
const vtkUUID&);
00510 };
00511
00512
00513
inline void
00514 vtkUUID::Structure::Clear (
void)
00515 {
00516 vtkUint32Type* ptr = static_cast<vtkUint32Type*>(&(this->
mTimeLow));
00517
00518
for (
int i=0; i<4; i++) *ptr++ = VTK_EXTENSIONS_UINT32(0);
00519 }
00520
00521
00522
inline void
00523 vtkUUID::Clear (
void)
00524 {
00525 this->Data.
Clear();
00526 }
00527
00528
00529
inline void
00530 vtkUUID::Structure::Copy (
vtkUUID::Structure const& a)
00531 {
00532
if (&a ==
this) {
return; }
00533
00534 this->
mTimeLow = a.
mTimeLow;
00535 this->
mTimeMid = a.
mTimeMid;
00536 this->
mTimeHigh = a.
mTimeHigh;
00537 this->
mClockSeqHigh = a.
mClockSeqHigh;
00538 this->
mClockSeqLow = a.
mClockSeqLow;
00539 this->
mNode[0] = a.
mNode[0];
00540 this->
mNode[1] = a.
mNode[1];
00541 this->
mNode[2] = a.
mNode[2];
00542 this->
mNode[3] = a.
mNode[3];
00543 this->
mNode[4] = a.
mNode[4];
00544 this->
mNode[5] = a.
mNode[5];
00545 }
00546
00547
inline void
00548 vtkUUID::Structure::Copy (
const unsigned char aInput[16])
00549 {
00550 assert(aInput != NULL);
00551
00552
const unsigned char* ptr = aInput;
00553 vtkUint32Type tmp;
00554
00555 tmp = *ptr++;
00556 tmp = (tmp << 8) | *ptr++;
00557 tmp = (tmp << 8) | *ptr++;
00558 tmp = (tmp << 8) | *ptr++;
00559 this->
mTimeLow = tmp;
00560
00561 tmp = *ptr++;
00562 tmp = (tmp << 8) | *ptr++;
00563 this->
mTimeMid = tmp;
00564
00565 tmp = *ptr++;
00566 tmp = (tmp << 8) | *ptr++;
00567 this->
mTimeHigh = tmp;
00568
00569 this->
mClockSeqHigh = ptr[0];
00570 this->
mClockSeqLow = ptr[1];
00571
00572 this->
mNode[0] = ptr[2];
00573 this->
mNode[1] = ptr[3];
00574 this->
mNode[2] = ptr[4];
00575 this->
mNode[3] = ptr[5];
00576 this->
mNode[4] = ptr[6];
00577 this->
mNode[5] = ptr[7];
00578 }
00579
00580
00581
inline void
00582 vtkUUID::Copy (
const vtkUUID* a)
00583 {
00584
if (a == NULL) { this->
Clear();
return; }
00585 this->Data.
Copy(a->
GetData());
00586 }
00587
00588
inline void
00589 vtkUUID::Copy (
const unsigned char a[16])
00590 {
00591 this->Data.
Copy(a);
00592 }
00593
00594
00595
inline int
00596 vtkUUID::Structure::GetBinary (
unsigned char a[16])
const
00597
{
00598
if (a == NULL) {
return VTK_FALSE; }
00599
00600 a[0] = this->
mTimeLow >> 24;
00601 a[1] = this->mTimeLow >> 16;
00602 a[2] = this->mTimeLow >> 8;
00603 a[3] = this->mTimeLow;
00604
00605 a[4] = this->
mTimeMid >> 8;
00606 a[5] = this->mTimeMid;
00607
00608 a[6] = this->
mTimeHigh >> 8;
00609 a[7] = this->mTimeHigh;
00610
00611 a[8] = this->
mClockSeqHigh;
00612 a[9] = this->
mClockSeqLow;
00613
00614 a[10] = this->
mNode[0];
00615 a[11] = this->mNode[1];
00616 a[12] = this->mNode[2];
00617 a[13] = this->mNode[3];
00618 a[14] = this->mNode[4];
00619 a[15] = this->mNode[5];
00620
00621
return VTK_TRUE;
00622 }
00623
00624
00625
inline int
00626 vtkUUID::GetBinary (
unsigned char a[16])
const
00627
{
00628
return this->Data.
GetBinary(a);
00629 }
00630
00631
00632
inline int
00633 vtkUUID::Structure::IsNull (
void)
const
00634
{
00635
return ( this->
mTimeLow || this->
mTimeMid || this->
mTimeHigh ||
00636 this->
mClockSeqHigh || this->
mClockSeqLow ||
00637 this->
mNode[0] || this->
mNode[1] || this->
mNode[2] ||
00638 this->
mNode[3] || this->
mNode[4] || this->
mNode[5]
00639 ?
VTK_FALSE :
VTK_TRUE );
00640 }
00641
00642
00643
inline int
00644 vtkUUID::IsNull (
void)
const
00645
{
00646
return this->Data.
IsNull();
00647 }
00648
00649
00650
inline int
00651 vtkUUID::Structure::GetVariant (
void)
const
00652
{
00653
if (!this->
IsNull())
00654 {
00655
if ((this->
mClockSeqHigh & 0x80) == 0x00)
00656
return VTK_UUID_VARIANT_NCS;
00657
else if ((this->
mClockSeqHigh & 0xC0) == 0x80)
00658
return VTK_UUID_VARIANT_DCE;
00659
else if ((this->
mClockSeqHigh & 0xE0) == 0xC0)
00660
return VTK_UUID_VARIANT_MICROSOFT;
00661
else if ((this->
mClockSeqHigh & 0xE0) == 0xE0)
00662
return VTK_UUID_VARIANT_RESERVED;
00663 }
00664
00665
return VTK_UUID_VARIANT_UNKNOWN;
00666 }
00667
00668
inline int
00669 vtkUUID::Structure::GetVersion (
void)
const
00670
{
00671
00672
unsigned char version = (
unsigned char)(this->
mTimeHigh >> 12);
00673
00674
if ( this->
IsNull() ||
00675 this->
GetVariant() !=
VTK_UUID_VARIANT_DCE ||
00676 version <
VTK_UUID_VERSION_TIME ||
00677 version >
VTK_UUID_VERSION_RANDOM )
00678 {
00679
return VTK_UUID_VERSION_UNKNOWN;
00680 }
00681
00682
return version;
00683 }
00684
00685
00686
inline int
00687 vtkUUID::GetVariant (
void)
const
00688
{
00689
return this->Data.
GetVariant();
00690 }
00691
00692
inline int
00693 vtkUUID::GetVersion (
void)
const
00694
{
00695
return this->Data.
GetVersion();
00696 }
00697
00698
00699
inline const char*
00700 vtkUUID::GetVariantString (
int aVariant)
00701 {
00702
switch (aVariant)
00703 {
00704
case VTK_UUID_VARIANT_NCS:
00705
return "NCS";
00706
case VTK_UUID_VARIANT_DCE:
00707
return "DCE";
00708
case VTK_UUID_VARIANT_MICROSOFT:
00709
return "Microsoft";
00710
case VTK_UUID_VARIANT_RESERVED:
00711
return "Reserved";
00712 }
00713
00714
return "Unknown";
00715 }
00716
00717
inline const char*
00718 vtkUUID::GetVersionString (
int aVersion)
00719 {
00720
switch (aVersion)
00721 {
00722
case VTK_UUID_VERSION_TIME:
00723
return "Time";
00724
case VTK_UUID_VERSION_EMBEDDED_POSIX:
00725
return "EmbeddedPOSIX";
00726
case VTK_UUID_VERSION_NAME:
00727
return "Name";
00728
case VTK_UUID_VERSION_RANDOM:
00729
return "Random";
00730 }
00731
00732
return "Unknown";
00733 }
00734
00735
00736
inline int
00737 vtkUUID::Structure::Compare (
vtkUUID::Structure const& a)
const
00738
{
00739
if (&a !=
this)
00740 {
00741
if (this->
mTimeLow != a.
mTimeLow)
00742
return ((this->
mTimeLow < a.
mTimeLow) ? -1 : 1);
00743
else if (this->
mTimeMid != a.
mTimeMid)
00744
return ((this->
mTimeMid < a.
mTimeMid) ? -1 : 1);
00745
else if (this->
mTimeHigh != a.
mTimeHigh)
00746
return ((this->
mTimeHigh < a.
mTimeHigh) ? -1 : 1);
00747
else if (this->
mClockSeqHigh != a.
mClockSeqHigh)
00748
return ((this->
mClockSeqHigh<a.
mClockSeqHigh) ? -1 : 1);
00749
else if (this->
mClockSeqLow != a.
mClockSeqLow)
00750
return ((this->
mClockSeqLow < a.
mClockSeqLow) ? -1 : 1);
00751
else if (this->
mNode[0] != a.
mNode[0])
00752
return ((this->
mNode[0] < a.
mNode[0]) ? -1 : 1);
00753
else if (this->
mNode[1] != a.
mNode[1])
00754
return ((this->
mNode[1] < a.
mNode[1]) ? -1 : 1);
00755
else if (this->
mNode[2] != a.
mNode[2])
00756
return ((this->
mNode[2] < a.
mNode[2]) ? -1 : 1);
00757
else if (this->
mNode[3] != a.
mNode[3])
00758
return ((this->
mNode[3] < a.
mNode[3]) ? -1 : 1);
00759
else if (this->
mNode[4] != a.
mNode[4])
00760
return ((this->
mNode[4] < a.
mNode[4]) ? -1 : 1);
00761
else if (this->
mNode[5] != a.
mNode[5])
00762
return ((this->
mNode[5] < a.
mNode[5]) ? -1 : 1);
00763 }
00764
00765
return 0;
00766 }
00767
00768
00769
inline int
00770 vtkUUID::Compare (
const vtkUUID* aOther)
const
00771
{
00772 assert(aOther != NULL);
00773
return this->Data.
Compare(aOther->
GetData());
00774 }
00775
00776
inline int
00777 vtkUUID::Compare (
const char* aOther)
const
00778
{
00779
vtkUUID::Structure tmp(aOther);
00780
return this->Data.
Compare(tmp);
00781 }
00782
00783
inline int
00784 vtkUUID::Compare (
const unsigned char aOther[16])
const
00785
{
00786
vtkUUID::Structure tmp(aOther);
00787
return this->Data.
Compare(tmp);
00788 }
00789
00790
00791
inline void
00792 vtkUUID::Structure::Swap (
vtkUUID::Structure & a)
00793 {
00794
if (this->
Compare(a) != 0)
00795 {
00796
const vtkUint32Type timeLow = this->
mTimeLow;
00797
const vtkUint16Type timeMid = this->
mTimeMid;
00798
const vtkUint16Type timeHigh = this->
mTimeHigh;
00799
const vtkUint8Type clockSeqHigh = this->
mClockSeqHigh;
00800
const vtkUint8Type clockSeqLow = this->
mClockSeqLow;
00801
const vtkUint8Type node[6] = { this->
mNode[0], this->
mNode[1],
00802 this->mNode[2], this->mNode[3],
00803 this->mNode[4], this->mNode[5], };
00804
00805 this->mTimeLow = a.
mTimeLow;
00806 this->mTimeMid = a.
mTimeMid;
00807 this->mTimeHigh = a.
mTimeHigh;
00808 this->mClockSeqHigh = a.
mClockSeqHigh;
00809 this->mClockSeqLow = a.
mClockSeqLow;
00810 this->
mNode[0] = a.
mNode[0];
00811 this->
mNode[1] = a.
mNode[1];
00812 this->
mNode[2] = a.
mNode[2];
00813 this->
mNode[3] = a.
mNode[3];
00814 this->
mNode[4] = a.
mNode[4];
00815 this->
mNode[5] = a.
mNode[5];
00816
00817 a.
mTimeLow = timeLow;
00818 a.
mTimeMid = timeMid;
00819 a.
mTimeHigh = timeHigh;
00820 a.
mClockSeqHigh = clockSeqHigh;
00821 a.
mClockSeqLow = clockSeqLow;
00822 a.
mNode[0] = node[0];
00823 a.
mNode[1] = node[1];
00824 a.
mNode[2] = node[2];
00825 a.
mNode[3] = node[3];
00826 a.
mNode[4] = node[4];
00827 a.
mNode[5] = node[5];
00828 }
00829 }
00830
00831
00832
inline void
00833 vtkUUID::Swap (vtkUUID* object)
00834 {
00835 this->Data.
Swap(object->
GetData());
00836 }
00837
00838
00839
00840
00841
00846
inline vtkstd_bool
00847 operator== (
vtkUUID::Structure const& a1,
vtkUUID::Structure const& a2)
00848 {
return a1.
Compare(a2) == 0; }
00849
00854
inline vtkstd_bool
00855 operator< (
vtkUUID::Structure const& a1,
vtkUUID::Structure const& a2)
00856 {
return a1.
Compare(a2) == -1; }
00857
00859
inline vtkstd_bool
00860 operator!= (
vtkUUID::Structure const& a1,
vtkUUID::Structure const& a2)
00861 {
return !(a1 == a2); }
00862
00864
inline vtkstd_bool
00865 operator> (
vtkUUID::Structure const& a1,
vtkUUID::Structure const& a2)
00866 {
return a2 < a1; }
00867
00869
inline vtkstd_bool
00870 operator<= (
vtkUUID::Structure const& a1,
vtkUUID::Structure const& a2)
00871 {
return !(a2 < a1); }
00872
00874
inline vtkstd_bool
00875 operator>= (
vtkUUID::Structure const& a1,
vtkUUID::Structure const& a2)
00876 {
return !(a1 < a2); }
00877
00878
inline void
00879 Swap (
vtkUUID::Structure & a1,
vtkUUID::Structure & a2)
00880 { a1.
Swap(a2); }
00881
00882
00886 static vtkUUID::Init vtkUUIDInitInstance;
00887
00888
VTK_EXTENSIONS_NAMESPACE_END
00889
00890
#endif
00891
00892
00893
00894