aboutsummaryrefslogtreecommitdiff
path: root/src/unstable/uuid.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/unstable/uuid.cpp34
1 files changed, 20 insertions, 14 deletions
diff --git a/src/unstable/uuid.cpp b/src/unstable/uuid.cpp
index 6642d75..9708423 100644
--- a/src/unstable/uuid.cpp
+++ b/src/unstable/uuid.cpp
@@ -10,6 +10,8 @@
10#include "bu/formatter.h" 10#include "bu/formatter.h"
11#include "bu/membuf.h" 11#include "bu/membuf.h"
12#include "bu/random.h" 12#include "bu/random.h"
13#include "bu/archive.h"
14#include "bu/blobbuilder.h"
13#include <string.h> 15#include <string.h>
14 16
15#ifdef WIN32 17#ifdef WIN32
@@ -27,11 +29,11 @@ Bu::Uuid::Uuid( const Uuid &src )
27 memcpy( data, src.data, 16 ); 29 memcpy( data, src.data, 16 );
28} 30}
29 31
30Bu::Uuid::Uuid( const Bu::String &sSrc ) 32Bu::Uuid::Uuid( const Bu::Blob &sSrc )
31{ 33{
32 if( sSrc.getSize() == 16 ) 34 if( sSrc.getSize() == 16 )
33 { 35 {
34 memcpy( data, sSrc.getStr(), 16 ); 36 memcpy( data, sSrc.getData(), 16 );
35 } 37 }
36 else if( sSrc.getSize() == 36 ) 38 else if( sSrc.getSize() == 36 )
37 { 39 {
@@ -44,12 +46,12 @@ Bu::Uuid::~Uuid()
44{ 46{
45} 47}
46 48
47Bu::String Bu::Uuid::toRawString() const 49Bu::Blob Bu::Uuid::toRawBlob() const
48{ 50{
49 return Bu::String( (char *)data, 16 ); 51 return Bu::Blob( (char *)data, 16 );
50} 52}
51 53
52Bu::String Bu::Uuid::toString() const 54Bu::Blob Bu::Uuid::toBlob() const
53{ 55{
54 Bu::MemBuf mb; 56 Bu::MemBuf mb;
55 Bu::Formatter f( mb ); 57 Bu::Formatter f( mb );
@@ -61,12 +63,14 @@ Bu::String Bu::Uuid::toString() const
61 f << Bu::Fmt::hex(2).caps(false) << (unsigned int)data[j]; 63 f << Bu::Fmt::hex(2).caps(false) << (unsigned int)data[j];
62 } 64 }
63 65
64 return mb.getString(); 66 return mb.getBlob();
65} 67}
66 68
67Bu::String Bu::Uuid::toUrn() const 69Bu::Blob Bu::Uuid::toUrn() const
68{ 70{
69 return "urn:uuid:" + toString(); 71 BlobBuilder bb("urn:uuid:");
72 bb.append( toBlob() );
73 return bb.getBlob();
70} 74}
71 75
72int Bu::Uuid::getVersion() 76int Bu::Uuid::getVersion()
@@ -129,9 +133,9 @@ Bu::Uuid Bu::Uuid::generate( Bu::Uuid::Type eType )
129 return id; 133 return id;
130} 134}
131 135
132void Bu::Uuid::set( const Bu::String &sSrc ) 136void Bu::Uuid::set( const Bu::Blob &sSrc )
133{ 137{
134 const char *dat = sSrc.getStr(); 138 const char *dat = sSrc.getData();
135 int iNibble = 0; 139 int iNibble = 0;
136 memset( data, 0, 16 ); 140 memset( data, 0, 16 );
137 for( int j = 0; j < 36; j++ ) 141 for( int j = 0; j < 36; j++ )
@@ -162,7 +166,7 @@ Bu::Uuid &Bu::Uuid::operator=( const Uuid &rhs )
162 166
163template<> uint32_t Bu::__calcHashCode<Bu::Uuid>( const Bu::Uuid &k ) 167template<> uint32_t Bu::__calcHashCode<Bu::Uuid>( const Bu::Uuid &k )
164{ 168{
165 return __calcHashCode<String>( k.toRawString() ); 169 return __calcHashCode<Blob>( k.toRawBlob() );
166} 170}
167 171
168template<> bool Bu::__cmpHashKeys<Bu::Uuid>( const Bu::Uuid &a, const Bu::Uuid &b ) 172template<> bool Bu::__cmpHashKeys<Bu::Uuid>( const Bu::Uuid &a, const Bu::Uuid &b )
@@ -172,18 +176,20 @@ template<> bool Bu::__cmpHashKeys<Bu::Uuid>( const Bu::Uuid &a, const Bu::Uuid &
172 176
173Bu::Archive &Bu::operator>>( Bu::Archive &ar, Bu::Uuid &u ) 177Bu::Archive &Bu::operator>>( Bu::Archive &ar, Bu::Uuid &u )
174{ 178{
175 ar.read( u.data, 16 ); 179 Bu::Blob b;
180 ar >> b;
181 memcpy( b.getData(), u.data, 16 );
176 return ar; 182 return ar;
177} 183}
178 184
179Bu::Archive &Bu::operator<<( Bu::Archive &ar, const Bu::Uuid &u ) 185Bu::Archive &Bu::operator<<( Bu::Archive &ar, const Bu::Uuid &u )
180{ 186{
181 ar.write( u.data, 16 ); 187 ar << u.toRawBlob();
182 return ar; 188 return ar;
183} 189}
184 190
185Bu::Formatter &Bu::operator<<( Bu::Formatter &f, const Bu::Uuid &u ) 191Bu::Formatter &Bu::operator<<( Bu::Formatter &f, const Bu::Uuid &u )
186{ 192{
187 return f << u.toString(); 193 return f << u.toBlob();
188} 194}
189 195