aboutsummaryrefslogtreecommitdiff
path: root/src/unstable/uuid.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/unstable/uuid.cpp')
-rw-r--r--src/unstable/uuid.cpp58
1 files changed, 37 insertions, 21 deletions
diff --git a/src/unstable/uuid.cpp b/src/unstable/uuid.cpp
index 41a35c2..0257270 100644
--- a/src/unstable/uuid.cpp
+++ b/src/unstable/uuid.cpp
@@ -80,33 +80,43 @@ void Bu::Uuid::clear()
80 data[7] = msb(0); 80 data[7] = msb(0);
81} 81}
82 82
83Bu::Uuid Bu::Uuid::gen() 83Bu::Uuid Bu::Uuid::generate( Bu::Uuid::Type eType )
84{ 84{
85 switch( eType )
86 {
87 case Version1:
88 case Version2:
89 case Version3:
90 case Version4:
91 case Version5:
92 default:
93 case System:
85#if defined(linux) 94#if defined(linux)
86 Bu::File fIn( "/proc/sys/kernel/random/uuid", Bu::File::Read ); 95 Bu::File fIn( "/proc/sys/kernel/random/uuid", Bu::File::Read );
87 char dat[36]; 96 char dat[36];
88 fIn.read( dat, 36 ); 97 fIn.read( dat, 36 );
89 Uuid id; 98 Uuid id;
90 id.set( dat ); 99 id.set( dat );
91 return id; 100 return id;
92#elif defined(WIN32) 101#elif defined(WIN32)
93 UUID uuid; 102 UUID uuid;
94 UuidCreate( &uuid ); 103 UuidCreate( &uuid );
95 Uuid id; 104 Uuid id;
96 id.data[0] = ((unsigned char *)&uuid.Data1)[3]; 105 id.data[0] = ((unsigned char *)&uuid.Data1)[3];
97 id.data[1] = ((unsigned char *)&uuid.Data1)[2]; 106 id.data[1] = ((unsigned char *)&uuid.Data1)[2];
98 id.data[2] = ((unsigned char *)&uuid.Data1)[1]; 107 id.data[2] = ((unsigned char *)&uuid.Data1)[1];
99 id.data[3] = ((unsigned char *)&uuid.Data1)[0]; 108 id.data[3] = ((unsigned char *)&uuid.Data1)[0];
100 id.data[4] = ((unsigned char *)&uuid.Data2)[1]; 109 id.data[4] = ((unsigned char *)&uuid.Data2)[1];
101 id.data[5] = ((unsigned char *)&uuid.Data2)[0]; 110 id.data[5] = ((unsigned char *)&uuid.Data2)[0];
102 id.data[6] = ((unsigned char *)&uuid.Data3)[1]; 111 id.data[6] = ((unsigned char *)&uuid.Data3)[1];
103 id.data[7] = ((unsigned char *)&uuid.Data3)[0]; 112 id.data[7] = ((unsigned char *)&uuid.Data3)[0];
104 memcpy( id.data+8, uuid.Data4, 8 ); 113 memcpy( id.data+8, uuid.Data4, 8 );
105 114
106 return id; 115 return id;
107#else 116#else
108# error We should be using one of the other fallbacks, but your platform is not supported yet. Sorry. 117# error We should be using one of the other fallbacks, but your platform is not supported yet. Sorry.
109#endif 118#endif
119 }
110} 120}
111 121
112void Bu::Uuid::set( const Bu::String &sSrc ) 122void Bu::Uuid::set( const Bu::String &sSrc )
@@ -129,6 +139,12 @@ bool Bu::Uuid::operator==( const Uuid &rhs ) const
129 return memcmp( data, rhs.data, 16 ) == 0; 139 return memcmp( data, rhs.data, 16 ) == 0;
130} 140}
131 141
142Bu::Uuid &Bu::Uuid::operator=( const Uuid &rhs )
143{
144 memcpy( data, rhs.data, 16 );
145 return *this;
146}
147
132template<> uint32_t Bu::__calcHashCode<Bu::Uuid>( const Bu::Uuid &k ) 148template<> uint32_t Bu::__calcHashCode<Bu::Uuid>( const Bu::Uuid &k )
133{ 149{
134 return __calcHashCode<String>( k.toRawString() ); 150 return __calcHashCode<String>( k.toRawString() );