diff options
author | Mike Buland <eichlan@xagasoft.com> | 2012-06-26 14:34:55 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2012-06-26 14:34:55 +0000 |
commit | 87fa2298eb73bf6213ec836937c236df25e2a4a7 (patch) | |
tree | 70cc1ea04267e4c8a1690c1c7a5ccbaf16a7c688 /src/unstable/uuid.cpp | |
parent | e231a34727bcba53ac093fc8f3e4062322fb7fc4 (diff) | |
download | libbu++-87fa2298eb73bf6213ec836937c236df25e2a4a7.tar.gz libbu++-87fa2298eb73bf6213ec836937c236df25e2a4a7.tar.bz2 libbu++-87fa2298eb73bf6213ec836937c236df25e2a4a7.tar.xz libbu++-87fa2298eb73bf6213ec836937c236df25e2a4a7.zip |
Changed the Bu::Uuid generate interface. It's now one function that takes a
type parameter. I think it's much nicer overall, the old gen function is
stil there for now, but marked deprecated.
Diffstat (limited to 'src/unstable/uuid.cpp')
-rw-r--r-- | src/unstable/uuid.cpp | 58 |
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 | ||
83 | Bu::Uuid Bu::Uuid::gen() | 83 | Bu::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 | ||
112 | void Bu::Uuid::set( const Bu::String &sSrc ) | 122 | void 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 | ||
142 | Bu::Uuid &Bu::Uuid::operator=( const Uuid &rhs ) | ||
143 | { | ||
144 | memcpy( data, rhs.data, 16 ); | ||
145 | return *this; | ||
146 | } | ||
147 | |||
132 | template<> uint32_t Bu::__calcHashCode<Bu::Uuid>( const Bu::Uuid &k ) | 148 | template<> uint32_t Bu::__calcHashCode<Bu::Uuid>( const Bu::Uuid &k ) |
133 | { | 149 | { |
134 | return __calcHashCode<String>( k.toRawString() ); | 150 | return __calcHashCode<String>( k.toRawString() ); |